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
22package org.apache.harmony.security.tests.fortress;
23
24import java.security.NoSuchAlgorithmException;
25import java.security.Provider;
26import java.security.Security;
27
28import org.apache.harmony.security.fortress.Engine;
29import org.apache.harmony.security.fortress.Services;
30import junit.framework.TestCase;
31
32
33/**
34 *
35 * Tests for Engine
36 */
37public class EngineTest extends TestCase {
38
39	protected void tearDown() throws Exception {
40		super.tearDown();
41		Services.updateServiceInfo();
42	}
43
44	/*
45	 * Class under test for SpiImpl getInstance(String, Object)
46	 */
47	public void testGetInstanceStringObject1() throws Exception {
48		Provider p = new MyProvider();
49		Services.initServiceInfo(p);
50		Engine engine = new Engine("Service");
51
52
53		engine.getInstance("AlGOrItHM", null);
54
55		if (engine.provider != p) {
56			fail("Incorrect provider");
57		}
58		if (!(engine.spi instanceof SomeClass)) {
59			fail("Incorrect spi");
60		}
61	}
62
63    /*
64	 * Class under test for SpiImpl getInstance(String, Object)
65	 */
66	public void testGetInstanceStringObject2() {
67        Provider p = new MyProvider();
68        Services.initServiceInfo(p);
69        Engine engine = new Engine("Service");
70        try {
71            engine.getInstance(null, null);
72            fail("No expected NoSuchAlgorithmException");
73        } catch (NoSuchAlgorithmException e) {}
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    public void testGetInstanceStringProvider1() throws Exception {
109        Provider p = Security.getProvider("SUN");
110        if (p == null) {
111            return;
112        }
113        Engine engine = new Engine("CertStore");
114        engine.getInstance("Collection", p,
115                new java.security.cert.CollectionCertStoreParameters());
116    }
117
118	public void testGetInstanceStringProvider2() throws Exception {
119		Provider p = Security.getProvider("SUN");
120		if (p == null) {
121			return;
122		}
123
124		Engine engine = new Engine("CertStore");
125        engine.getInstance("Collection",
126                new java.security.cert.CollectionCertStoreParameters());
127	}
128
129
130}
131