blob: 60f4f7a6d5743dbe08751460a93f03d0c8417475 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 6455351
27 * @summary Make sure the Provider.info entries have the correct values
28 * after going through serialization/deserialization.
29 * @author Valerie Peng
30 */
31
32import java.io.*;
33import java.security.*;
34import java.util.*;
35
36public class ProviderInfoCheck {
37
38 public static void main(String[] args) throws Exception {
39 Provider p = new SampleProvider();
40
41 // Serialize and deserialize the above Provider object
42 ByteArrayOutputStream baos = new ByteArrayOutputStream();
43 ObjectOutputStream oos = new ObjectOutputStream(baos);
44 oos.writeObject(p);
45 oos.close();
46 ByteArrayInputStream bais =
47 new ByteArrayInputStream(baos.toByteArray());
48 ObjectInputStream ois = new ObjectInputStream(bais);
49 Provider p2 = (Provider) ois.readObject();
50 ois.close();
51
52 checkProviderInfoEntries(p2);
53 }
54
55 private static void checkProviderInfoEntries(Provider p)
56 throws Exception {
57 String value = (String) p.get("Provider.id name");
58 if (!SampleProvider.NAME.equalsIgnoreCase(value) ||
59 !p.getName().equalsIgnoreCase(value)) {
60 throw new Exception("Test Failed: incorrect name!");
61 }
62 value = (String) p.get("Provider.id info");
63 if (!SampleProvider.INFO.equalsIgnoreCase(value) ||
64 !p.getInfo().equalsIgnoreCase(value)) {
65 throw new Exception("Test Failed: incorrect info!");
66 }
67 value = (String) p.get("Provider.id className");
68 if (!p.getClass().getName().equalsIgnoreCase(value)) {
69 throw new Exception("Test Failed: incorrect className!");
70 }
71 double dvalue =
72 Double.parseDouble((String) p.get("Provider.id version"));
73 if ((SampleProvider.VERSION != dvalue) ||
74 p.getVersion() != dvalue) {
75 throw new Exception("Test Failed: incorrect version!");
76 }
77 System.out.println("Test Passed");
78 }
79
80 private static class SampleProvider extends Provider {
81 static String NAME = "Sample";
82 static double VERSION = 1.1d;
83 static String INFO = "Good for nothing";
84 SampleProvider() {
85 super(NAME, VERSION, INFO);
86 }
87 }
88}