Home | History | Annotate | Download | only in ssl
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 
     19 package javax.net.ssl;
     20 
     21 import java.io.IOException;
     22 import java.net.InetAddress;
     23 import java.net.Socket;
     24 import java.net.SocketException;
     25 
     26 import junit.framework.TestCase;
     27 
     28 
     29 /**
     30  * Tests for <code>DefaultSSLSocketFactory</code> class constructors and
     31  * methods.
     32  */
     33 public class DefaultSSLSocketFactoryTest extends TestCase {
     34 
     35     /*
     36      * Class under test for Socket createSocket(String, int)
     37      */
     38     public void testCreateSocketStringint() {
     39         DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR");
     40         try {
     41             f.createSocket("localhost", 0);
     42             fail("No expected SocketException");
     43         } catch (SocketException e) {
     44         } catch (IOException e) {
     45             fail(e.toString());
     46         }
     47 
     48     }
     49 
     50     /*
     51      * Class under test for Socket createSocket(String, int, InetAddress, int)
     52      */
     53     public void testCreateSocketStringintInetAddressint() {
     54         DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR");
     55         try {
     56             f.createSocket("localhost", 0, InetAddress.getLocalHost(), 1);
     57             fail("No expected SocketException");
     58         } catch (SocketException e) {
     59         } catch (IOException e) {
     60             fail(e.toString());
     61         }
     62     }
     63 
     64     /*
     65      * Class under test for Socket createSocket(InetAddress, int)
     66      */
     67     public void testCreateSocketInetAddressint() {
     68         DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR");
     69         try {
     70             f.createSocket(InetAddress.getLocalHost(), 1);
     71             fail("No expected SocketException");
     72         } catch (SocketException e) {
     73         } catch (IOException e) {
     74             fail(e.toString());
     75         }
     76     }
     77 
     78     /*
     79      * Class under test for Socket createSocket(InetAddress, int, InetAddress,
     80      * int)
     81      */
     82     public void testCreateSocketInetAddressintInetAddressint() {
     83         DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR");
     84         try {
     85             f.createSocket(InetAddress.getLocalHost(), 1, InetAddress
     86                     .getLocalHost(), 2);
     87             fail("No expected SocketException");
     88         } catch (SocketException e) {
     89         } catch (IOException e) {
     90             fail(e.toString());
     91         }
     92     }
     93 
     94     public void testGetDefaultCipherSuites() {
     95         DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR");
     96         String[] res = f.getDefaultCipherSuites();
     97         if (res == null || res.length != 0) {
     98             fail("incorrect result");
     99         }
    100     }
    101 
    102     public void testGetSupportedCipherSuites() {
    103         DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR");
    104         String[] res = f.getSupportedCipherSuites();
    105         if (res == null || res.length != 0) {
    106             fail("incorrect result");
    107         }
    108     }
    109 
    110     /*
    111      * Class under test for Socket createSocket(Socket, String, int, boolean)
    112      */
    113     public void testCreateSocketSocketStringintboolean() {
    114         DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR");
    115         try {
    116             f.createSocket(new Socket(), "localhost", 1, true);
    117             fail("No expected SocketException");
    118         } catch (SocketException e) {
    119         } catch (IOException e) {
    120             fail(e.toString());
    121         }
    122     }
    123 }
    124