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 Boris V. Kuznetsov 20 */ 21 22 package org.apache.harmony.security.tests.fortress; 23 24 import java.security.NoSuchAlgorithmException; 25 import java.security.Provider; 26 import java.security.Security; 27 28 import org.apache.harmony.security.fortress.Engine; 29 import org.apache.harmony.security.fortress.Services; 30 import junit.framework.TestCase; 31 32 33 /** 34 * Tests for Engine 35 */ 36 public class EngineTest extends TestCase { 37 38 protected void tearDown() throws Exception { 39 super.tearDown(); 40 Services.updateServiceInfo(); 41 } 42 43 /* 44 * Class under test for SpiImpl getInstance(String, Object) 45 */ 46 public void testGetInstanceStringObject1() throws Exception { 47 Provider p = new MyProvider(); 48 Services.initServiceInfo(p); 49 Engine engine = new Engine("Service"); 50 51 52 engine.getInstance("AlGOrItHM", null); 53 54 if (engine.provider != p) { 55 fail("Incorrect provider"); 56 } 57 if (!(engine.spi instanceof SomeClass)) { 58 fail("Incorrect spi"); 59 } 60 } 61 62 /* 63 * Class under test for SpiImpl getInstance(String, Object) 64 */ 65 public void testGetInstanceStringObject2() { 66 Provider p = new MyProvider(); 67 Services.initServiceInfo(p); 68 Engine engine = new Engine("Service"); 69 try { 70 engine.getInstance(null, null); 71 fail("No expected NoSuchAlgorithmException"); 72 } catch (NoSuchAlgorithmException e) { 73 } 74 } 75 76 /* 77 * Class under test for SpiImpl getInstance(String, Provider, Object) 78 */ 79 public void testGetInstanceStringProviderObject1() throws Exception { 80 Provider p = new MyProvider(); 81 Services.initServiceInfo(p); 82 Engine engine = new Engine("Service"); 83 84 engine.getInstance("AlGOrItHM", p, null); 85 86 if (engine.provider != p) { 87 fail("Incorrect provider"); 88 } 89 if (!(engine.spi instanceof SomeClass)) { 90 fail("Incorrect spi"); 91 } 92 } 93 94 /* 95 * Class under test for SpiImpl getInstance(String, Provider, Object) 96 */ 97 public void testGetInstanceStringProviderObject2() { 98 Provider p = new MyProvider(); 99 Services.initServiceInfo(p); 100 Engine engine = new Engine("Service"); 101 102 try { 103 engine.getInstance(null, p, null); 104 fail("No expected NoSuchAlgorithmException"); 105 } catch (NoSuchAlgorithmException e) { 106 } 107 } 108 109 public void testGetInstanceStringProvider1() throws Exception { 110 Provider p = Security.getProvider("SUN"); 111 if (p == null) { 112 return; 113 } 114 Engine engine = new Engine("CertStore"); 115 engine.getInstance("Collection", p, 116 new java.security.cert.CollectionCertStoreParameters()); 117 } 118 119 public void testGetInstanceStringProvider2() throws Exception { 120 Provider p = Security.getProvider("SUN"); 121 if (p == null) { 122 return; 123 } 124 125 Engine engine = new Engine("CertStore"); 126 engine.getInstance("Collection", 127 new java.security.cert.CollectionCertStoreParameters()); 128 } 129 130 131 } 132