Path: blob/master/test/jdk/java/security/Provider/CaseSensitiveServices.java
41149 views
/*1* Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 5097015 813018126* @summary make sure we correctly treat Provider string entries as case insensitive27* @author Andreas Sterbenz28*/2930import java.security.*;31import java.security.Provider.*;3233public class CaseSensitiveServices extends Provider {34CaseSensitiveServices() {35super("Foo", "1.0", null);36put("MessageDigest.Foo", "com.Foo");37put("mESSAGEdIGEST.fOO xYz", "aBc");38put("ALg.aliaS.MESSAGEdigest.Fu", "FoO");39put("messageDigest.Bar", "com.Bar");40put("MESSAGEDIGEST.BAZ", "com.Baz");41}4243public static void main(String[] args) throws Exception {44Provider p = new CaseSensitiveServices();45System.out.println(p.getServices());46if (p.getServices().size() != 3) {47throw new Exception("services.size() should be 3");48}49Service s = testService(p, "MessageDigest", "fOO");50String val = s.getAttribute("Xyz");51if ("aBc".equals(val) == false) {52throw new Exception("Wrong value: " + val);53}54testService(p, "MessageDigest", "fU");55testService(p, "MessageDigest", "BAR");56testService(p, "MessageDigest", "baz");57System.out.println("OK");58}5960private static Service testService(Provider p, String type, String alg) throws Exception {61System.out.println("Getting " + type + "." + alg + "...");62Service s = p.getService(type, alg);63System.out.println(s);64if (s == null) {65throw new Exception("Lookup failed for: " + type + "." + alg);66}67return s;68}6970}717273