Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Properties/CompatibilityTest.java
47019 views
/*1* Copyright (c) 2012, 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 8005280 800437126* @summary Compatibility test27* @run main CompatibilityTest28* @run main/othervm -Dsun.util.spi.XmlPropertiesProvider=jdk.internal.util.xml.BasicXmlPropertiesProvider CompatibilityTest29*/3031import java.io.FileInputStream;32import java.io.IOException;33import java.io.InputStream;34import java.util.Properties;3536/**37* This is a behavior compatibility test.38* Although not defined by the properties.dtd, the constructs39* in Compatibility.xml are supported by the regular JDK XML40* Provider.41*42* @author: Joe Wang43*/44public class CompatibilityTest {4546public static void main(String[] args) {47testInternalDTD();48}4950/*51* Not in the spec, but the constructs work with the current JDK52*/53static void testInternalDTD() {54String src = System.getProperty("test.src");55if (src == null) {56src = ".";57}58loadPropertyFile(src + "/Compatibility.xml");59}6061/*62* 'Store' the populated 'Property' with the specified 'Encoding Type' as an63* XML file. Retrieve the same XML file and 'load' onto a new 'Property' object.64*/65static void loadPropertyFile(String filename) {66try (InputStream in = new FileInputStream(filename)) {67Properties prop = new Properties();68prop.loadFromXML(in);69verifyProperites(prop);70} catch (IOException ex) {71fail(ex.getMessage());72}73}7475/*76* This method verifies the first key-value with the original string.77*/78static void verifyProperites(Properties prop) {79try {80for (String key : prop.stringPropertyNames()) {81String val = prop.getProperty(key);82if (key.equals("Key1")) {83if (!val.equals("value1")) {84fail("Key:" + key + "'s value: \nExpected: value1\nFound: " + val);85}86} else if (key.equals("Key2")) {87if (!val.equals("<value2>")) {88fail("Key:" + key + "'s value: \nExpected: <value2>\nFound: " + val);89}90} else if (key.equals("Key3")) {91if (!val.equals("value3")) {92fail("Key:" + key + "'s value: \nExpected: value3\nFound: " + val);93}94}95}96} catch (Exception e) {97fail(e.getMessage());98}99100}101102static void fail(String err) {103throw new RuntimeException(err);104}105106}107108109