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 */ 34 public class DefaultSSLSocketFactoryTest extends TestCase { 35 36 /* 37 * Class under test for Socket createSocket(String, int) 38 */ 39 public void testCreateSocketStringint() { 40 DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR"); 41 try { 42 f.createSocket("localhost", 0); 43 fail("No expected SocketException"); 44 } catch (SocketException e) { 45 } catch (IOException e) { 46 fail(e.toString()); 47 } 48 49 } 50 51 /* 52 * Class under test for Socket createSocket(String, int, InetAddress, int) 53 */ 54 public void testCreateSocketStringintInetAddressint() { 55 DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR"); 56 try { 57 f.createSocket("localhost", 0, InetAddress.getLocalHost(), 1); 58 fail("No expected SocketException"); 59 } catch (SocketException e) { 60 } catch (IOException e) { 61 fail(e.toString()); 62 } 63 } 64 65 /* 66 * Class under test for Socket createSocket(InetAddress, int) 67 */ 68 public void testCreateSocketInetAddressint() { 69 DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR"); 70 try { 71 f.createSocket(InetAddress.getLocalHost(), 1); 72 fail("No expected SocketException"); 73 } catch (SocketException e) { 74 } catch (IOException e) { 75 fail(e.toString()); 76 } 77 } 78 79 /* 80 * Class under test for Socket createSocket(InetAddress, int, InetAddress, 81 * int) 82 */ 83 public void testCreateSocketInetAddressintInetAddressint() { 84 DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR"); 85 try { 86 f.createSocket(InetAddress.getLocalHost(), 1, InetAddress 87 .getLocalHost(), 2); 88 fail("No expected SocketException"); 89 } catch (SocketException e) { 90 } catch (IOException e) { 91 fail(e.toString()); 92 } 93 } 94 95 public void testGetDefaultCipherSuites() { 96 DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR"); 97 String[] res = f.getDefaultCipherSuites(); 98 if (res == null || res.length != 0) { 99 fail("incorrect result"); 100 } 101 } 102 103 public void testGetSupportedCipherSuites() { 104 DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR"); 105 String[] res = f.getSupportedCipherSuites(); 106 if (res == null || res.length != 0) { 107 fail("incorrect result"); 108 } 109 } 110 111 /* 112 * Class under test for Socket createSocket(Socket, String, int, boolean) 113 */ 114 public void testCreateSocketSocketStringintboolean() { 115 DefaultSSLSocketFactory f = new DefaultSSLSocketFactory("ERROR"); 116 try { 117 f.createSocket(new Socket(), "localhost", 1, true); 118 fail("No expected SocketException"); 119 } catch (SocketException e) { 120 } catch (IOException e) { 121 fail(e.toString()); 122 } 123 } 124 } 125