01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.provider.jsse;
19:
20: import java.security.InvalidAlgorithmParameterException;
21: import java.security.KeyStore;
22: import java.security.KeyStoreException;
23:
24: import javax.net.ssl.ManagerFactoryParameters;
25: import javax.net.ssl.TrustManager;
26:
27: import org.apache.harmony.xnet.provider.jsse.TrustManagerFactoryImpl;
28: import org.apache.harmony.xnet.provider.jsse.TrustManagerImpl;
29: import junit.framework.TestCase;
30:
31: /**
32: * Tests for <code>TrustManagerFactoryImpl</code> constructor and methods
33: *
34: */
35: public class TrustManagerFactoryImplTest extends TestCase {
36:
37: /*
38: * Class under test for void engineInit(KeyStore)
39: */
40: public void testEngineInitKeyStore() throws Exception {
41: TrustManagerFactoryImpl tmf = new TrustManagerFactoryImpl();
42: tmf.engineInit((KeyStore) null);
43:
44: String def_keystore = System
45: .getProperty("javax.net.ssl.trustStore");
46: System.setProperty("javax.net.ssl.trustStore", "abc");
47: try {
48: tmf.engineInit((KeyStore) null);
49: fail("No expected KeyStoreException");
50: } catch (KeyStoreException e) {
51: } finally {
52: if (def_keystore == null) {
53: System.clearProperty("javax.net.ssl.trustStore");
54: } else {
55: System.setProperty("javax.net.ssl.trustStore",
56: def_keystore);
57: }
58: }
59: }
60:
61: /*
62: * Class under test for void engineInit(ManagerFactoryParameters)
63: */
64: public void testEngineInitManagerFactoryParameters() {
65: TrustManagerFactoryImpl tmf = new TrustManagerFactoryImpl();
66:
67: try {
68: tmf.engineInit((ManagerFactoryParameters) null);
69: fail("No expected InvalidAlgorithmParameterException");
70: } catch (InvalidAlgorithmParameterException e) {
71: }
72: }
73:
74: public void testEngineGetTrustManagers() throws Exception {
75: TrustManagerFactoryImpl tmf = new TrustManagerFactoryImpl();
76: try {
77: tmf.engineGetTrustManagers();
78: fail("No expected IllegalStateException");
79: } catch (IllegalStateException e) {
80: // expected
81: }
82: KeyStore ks;
83: ks = KeyStore.getInstance("BKS");
84: ks.load(null, null);
85: tmf.engineInit(ks);
86:
87: TrustManager[] tma = tmf.engineGetTrustManagers();
88: assertEquals("Incorrect array length", 1, tma.length);
89: assertTrue("Incorrect KeyManager type",
90: tma[0] instanceof TrustManagerImpl);
91: }
92:
93: }
|