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.Provider; 25 26import org.apache.harmony.security.fortress.Services; 27import junit.framework.TestCase; 28 29 30/** 31 * 32 * Tests for Services 33 */ 34public class ServicesTest extends TestCase { 35 36 public void testInitServiceInfo() { 37 Provider p = new MyProvider(); 38 Services.initServiceInfo(p); 39 Provider ap = new AnotherProvider(); 40 Services.initServiceInfo(ap); 41 42 Provider.Service serv = Services.getService("Service.ALGORITHM"); 43 if (serv == null) { 44 fail("Service is null"); 45 } 46 if (serv.getProvider() != p || 47 ! "org.apache.harmony.security.tests.fortress.SomeClass".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.getService("Service.ALGORITHM"); 62 Services.refresh(); 63 serv = Services.getService("Service.ALGORITHM"); 64 if (serv == null) { 65 fail("Service removed"); 66 } 67 68 Services.setNeedRefresh(); 69 Services.refresh(); 70 serv = Services.getService("Service.ALGORITHM"); 71 if (serv != null) { 72 fail("Service not removed"); 73 } 74 } 75 76 class AnotherProvider extends Provider { 77 AnotherProvider() { 78 super("MyProvider", 1.0, "Provider for testing"); 79 put("Service.Algorithm", "AnotherClassName"); 80 } 81 82 AnotherProvider(String name, double version, String info) { 83 super(name, version, info); 84 } 85 } 86 87} 88