01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @version $Revision$
21: */package org.apache.harmony.security.tests.fortress;
22:
23: import java.security.Provider;
24:
25: import org.apache.harmony.security.fortress.Services;
26: import junit.framework.TestCase;
27:
28: /**
29: *
30: * Tests for Services
31: */
32: public class ServicesTest extends TestCase {
33:
34: public void testInitServiceInfo() {
35: Provider p = new MyProvider();
36: Services.initServiceInfo(p);
37: Provider ap = new AnotherProvider();
38: Services.initServiceInfo(ap);
39:
40: Provider.Service serv = Services
41: .getService("Service.ALGORITHM");
42: if (serv == null) {
43: fail("Service is null");
44: }
45: if (serv.getProvider() != p
46: || !"org.apache.harmony.security.tests.fortress.SomeClass"
47: .equals(serv.getClassName())) {
48: fail("Incorrect Service");
49: }
50: Services.updateServiceInfo(); // restore from registered providers
51: serv = Services.getService("Service.ALGORITHM");
52: if (serv != null) {
53: fail("ServiceDescription not removed");
54: }
55: }
56:
57: public void testRefresh() {
58: Provider p = new MyProvider();
59: Services.updateServiceInfo(); //to make needRefresh = false;
60: Services.initServiceInfo(p);
61: Provider.Service serv = Services
62: .getService("Service.ALGORITHM");
63: Services.refresh();
64: serv = Services.getService("Service.ALGORITHM");
65: if (serv == null) {
66: fail("Service removed");
67: }
68:
69: Services.setNeedRefresh();
70: Services.refresh();
71: serv = Services.getService("Service.ALGORITHM");
72: if (serv != null) {
73: fail("Service not removed");
74: }
75: }
76:
77: class AnotherProvider extends Provider {
78: AnotherProvider() {
79: super ("MyProvider", 1.0, "Provider for testing");
80: put("Service.Algorithm", "AnotherClassName");
81: }
82:
83: AnotherProvider(String name, double version, String info) {
84: super(name, version, info);
85: }
86: }
87:
88: }
|