jdk/test/java/util/prefs/ExportSubtree.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 14694 6d6d54dc0ae1
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3620
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 14694
diff changeset
     2
 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3620
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
     4
 *
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
     8
 *
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    13
 * accompanied this code).
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    14
 *
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3620
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3620
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3620
diff changeset
    21
 * questions.
3620
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    22
 */
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    23
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    24
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    25
/* @test
14694
6d6d54dc0ae1 7197662: (prefs) java/util/prefs/AddNodeChangeListener.java fails by timeout or by "couldn't get file lock"
khazra
parents: 5506
diff changeset
    26
 * @bug 6203576 4700020 7197662
6d6d54dc0ae1 7197662: (prefs) java/util/prefs/AddNodeChangeListener.java fails by timeout or by "couldn't get file lock"
khazra
parents: 5506
diff changeset
    27
 * @summary checks if the output of exportSubtree() is identical to
6d6d54dc0ae1 7197662: (prefs) java/util/prefs/AddNodeChangeListener.java fails by timeout or by "couldn't get file lock"
khazra
parents: 5506
diff changeset
    28
 *          the output from previous release.
6d6d54dc0ae1 7197662: (prefs) java/util/prefs/AddNodeChangeListener.java fails by timeout or by "couldn't get file lock"
khazra
parents: 5506
diff changeset
    29
 * @run main/othervm -Djava.util.prefs.userRoot=. ExportSubtree
3620
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    30
 */
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    31
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    32
import java.io.*;
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    33
import java.util.prefs.*;
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    34
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    35
public class ExportSubtree {
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    36
   public static void main(String[] args) throws Exception {
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    37
      try
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    38
      {
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    39
          //File f = new File(System.getProperty("test.src", "."), "TestPrefs.xml");
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    40
          ByteArrayInputStream bais = new ByteArrayInputStream(importPrefs.getBytes("utf-8"));
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    41
          Preferences.importPreferences(bais);
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    42
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    43
          Preferences.userRoot().node("testExportSubtree").exportSubtree(baos);
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    44
          Preferences.userRoot().node("testExportSubtree").removeNode();
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    45
          if (!expectedResult.equals(baos.toString())) {
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    46
              //System.out.print(baos.toString());
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    47
              //System.out.print(expectedResult);
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    48
              throw new IOException("exportSubtree does not output expected result");
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    49
          }
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    50
      }
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    51
      catch( Exception e ) {
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    52
         e.printStackTrace();
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    53
      }
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    54
   }
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    55
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    56
   static String ls = System.getProperty("line.separator");
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    57
   static String importPrefs =
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    58
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    59
        + "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    60
        + "<preferences EXTERNAL_XML_VERSION=\"1.0\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    61
        + "  <root type=\"user\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    62
        + "    <map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    63
        + "      <entry key=\"key1\" value=\"value1\"/>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    64
        + "    </map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    65
        + "    <node name=\"testExportSubtree\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    66
        + "      <map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    67
        + "        <entry key=\"key2\" value=\"value2\"/>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    68
        + "      </map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    69
        + "      <node name=\"test\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    70
        + "        <map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    71
        + "          <entry key=\"key3\" value=\"value3\"/>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    72
        + "        </map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    73
        + "      </node>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    74
        + "    </node>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    75
        + "  </root>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    76
        + "</preferences>";
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    77
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    78
   static String expectedResult =
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    79
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    80
        + ls    +  "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    81
        + ls    +  "<preferences EXTERNAL_XML_VERSION=\"1.0\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    82
        + ls    +  "  <root type=\"user\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    83
        + ls    +  "    <map/>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    84
        + ls    +  "    <node name=\"testExportSubtree\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    85
        + ls    +  "      <map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    86
        + ls    +  "        <entry key=\"key2\" value=\"value2\"/>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    87
        + ls    +  "      </map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    88
        + ls    +  "      <node name=\"test\">"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    89
        + ls    +  "        <map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    90
        + ls    +  "          <entry key=\"key3\" value=\"value3\"/>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    91
        + ls    +  "        </map>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    92
        + ls    +  "      </node>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    93
        + ls    +  "    </node>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    94
        + ls    +  "  </root>"
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    95
        + ls    +  "</preferences>"     + ls;
23aad720fe49 6676423: (prefs) Opensource unit/regression tests for java.util.prefs
sherman
parents:
diff changeset
    96
}