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: /**
19: * @author Vera Y. Petrashkova
20: * @version $Revision$
21: */package javax.net.ssl;
22:
23: import java.security.InvalidAlgorithmParameterException;
24: import java.security.KeyStore;
25: import java.security.KeyStoreException;
26:
27: import javax.net.ssl.TrustManagerFactorySpi;
28:
29: import junit.framework.TestCase;
30:
31: /**
32: * Tests for <code>TrustManagerFactorySpi</code> class constructors and
33: * methods.
34: *
35: */
36:
37: public class TrustManagerFactorySpiTests extends TestCase {
38: /**
39: * Constructor for TrustManegerFactorySpiTests.
40: *
41: * @param arg0
42: */
43: public TrustManagerFactorySpiTests(String arg0) {
44: super (arg0);
45: }
46:
47: /**
48: * Test for <code>TrustManagerFactorySpi</code> constructor
49: * Assertion: constructs TrustManagerFactorySpi
50: */
51: public void testTrustManagerFactorySpi01() throws Exception {
52: TrustManagerFactorySpi kmfSpi = new MyTrustManagerFactorySpi();
53: assertNull("Not null results", kmfSpi.engineGetTrustManagers());
54: KeyStore kStore = null;
55: ManagerFactoryParameters mfp = null;
56:
57: try {
58: kmfSpi.engineInit(kStore);
59: fail("KeyStoreException must be thrown");
60: } catch (KeyStoreException e) {
61: }
62: try {
63: kmfSpi.engineInit(mfp);
64: fail("InvalidAlgorithmParameterException must be thrown");
65: } catch (InvalidAlgorithmParameterException e) {
66: }
67: assertNull("getTrustManagers() should return null object",
68: kmfSpi.engineGetTrustManagers());
69:
70: try {
71: kStore = KeyStore.getInstance(KeyStore.getDefaultType());
72: kStore.load(null, null);
73: } catch (KeyStoreException e) {
74: fail("default keystore is not supported");
75: return;
76: }
77: kmfSpi.engineInit(kStore);
78: mfp = new MyTrustManagerFactorySpi.Parameters(null);
79: try {
80: kmfSpi.engineInit(mfp);
81: fail("RuntimeException must be thrown");
82: } catch (RuntimeException e) {
83: assertTrue("Incorrect exception",
84: e.getCause() instanceof KeyStoreException);
85: }
86: mfp = new MyTrustManagerFactorySpi.Parameters(kStore);
87: kmfSpi.engineInit(mfp);
88: }
89: }
|