001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Boris V. Kuznetsov
020: * @version $Revision$
021: */package org.apache.harmony.security.tests.fortress;
022:
023: import java.security.NoSuchAlgorithmException;
024: import java.security.Provider;
025: import java.security.Security;
026:
027: import org.apache.harmony.security.fortress.Engine;
028: import org.apache.harmony.security.fortress.Services;
029: import junit.framework.TestCase;
030:
031: /**
032: *
033: * Tests for Engine
034: */
035: public class EngineTest extends TestCase {
036:
037: protected void tearDown() throws Exception {
038: super .tearDown();
039: Services.updateServiceInfo();
040: }
041:
042: /*
043: * Class under test for SpiImpl getInstance(String, Object)
044: */
045: public void testGetInstanceStringObject1() throws Exception {
046: Provider p = new MyProvider();
047: Services.initServiceInfo(p);
048: Engine engine = new Engine("Service");
049:
050: engine.getInstance("AlGOrItHM", null);
051:
052: if (engine.provider != p) {
053: fail("Incorrect provider");
054: }
055: if (!(engine.spi instanceof SomeClass)) {
056: fail("Incorrect spi");
057: }
058: }
059:
060: /*
061: * Class under test for SpiImpl getInstance(String, Object)
062: */
063: public void testGetInstanceStringObject2() {
064: Provider p = new MyProvider();
065: Services.initServiceInfo(p);
066: Engine engine = new Engine("Service");
067: try {
068: engine.getInstance(null, null);
069: fail("No expected NoSuchAlgorithmException");
070: } catch (NoSuchAlgorithmException e) {
071: }
072: }
073:
074: /*
075: * Class under test for SpiImpl getInstance(String, Provider, Object)
076: */
077: public void testGetInstanceStringProviderObject1() throws Exception {
078: Provider p = new MyProvider();
079: Services.initServiceInfo(p);
080: Engine engine = new Engine("Service");
081:
082: engine.getInstance("AlGOrItHM", p, null);
083:
084: if (engine.provider != p) {
085: fail("Incorrect provider");
086: }
087: if (!(engine.spi instanceof SomeClass)) {
088: fail("Incorrect spi");
089: }
090: }
091:
092: /*
093: * Class under test for SpiImpl getInstance(String, Provider, Object)
094: */
095: public void testGetInstanceStringProviderObject2() {
096: Provider p = new MyProvider();
097: Services.initServiceInfo(p);
098: Engine engine = new Engine("Service");
099:
100: try {
101: engine.getInstance(null, p, null);
102: fail("No expected NoSuchAlgorithmException");
103: } catch (NoSuchAlgorithmException e) {
104: }
105: }
106:
107: public void testGetInstanceStringProvider1() throws Exception {
108: Provider p = Security.getProvider("SUN");
109: if (p == null) {
110: return;
111: }
112: Engine engine = new Engine("CertStore");
113: engine.getInstance("Collection", p,
114: new java.security.cert.CollectionCertStoreParameters());
115: }
116:
117: public void testGetInstanceStringProvider2() throws Exception {
118: Provider p = Security.getProvider("SUN");
119: if (p == null) {
120: return;
121: }
122:
123: Engine engine = new Engine("CertStore");
124: engine.getInstance("Collection",
125: new java.security.cert.CollectionCertStoreParameters());
126: }
127:
128: }
|