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 java.security;
022:
023: import java.util.HashMap;
024:
025: import junit.framework.TestCase;
026:
027: /**
028: * Tests for <code>Provider</code> constructor and methods
029: *
030: */
031: public class Provider_ImplTest extends TestCase {
032:
033: Provider p;
034:
035: /*
036: * @see TestCase#setUp()
037: */
038: protected void setUp() throws Exception {
039: super .setUp();
040: p = new MyProvider();
041: }
042:
043: /*
044: * Class under test for String toString()
045: */
046: public final void testToString() {
047: assertEquals("Incorrect provider.toString()",
048: "MyProvider version 1.0", p.toString());
049: }
050:
051: public final void testImplementsAlg() {
052: HashMap hm = new HashMap();
053: hm.put("KeySize", "1024");
054: hm.put("AAA", "BBB");
055: Provider.Service s = new Provider.Service(p, "Type",
056: "Algorithm", "className", null, hm);
057: p.putService(s);
058: if (!p.implements Alg("Type", "Algorithm", null, null)
059: || !p.implements Alg("MessageDigest", "SHA-1", null,
060: null)) {
061: fail("Case 1. implementsAlg failed");
062: }
063: if (!p.implements Alg("Type", "Algorithm", "KeySize", "512")) {
064: fail("Case 2. implementsAlg failed");
065: }
066: if (p.implements Alg("Type", "Algorithm", "KeySize", "1025")) {
067: fail("Case 3. implementsAlg failed");
068: }
069: if (!p.implements Alg("Type", "Algorithm", "AAA", "BBB")) {
070: fail("Case 3. implementsAlg failed");
071: }
072: }
073:
074: public final void testSetProviderNumber() {
075: p.setProviderNumber(100);
076: assertEquals("Incorrect ProviderNumber", 100, p
077: .getProviderNumber());
078: }
079:
080: public final void testGetProviderNumber() {
081: assertEquals("Incorrect ProviderNumber", -1, p
082: .getProviderNumber());
083:
084: int i = Security.addProvider(p);
085: assertEquals("Incorrect ProviderNumber", i, p
086: .getProviderNumber());
087: Security.removeProvider(p.getName()); // clean up
088: }
089:
090: class MyProvider extends Provider {
091: MyProvider() {
092: super ("MyProvider", 1.0, "Provider for testing");
093: put("MessageDigest.SHA-1", "SomeClassName");
094: put("MessageDigest.abc", "SomeClassName");
095: put("Alg.Alias.MessageDigest.SHA1", "SHA-1");
096: }
097:
098: MyProvider(String name, double version, String info) {
099: super(name, version, info);
100: }
101: }
102: }
|