1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * 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 */ 21 22 package javax.net.ssl; 23 24 import java.security.InvalidAlgorithmParameterException; 25 import java.security.KeyStore; 26 import java.security.KeyStoreException; 27 28 import javax.net.ssl.TrustManagerFactorySpi; 29 30 import junit.framework.TestCase; 31 32 /** 33 * Tests for <code>TrustManagerFactorySpi</code> class constructors and 34 * methods. 35 * 36 */ 37 38 public class TrustManagerFactorySpiTests extends TestCase { 39 /** 40 * Constructor for TrustManegerFactorySpiTests. 41 * 42 * @param arg0 43 */ 44 public TrustManagerFactorySpiTests(String arg0) { 45 super(arg0); 46 } 47 48 /** 49 * Test for <code>TrustManagerFactorySpi</code> constructor 50 * Assertion: constructs TrustManagerFactorySpi 51 */ 52 public void testTrustManagerFactorySpi01() throws Exception { 53 TrustManagerFactorySpi kmfSpi = new MyTrustManagerFactorySpi(); 54 assertNull("Not null results", kmfSpi.engineGetTrustManagers()); 55 KeyStore kStore = null; 56 ManagerFactoryParameters mfp = null; 57 58 try { 59 kmfSpi.engineInit(kStore); 60 fail("KeyStoreException must be thrown"); 61 } catch (KeyStoreException e) { 62 } 63 try { 64 kmfSpi.engineInit(mfp); 65 fail("InvalidAlgorithmParameterException must be thrown"); 66 } catch (InvalidAlgorithmParameterException e) { 67 } 68 assertNull("getTrustManagers() should return null object", 69 kmfSpi.engineGetTrustManagers()); 70 71 try { 72 kStore = KeyStore.getInstance(KeyStore.getDefaultType()); 73 kStore.load(null, null); 74 } catch (KeyStoreException e) { 75 fail("default keystore is not supported"); 76 return; 77 } 78 kmfSpi.engineInit(kStore); 79 mfp = new MyTrustManagerFactorySpi.Parameters(null); 80 try { 81 kmfSpi.engineInit(mfp); 82 fail("RuntimeException must be thrown"); 83 } catch (RuntimeException e) { 84 assertTrue("Incorrect exception", e.getCause() instanceof KeyStoreException); 85 } 86 mfp = new MyTrustManagerFactorySpi.Parameters(kStore); 87 kmfSpi.engineInit(mfp); 88 } 89 } 90