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 package org.apache.harmony.xnet.tests.javax.net.ssl;
     19 
     20 import java.io.IOException;
     21 import java.net.InetAddress;
     22 import java.net.ServerSocket;
     23 import java.net.UnknownHostException;
     24 
     25 import javax.net.ssl.SSLParameters;
     26 import javax.net.ssl.SSLSession;
     27 import javax.net.ssl.SSLSocket;
     28 import javax.net.ssl.HandshakeCompletedListener;
     29 
     30 import junit.framework.TestCase;
     31 
     32 
     33 /**
     34  * Tests for <code>SSLSocket</code> class constructors.
     35  *
     36  */
     37 public class SSLSocketTest extends TestCase {
     38 
     39     /*
     40      * Class under test for void SSLSocket()
     41      */
     42     public void testSSLSocket() {
     43         SSLSocket soc = new MySSLSocket();
     44         try {
     45             soc.close();
     46         } catch (IOException e) {
     47         }
     48     }
     49 
     50     /*
     51      * Class under test for void SSLSocket(String, int)
     52      */
     53     public void testSSLSocketStringint() throws Exception {
     54         ServerSocket ss = new ServerSocket(0);
     55         SSLSocket soc = new MySSLSocket("localhost", ss.getLocalPort());
     56         ss.close();
     57         soc.close();
     58     }
     59 
     60     /*
     61      * Class under test for void SSLSocket(InetAddress, int)
     62      */
     63     public void testSSLSocketInetAddressint() throws Exception {
     64         ServerSocket ss = new ServerSocket(0);
     65         SSLSocket soc = new MySSLSocket(InetAddress.getLocalHost(), ss
     66                 .getLocalPort());
     67         ss.close();
     68         soc.close();
     69     }
     70 
     71     /*
     72      * Class under test for void SSLSocket(String, int, InetAddress, int)
     73      */
     74     public void testSSLSocketStringintInetAddressint() throws Exception {
     75         try {
     76             ServerSocket ss1 = new ServerSocket(0);
     77             ServerSocket ss2 = new ServerSocket(0);
     78             SSLSocket soc = new MySSLSocket("localhost", ss1.getLocalPort(),
     79                     InetAddress.getLocalHost(), ss2.getLocalPort());
     80             ss1.close();
     81             ss2.close();
     82             soc.close();
     83         } catch (IOException e) {
     84         }
     85     }
     86 
     87     /*
     88      * Class under test for void SSLSocket(InetAddress, int, InetAddress, int)
     89      */
     90     public void testSSLSocketInetAddressintInetAddressint() throws Exception {
     91         try {
     92             ServerSocket ss1 = new ServerSocket(0);
     93             ServerSocket ss2 = new ServerSocket(0);
     94             SSLSocket soc = new MySSLSocket(InetAddress.getLocalHost(), ss1
     95                     .getLocalPort(), InetAddress.getLocalHost(), ss2
     96                     .getLocalPort());
     97             ss1.close();
     98             ss2.close();
     99             soc.close();
    100         } catch (IOException e) {
    101         }
    102     }
    103 }
    104 
    105 class MySSLSocket extends SSLSocket {
    106 
    107     public MySSLSocket() {
    108         super();
    109     }
    110 
    111     public MySSLSocket(String host, int port) throws IOException,
    112             UnknownHostException {
    113         super(host, port);
    114     }
    115 
    116     protected MySSLSocket(InetAddress address, int port,
    117             InetAddress clientAddress, int clientPort) throws IOException {
    118         super(address, port, clientAddress, clientPort);
    119     }
    120 
    121     public MySSLSocket(InetAddress address, int port) throws IOException {
    122         super(address, port);
    123     }
    124 
    125     public MySSLSocket(String host, int port, InetAddress clientAddress,
    126             int clientPort) throws IOException, UnknownHostException {
    127         super(host, port, clientAddress, clientPort);
    128     }
    129 
    130     @Override
    131     public String[] getSupportedCipherSuites() {
    132         return null;
    133     }
    134 
    135     @Override
    136     public String[] getEnabledCipherSuites() {
    137         return null;
    138     }
    139 
    140     @Override
    141     public void setEnabledCipherSuites(String[] suites) {
    142     }
    143 
    144     @Override
    145     public String[] getSupportedProtocols() {
    146         return null;
    147     }
    148 
    149     @Override
    150     public String[] getEnabledProtocols() {
    151         return null;
    152     }
    153 
    154     @Override
    155     public void setEnabledProtocols(String[] protocols) {
    156     }
    157 
    158     @Override
    159     public SSLSession getSession() {
    160         return null;
    161     }
    162 
    163     @Override
    164     public void addHandshakeCompletedListener(
    165             HandshakeCompletedListener listener) {
    166     }
    167 
    168     @Override
    169     public void removeHandshakeCompletedListener(
    170             HandshakeCompletedListener listener) {
    171     }
    172 
    173     @Override
    174     public void startHandshake() throws IOException {
    175     }
    176 
    177     @Override
    178     public void setUseClientMode(boolean mode) {
    179     }
    180 
    181     @Override
    182     public boolean getUseClientMode() {
    183         return false;
    184     }
    185 
    186     @Override
    187     public void setNeedClientAuth(boolean need) {
    188     }
    189 
    190     @Override
    191     public boolean getNeedClientAuth() {
    192         return false;
    193     }
    194 
    195     @Override
    196     public void setWantClientAuth(boolean want) {
    197     }
    198 
    199     @Override
    200     public boolean getWantClientAuth() {
    201         return false;
    202     }
    203 
    204     @Override
    205     public void setEnableSessionCreation(boolean flag) {
    206     }
    207 
    208     @Override
    209     public boolean getEnableSessionCreation() {
    210         return false;
    211     }
    212 
    213     @Override
    214     public SSLParameters getSSLParameters() {
    215         // TODO Auto-generated method stub
    216         return null;
    217     }
    218 
    219     @Override
    220     public void setSSLParameters(SSLParameters sslP) {
    221         // TODO Auto-generated method stub
    222 
    223     }
    224 }
    225