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 * @author Vera Y. Petrashkova
     20 */
     21 
     22 package javax.net.ssl;
     23 
     24 import java.security.KeyManagementException;
     25 import java.security.SecureRandom;
     26 
     27 import javax.net.ssl.SSLContextSpi;
     28 
     29 import junit.framework.TestCase;
     30 
     31 
     32 /**
     33  * Tests for <code>SSLContextSpi</code> class constructors and methods.
     34  *
     35  */
     36 
     37 public class SSLContextSpiTests extends TestCase {
     38     /**
     39      * Constructor for SSLContextSpiTests.
     40      *
     41      * @param arg0
     42      */
     43     public SSLContextSpiTests(String arg0) {
     44         super(arg0);
     45     }
     46 
     47     /**
     48      * Test for <code>SSLContextSpi</code> constructor
     49      * Assertion: constructs SSLContextSpi
     50      */
     51     public void testSSLContextSpi01() throws KeyManagementException {
     52         SSLContextSpi sslConSpi = new MySSLContextSpi();
     53         try {
     54             sslConSpi.engineGetSocketFactory();
     55             fail("RuntimeException must be thrown");
     56         } catch (RuntimeException e) {
     57             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     58         }
     59         try {
     60             sslConSpi.engineGetServerSocketFactory();
     61             fail("RuntimeException must be thrown");
     62         } catch (RuntimeException e) {
     63             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     64         }
     65         try {
     66             sslConSpi.engineGetServerSessionContext();
     67             fail("RuntimeException must be thrown");
     68         } catch (RuntimeException e) {
     69             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     70         }
     71         try {
     72             sslConSpi.engineGetClientSessionContext();
     73             fail("RuntimeException must be thrown");
     74         } catch (RuntimeException e) {
     75             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     76         }
     77         try {
     78             sslConSpi.engineCreateSSLEngine();
     79             fail("RuntimeException must be thrown");
     80         } catch (RuntimeException e) {
     81             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     82         }
     83         try {
     84             sslConSpi.engineCreateSSLEngine("host",1);
     85             fail("RuntimeException must be thrown");
     86         } catch (RuntimeException e) {
     87             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     88         }
     89         sslConSpi.engineInit(null, null, new SecureRandom());
     90         assertNull("Not null result", sslConSpi.engineGetSocketFactory());
     91         assertNull("Not null result", sslConSpi.engineGetServerSocketFactory());
     92         assertNotNull("Null result", sslConSpi.engineCreateSSLEngine());
     93         assertNotNull("Null result", sslConSpi.engineCreateSSLEngine("host",1));
     94         assertNull("Not null result", sslConSpi.engineGetServerSessionContext());
     95         assertNull("Not null result", sslConSpi.engineGetClientSessionContext());
     96     }
     97 }
     98