001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Vera Y. Petrashkova
020: * @version $Revision$
021: */package javax.net.ssl;
022:
023: import java.security.KeyManagementException;
024: import java.security.SecureRandom;
025:
026: import javax.net.ssl.SSLContextSpi;
027:
028: import junit.framework.TestCase;
029:
030: /**
031: * Tests for <code>SSLContextSpi</code> class constructors and methods.
032: *
033: */
034:
035: public class SSLContextSpiTests extends TestCase {
036: /**
037: * Constructor for SSLContextSpiTests.
038: *
039: * @param arg0
040: */
041: public SSLContextSpiTests(String arg0) {
042: super (arg0);
043: }
044:
045: /**
046: * Test for <code>SSLContextSpi</code> constructor
047: * Assertion: constructs SSLContextSpi
048: */
049: public void testSSLContextSpi01() throws KeyManagementException {
050: SSLContextSpi sslConSpi = new MySSLContextSpi();
051: try {
052: sslConSpi.engineGetSocketFactory();
053: fail("RuntimeException must be thrown");
054: } catch (RuntimeException e) {
055: assertEquals("Incorrect message", "Not initialiazed", e
056: .getMessage());
057: }
058: try {
059: sslConSpi.engineGetServerSocketFactory();
060: fail("RuntimeException must be thrown");
061: } catch (RuntimeException e) {
062: assertEquals("Incorrect message", "Not initialiazed", e
063: .getMessage());
064: }
065: try {
066: sslConSpi.engineGetServerSessionContext();
067: fail("RuntimeException must be thrown");
068: } catch (RuntimeException e) {
069: assertEquals("Incorrect message", "Not initialiazed", e
070: .getMessage());
071: }
072: try {
073: sslConSpi.engineGetClientSessionContext();
074: fail("RuntimeException must be thrown");
075: } catch (RuntimeException e) {
076: assertEquals("Incorrect message", "Not initialiazed", e
077: .getMessage());
078: }
079: try {
080: sslConSpi.engineCreateSSLEngine();
081: fail("RuntimeException must be thrown");
082: } catch (RuntimeException e) {
083: assertEquals("Incorrect message", "Not initialiazed", e
084: .getMessage());
085: }
086: try {
087: sslConSpi.engineCreateSSLEngine("host", 1);
088: fail("RuntimeException must be thrown");
089: } catch (RuntimeException e) {
090: assertEquals("Incorrect message", "Not initialiazed", e
091: .getMessage());
092: }
093: sslConSpi.engineInit(null, null, new SecureRandom());
094: assertNull("Not null result", sslConSpi
095: .engineGetSocketFactory());
096: assertNull("Not null result", sslConSpi
097: .engineGetServerSocketFactory());
098: assertNotNull("Null result", sslConSpi.engineCreateSSLEngine());
099: assertNotNull("Null result", sslConSpi.engineCreateSSLEngine(
100: "host", 1));
101: assertNull("Not null result", sslConSpi
102: .engineGetServerSessionContext());
103: assertNull("Not null result", sslConSpi
104: .engineGetClientSessionContext());
105: }
106: }
|