1 /* 2 * Copyright (c) 2009, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 /* @test 26 @bug 6203576 4700020 27 @summary checks if the output of exportSubtree() is identical to 28 the output from previous release. 29 */ 30 31 import java.io.*; 32 import java.util.prefs.*; 33 34 public class ExportSubtree { 35 public static void main(String[] args) throws Exception { 36 try 37 { 38 //File f = new File(System.getProperty("test.src", "."), "TestPrefs.xml"); 39 ByteArrayInputStream bais = new ByteArrayInputStream(importPrefs.getBytes("utf-8")); 40 Preferences.importPreferences(bais); 41 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 42 Preferences.userRoot().node("testExportSubtree").exportSubtree(baos); 43 Preferences.userRoot().node("testExportSubtree").removeNode(); 44 if (!expectedResult.equals(baos.toString())) { 45 //System.out.print(baos.toString()); 46 //System.out.print(expectedResult); 47 throw new IOException("exportSubtree does not output expected result"); 48 } 49 } 50 catch( Exception e ) { 51 e.printStackTrace(); 52 } 53 } 54 55 static String ls = System.getProperty("line.separator"); 56 static String importPrefs = 57 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 58 + "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\">" 59 + "<preferences EXTERNAL_XML_VERSION=\"1.0\">" 60 + " <root type=\"user\">" 61 + " <map>" 62 + " <entry key=\"key1\" value=\"value1\"/>" 63 + " </map>" 64 + " <node name=\"testExportSubtree\">" 65 + " <map>" 66 + " <entry key=\"key2\" value=\"value2\"/>" 67 + " </map>" 68 + " <node name=\"test\">" 69 + " <map>" 70 + " <entry key=\"key3\" value=\"value3\"/>" 71 + " </map>" 72 + " </node>" 73 + " </node>" 74 + " </root>" 75 + "</preferences>"; 76 77 static String expectedResult = 78 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 79 + ls + "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\">" 80 + ls + "<preferences EXTERNAL_XML_VERSION=\"1.0\">" 81 + ls + " <root type=\"user\">" 82 + ls + " <map/>" 83 + ls + " <node name=\"testExportSubtree\">" 84 + ls + " <map>" 85 + ls + " <entry key=\"key2\" value=\"value2\"/>" 86 + ls + " </map>" 87 + ls + " <node name=\"test\">" 88 + ls + " <map>" 89 + ls + " <entry key=\"key3\" value=\"value3\"/>" 90 + ls + " </map>" 91 + ls + " </node>" 92 + ls + " </node>" 93 + ls + " </root>" 94 + ls + "</preferences>" + ls; 95 }