Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/security/Provider/ProviderInfoCheck.java
38812 views
/*1* Copyright (c) 2006, 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 645535126* @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}70double dvalue =71Double.parseDouble((String) p.get("Provider.id version"));72if ((SampleProvider.VERSION != dvalue) ||73p.getVersion() != dvalue) {74throw new Exception("Test Failed: incorrect version!");75}76System.out.println("Test Passed");77}7879private static class SampleProvider extends Provider {80static String NAME = "Sample";81static double VERSION = 1.1d;82static String INFO = "Good for nothing";83SampleProvider() {84super(NAME, VERSION, INFO);85}86}87}888990