Path: blob/master/test/jdk/java/security/Provider/ChangeProviders.java
41149 views
/*1* Copyright (c) 2003, 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 4856968 7054918 813018126* @library ../testlibrary27* @summary make sure add/insert/removeProvider() work correctly28* @author Andreas Sterbenz29*/3031import java.util.*;3233import java.security.*;3435public class ChangeProviders extends Provider {3637private ChangeProviders() {38super("Foo", "47.23", "none");39}4041private static int plen() {42return Security.getProviders().length;43}4445public static void main(String[] args) throws Exception {46ProvidersSnapshot snapshot = ProvidersSnapshot.create();47try {48main0(args);49} finally {50snapshot.restore();51}52}5354public static void main0(String[] args) throws Exception {55long start = System.currentTimeMillis();56Provider p = new ChangeProviders();5758int n = plen();59Security.addProvider(p);60if (plen() != n + 1) {61throw new Exception("Provider not added");62}63Security.addProvider(p);64if (plen() != n + 1) {65throw new Exception("Provider readded");66}67Security.insertProviderAt(p, 1);68if (plen() != n + 1) {69throw new Exception("Provider readded");70}71Security.removeProvider(p.getName());72if ((plen() != n) || (Security.getProvider(p.getName()) != null)) {73throw new Exception("Provider not removed");74}75Security.insertProviderAt(p, 1);76if (plen() != n + 1) {77throw new Exception("Provider not added");78}79if (Security.getProviders()[0] != p) {80throw new Exception("Provider not at pos 1");81}8283System.out.println("All tests passed.");84}8586}878889