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: import java.security.UnrecoverableKeyException;
27:
28: import javax.net.ssl.KeyManagerFactorySpi;
29:
30: import junit.framework.TestCase;
31:
32: /**
33: * Tests for <code>KeyManagerFactorySpi</code> class constructors and methods.
34: *
35: */
36:
37: public class KeyManagerFactorySpiTests extends TestCase {
38:
39: /**
40: * Constructor for KeyManegerFactorySpiTests.
41: *
42: * @param arg0
43: */
44: public KeyManagerFactorySpiTests(String arg0) {
45: super (arg0);
46: }
47:
48: /**
49: * Test for <code>KeyManagerFactorySpi</code> constructor
50: * Assertion: constructs KeyManagerFactorySpi
51: */
52: public void testKeyManagerFactorySpi01() throws Exception {
53: KeyManagerFactorySpi kmfSpi = new MyKeyManagerFactorySpi();
54: assertNull(kmfSpi.engineGetKeyManagers());
55: KeyStore kStore = null;
56: ManagerFactoryParameters mfp = null;
57:
58: char[] pass = { 'a', 'b', 'c' };
59:
60: try {
61: kmfSpi.engineInit(kStore, null);
62: fail("KeyStoreException must be thrown");
63: } catch (KeyStoreException e) {
64: }
65: try {
66: kmfSpi.engineInit(kStore, pass);
67: fail("UnrecoverableKeyException must be thrown");
68: } catch (UnrecoverableKeyException e) {
69: }
70: try {
71: kmfSpi.engineInit(mfp);
72: fail("InvalidAlgorithmParameterException must be thrown");
73: } catch (InvalidAlgorithmParameterException e) {
74: }
75: assertNull("getKeyManagers() should return null object", kmfSpi
76: .engineGetKeyManagers());
77:
78: try {
79: kStore = KeyStore.getInstance(KeyStore.getDefaultType());
80: kStore.load(null, null);
81: } catch (KeyStoreException e) {
82: fail("default keystore type is not supported");
83: return;
84: }
85: kmfSpi.engineInit(kStore, pass);
86:
87: mfp = new MyKeyManagerFactorySpi.Parameters(kStore, null);
88: try {
89: kmfSpi.engineInit(mfp);
90: fail("InvalidAlgorithmParameterException must be thrown");
91: } catch (InvalidAlgorithmParameterException e) {
92: }
93: mfp = new MyKeyManagerFactorySpi.Parameters(kStore, pass);
94: kmfSpi.engineInit(mfp);
95: }
96: }
|