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 Boris V. Kuznetsov
020: * @version $Revision$
021: */package javax.net.ssl;
022:
023: import java.io.IOException;
024: import java.security.Security;
025: import java.net.SocketException;
026:
027: import junit.framework.TestCase;
028:
029: /**
030: * Tests for <code>SSLSocketFactory</code> class methods.
031: *
032: */
033: public class SSLServerSocketFactoryTest extends TestCase {
034:
035: private SSLServerSocketFactory customServerSocketFactory;
036:
037: /*
038: * @see TestCase#setUp()
039: */
040: protected void setUp() throws Exception {
041: super .setUp();
042: String defaultName = Security
043: .getProperty("ssl.ServerSocketFactory.provider");
044: if (defaultName != null) {
045: try {
046: customServerSocketFactory = (SSLServerSocketFactory) Class
047: .forName(defaultName, true,
048: ClassLoader.getSystemClassLoader())
049: .newInstance();
050: } catch (Exception e) {
051: }
052: }
053: if (customServerSocketFactory == null) {
054: SSLContext context = DefaultSSLContext.getContext();
055: if (context != null) {
056: customServerSocketFactory = context
057: .getServerSocketFactory();
058: }
059: }
060: }
061:
062: /*
063: * @see TestCase#tearDown()
064: */
065: protected void tearDown() throws Exception {
066: super .tearDown();
067: }
068:
069: public final void testGetDefault() {
070: SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory
071: .getDefault();
072: if (customServerSocketFactory != null) {
073: if (!factory.getClass().getName().equals(
074: customServerSocketFactory.getClass().getName())) {
075: fail("incorrect instance: "
076: + factory.getClass()
077: + " expected: "
078: + customServerSocketFactory.getClass()
079: .getName());
080: }
081: } else {
082: if (!(factory instanceof DefaultSSLServerSocketFactory)) {
083: fail("incorrect instance " + factory.getClass());
084: }
085: if (factory.getDefaultCipherSuites().length != 0) {
086: fail("incorrect result: DefaultSSLServerSocketFactory.getDefaultCipherSuites()");
087: }
088: if (factory.getSupportedCipherSuites().length != 0) {
089: fail("incorrect result: DefaultSSLServerSocketFactory.getDefaultCipherSuites()");
090: }
091: try {
092: factory.createServerSocket(0);
093: fail("No expected SocketException");
094: } catch (SocketException e) {
095: } catch (IOException e) {
096: fail(e.toString());
097: }
098: }
099: }
100:
101: }
|