author | ctornqvi |
Thu, 16 May 2013 15:31:00 +0200 | |
changeset 17598 | f78d22d3c6c2 |
parent 14922 | fdb5ce96f459 |
child 24371 | a9c7b18bf425 |
permissions | -rw-r--r-- |
14922
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
1 |
/* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
4 |
* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
8 |
* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
13 |
* accompanied this code). |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
14 |
* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
18 |
* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
21 |
* questions. |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
22 |
*/ |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
23 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
24 |
/* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
25 |
* @test |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
26 |
* @bug 8005280 8004371 |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
27 |
* @summary Compatibility test |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
28 |
* @run main CompatibilityTest |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
29 |
* @run main/othervm -Dsun.util.spi.XmlPropertiesProvider=jdk.internal.util.xml.BasicXmlPropertiesProvider CompatibilityTest |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
30 |
*/ |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
31 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
32 |
import java.io.FileInputStream; |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
33 |
import java.io.IOException; |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
34 |
import java.io.InputStream; |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
35 |
import java.util.Properties; |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
36 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
37 |
/** |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
38 |
* This is a behavior compatibility test. |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
39 |
* Although not defined by the properties.dtd, the constructs |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
40 |
* in Compatibility.xml are supported by the regular JDK XML |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
41 |
* Provider. |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
42 |
* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
43 |
* @author: Joe Wang |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
44 |
*/ |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
45 |
public class CompatibilityTest { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
46 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
47 |
public static void main(String[] args) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
48 |
testInternalDTD(); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
49 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
50 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
51 |
/* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
52 |
* Not in the spec, but the constructs work with the current JDK |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
53 |
*/ |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
54 |
static void testInternalDTD() { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
55 |
String src = System.getProperty("test.src"); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
56 |
if (src == null) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
57 |
src = "."; |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
58 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
59 |
loadPropertyFile(src + "/Compatibility.xml"); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
60 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
61 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
62 |
/* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
63 |
* 'Store' the populated 'Property' with the specified 'Encoding Type' as an |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
64 |
* XML file. Retrieve the same XML file and 'load' onto a new 'Property' object. |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
65 |
*/ |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
66 |
static void loadPropertyFile(String filename) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
67 |
try (InputStream in = new FileInputStream(filename)) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
68 |
Properties prop = new Properties(); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
69 |
prop.loadFromXML(in); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
70 |
verifyProperites(prop); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
71 |
} catch (IOException ex) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
72 |
fail(ex.getMessage()); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
73 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
74 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
75 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
76 |
/* |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
77 |
* This method verifies the first key-value with the original string. |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
78 |
*/ |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
79 |
static void verifyProperites(Properties prop) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
80 |
try { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
81 |
for (String key : prop.stringPropertyNames()) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
82 |
String val = prop.getProperty(key); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
83 |
if (key.equals("Key1")) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
84 |
if (!val.equals("value1")) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
85 |
fail("Key:" + key + "'s value: \nExpected: value1\nFound: " + val); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
86 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
87 |
} else if (key.equals("Key2")) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
88 |
if (!val.equals("<value2>")) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
89 |
fail("Key:" + key + "'s value: \nExpected: <value2>\nFound: " + val); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
90 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
91 |
} else if (key.equals("Key3")) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
92 |
if (!val.equals("value3")) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
93 |
fail("Key:" + key + "'s value: \nExpected: value3\nFound: " + val); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
94 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
95 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
96 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
97 |
} catch (Exception e) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
98 |
fail(e.getMessage()); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
99 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
100 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
101 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
102 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
103 |
static void fail(String err) { |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
104 |
throw new RuntimeException(err); |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
105 |
} |
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
106 |
|
fdb5ce96f459
8005280: (props) Improve test coverage for small XML parser
joehw
parents:
diff
changeset
|
107 |
} |