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 public class SSLContextSpiTests extends TestCase {
     37     /**
     38      * Constructor for SSLContextSpiTests.
     39      *
     40      * @param arg0
     41      */
     42     public SSLContextSpiTests(String arg0) {
     43         super(arg0);
     44     }
     45 
     46     /**
     47      * Test for <code>SSLContextSpi</code> constructor
     48      * Assertion: constructs SSLContextSpi
     49      */
     50     public void testSSLContextSpi01() throws KeyManagementException {
     51         SSLContextSpi sslConSpi = new MySSLContextSpi();
     52         try {
     53             sslConSpi.engineGetSocketFactory();
     54             fail("RuntimeException must be thrown");
     55         } catch (RuntimeException e) {
     56             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     57         }
     58         try {
     59             sslConSpi.engineGetServerSocketFactory();
     60             fail("RuntimeException must be thrown");
     61         } catch (RuntimeException e) {
     62             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     63         }
     64         try {
     65             sslConSpi.engineGetServerSessionContext();
     66             fail("RuntimeException must be thrown");
     67         } catch (RuntimeException e) {
     68             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     69         }
     70         try {
     71             sslConSpi.engineGetClientSessionContext();
     72             fail("RuntimeException must be thrown");
     73         } catch (RuntimeException e) {
     74             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     75         }
     76         try {
     77             sslConSpi.engineCreateSSLEngine();
     78             fail("RuntimeException must be thrown");
     79         } catch (RuntimeException e) {
     80             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     81         }
     82         try {
     83             sslConSpi.engineCreateSSLEngine("host", 1);
     84             fail("RuntimeException must be thrown");
     85         } catch (RuntimeException e) {
     86             assertEquals("Incorrect message", "Not initialiazed", e.getMessage());
     87         }
     88         sslConSpi.engineInit(null, null, new SecureRandom());
     89         assertNull("Not null result", sslConSpi.engineGetSocketFactory());
     90         assertNull("Not null result", sslConSpi.engineGetServerSocketFactory());
     91         assertNotNull("Null result", sslConSpi.engineCreateSSLEngine());
     92         assertNotNull("Null result", sslConSpi.engineCreateSSLEngine("host", 1));
     93         assertNull("Not null result", sslConSpi.engineGetServerSessionContext());
     94         assertNull("Not null result", sslConSpi.engineGetClientSessionContext());
     95     }
     96 }
     97