ExportSubtree.java revision 1568
1568N/A/*
1568N/A * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
1568N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1568N/A *
1568N/A * This code is free software; you can redistribute it and/or modify it
1568N/A * under the terms of the GNU General Public License version 2 only, as
1568N/A * published by the Free Software Foundation.
1568N/A *
1568N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1568N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1568N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1568N/A * version 2 for more details (a copy is included in the LICENSE file that
1568N/A * accompanied this code).
1568N/A *
1568N/A * You should have received a copy of the GNU General Public License version
1568N/A * 2 along with this work; if not, write to the Free Software Foundation,
1568N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1568N/A *
1568N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1568N/A * CA 95054 USA or visit www.sun.com if you need additional information or
1568N/A * have any questions.
1568N/A */
1568N/A
1568N/A
1568N/A/* @test
1568N/A @bug 6203576 4700020
1568N/A @summary checks if the output of exportSubtree() is identical to
1568N/A the output from previous release.
1568N/A */
1568N/A
1568N/Aimport java.io.*;
1568N/Aimport java.util.prefs.*;
1568N/A
1568N/Apublic class ExportSubtree {
1568N/A public static void main(String[] args) throws Exception {
1568N/A try
1568N/A {
1568N/A //File f = new File(System.getProperty("test.src", "."), "TestPrefs.xml");
1568N/A ByteArrayInputStream bais = new ByteArrayInputStream(importPrefs.getBytes("utf-8"));
1568N/A Preferences.importPreferences(bais);
1568N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
1568N/A Preferences.userRoot().node("testExportSubtree").exportSubtree(baos);
1568N/A Preferences.userRoot().node("testExportSubtree").removeNode();
1568N/A if (!expectedResult.equals(baos.toString())) {
1568N/A //System.out.print(baos.toString());
1568N/A //System.out.print(expectedResult);
1568N/A throw new IOException("exportSubtree does not output expected result");
1568N/A }
1568N/A }
1568N/A catch( Exception e ) {
1568N/A e.printStackTrace();
1568N/A }
1568N/A }
1568N/A
1568N/A static String ls = System.getProperty("line.separator");
1568N/A static String importPrefs =
1568N/A "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1568N/A + "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\">"
1568N/A + "<preferences EXTERNAL_XML_VERSION=\"1.0\">"
1568N/A + " <root type=\"user\">"
1568N/A + " <map>"
1568N/A + " <entry key=\"key1\" value=\"value1\"/>"
1568N/A + " </map>"
1568N/A + " <node name=\"testExportSubtree\">"
1568N/A + " <map>"
1568N/A + " <entry key=\"key2\" value=\"value2\"/>"
1568N/A + " </map>"
1568N/A + " <node name=\"test\">"
1568N/A + " <map>"
1568N/A + " <entry key=\"key3\" value=\"value3\"/>"
1568N/A + " </map>"
1568N/A + " </node>"
1568N/A + " </node>"
1568N/A + " </root>"
1568N/A + "</preferences>";
1568N/A
1568N/A static String expectedResult =
1568N/A "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1568N/A + ls + "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\">"
1568N/A + ls + "<preferences EXTERNAL_XML_VERSION=\"1.0\">"
1568N/A + ls + " <root type=\"user\">"
1568N/A + ls + " <map/>"
1568N/A + ls + " <node name=\"testExportSubtree\">"
1568N/A + ls + " <map>"
1568N/A + ls + " <entry key=\"key2\" value=\"value2\"/>"
1568N/A + ls + " </map>"
1568N/A + ls + " <node name=\"test\">"
1568N/A + ls + " <map>"
1568N/A + ls + " <entry key=\"key3\" value=\"value3\"/>"
1568N/A + ls + " </map>"
1568N/A + ls + " </node>"
1568N/A + ls + " </node>"
1568N/A + ls + " </root>"
1568N/A + ls + "</preferences>" + ls;
1568N/A}