Path: blob/master/test/jdk/java/security/Provider/ProviderInfoCheck.java
41149 views
/*1* Copyright (c) 2006, 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 6455351 813018126* @summary Make sure the Provider.info entries have the correct values27* after going through serialization/deserialization.28* @author Valerie Peng29*/3031import java.io.*;32import java.security.*;33import java.util.*;3435public class ProviderInfoCheck {3637public static void main(String[] args) throws Exception {38Provider p = new SampleProvider();3940// Serialize and deserialize the above Provider object41ByteArrayOutputStream baos = new ByteArrayOutputStream();42ObjectOutputStream oos = new ObjectOutputStream(baos);43oos.writeObject(p);44oos.close();45ByteArrayInputStream bais =46new ByteArrayInputStream(baos.toByteArray());47ObjectInputStream ois = new ObjectInputStream(bais);48Provider p2 = (Provider) ois.readObject();49ois.close();5051checkProviderInfoEntries(p2);52}5354private static void checkProviderInfoEntries(Provider p)55throws Exception {56String value = (String) p.get("Provider.id name");57if (!SampleProvider.NAME.equalsIgnoreCase(value) ||58!p.getName().equalsIgnoreCase(value)) {59throw new Exception("Test Failed: incorrect name!");60}61value = (String) p.get("Provider.id info");62if (!SampleProvider.INFO.equalsIgnoreCase(value) ||63!p.getInfo().equalsIgnoreCase(value)) {64throw new Exception("Test Failed: incorrect info!");65}66value = (String) p.get("Provider.id className");67if (!p.getClass().getName().equalsIgnoreCase(value)) {68throw new Exception("Test Failed: incorrect className!");69}70value = (String) p.get("Provider.id version");71if (!SampleProvider.VERSION.equalsIgnoreCase(value) ||72p.getVersionStr() != value) {73throw new Exception("Test Failed: incorrect versionStr!");74}75System.out.println("Test Passed");76}7778private static class SampleProvider extends Provider {79static String NAME = "Sample";80static String VERSION = "1.1";81static String INFO = "Good for nothing";82SampleProvider() {83super(NAME, VERSION, INFO);84}85}86}878889