mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 11:34:38 +02:00
6676423: (prefs) Opensource unit/regression tests for java.util.prefs
Moved the existing test cases for prefs to open area Reviewed-by: martin, alanb
This commit is contained in:
parent
dfa68f9504
commit
fcfe031b58
9 changed files with 575 additions and 0 deletions
60
jdk/test/java/util/prefs/CommentsInXml.java
Normal file
60
jdk/test/java/util/prefs/CommentsInXml.java
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 4619564
|
||||||
|
* @summary XMl Comments in Preferences File lead to ClassCastException
|
||||||
|
* @author kladko
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.prefs.*;
|
||||||
|
|
||||||
|
public class CommentsInXml {
|
||||||
|
|
||||||
|
public static void main(String[] argv) throws Exception {
|
||||||
|
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
bos.write(new String(
|
||||||
|
"<!DOCTYPE preferences SYSTEM " +
|
||||||
|
"\"http://java.sun.com/dtd/preferences.dtd\"> " +
|
||||||
|
"<preferences EXTERNAL_XML_VERSION=\"1.0\"> " +
|
||||||
|
" <root type=\"user\"> " +
|
||||||
|
" <map> " +
|
||||||
|
" </map> " +
|
||||||
|
" <node name=\"hlrAgent\"> <!-- HLR Agent --> " +
|
||||||
|
" <map> " +
|
||||||
|
" <entry key=\"agentName\" value=\"HLRAgent\" />" +
|
||||||
|
" </map> " +
|
||||||
|
" </node> " +
|
||||||
|
" </root> " +
|
||||||
|
"</preferences> "
|
||||||
|
).getBytes());
|
||||||
|
|
||||||
|
Preferences ur = Preferences.userRoot();
|
||||||
|
ur.importPreferences(new ByteArrayInputStream(bos.toByteArray()));
|
||||||
|
ur.node("hlrAgent").removeNode(); // clean
|
||||||
|
}
|
||||||
|
}
|
49
jdk/test/java/util/prefs/ConflictInFlush.java
Normal file
49
jdk/test/java/util/prefs/ConflictInFlush.java
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 4703132
|
||||||
|
* @summary flush() throws an IllegalStateException on a removed node
|
||||||
|
* @author Sucheta Dambalkar
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.prefs.*;
|
||||||
|
|
||||||
|
public final class ConflictInFlush{
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
Preferences root = Preferences.userRoot();
|
||||||
|
try {
|
||||||
|
Preferences node = root.node("1/2/3");
|
||||||
|
node.flush();
|
||||||
|
System.out.println("Node "+node+" has been created");
|
||||||
|
System.out.println("Removing node "+node);
|
||||||
|
node.removeNode();
|
||||||
|
node.flush();
|
||||||
|
}catch (BackingStoreException bse){
|
||||||
|
bse.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
53
jdk/test/java/util/prefs/ExportNode.java
Normal file
53
jdk/test/java/util/prefs/ExportNode.java
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 4387136 4947349
|
||||||
|
* @summary Due to a bug in XMLSupport.putPreferencesInXml(...),
|
||||||
|
* node's keys would not get exported.
|
||||||
|
* @author Konstantin Kladko
|
||||||
|
*/
|
||||||
|
import java.util.prefs.*;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class ExportNode {
|
||||||
|
public static void main(String[] args) throws
|
||||||
|
BackingStoreException, IOException {
|
||||||
|
Preferences N1 = Preferences.userRoot().node("ExportNodeTest1");
|
||||||
|
N1.put("ExportNodeTestName1","ExportNodeTestValue1");
|
||||||
|
Preferences N2 = N1.node("ExportNodeTest2");
|
||||||
|
N2.put("ExportNodeTestName2","ExportNodeTestValue2");
|
||||||
|
ByteArrayOutputStream exportStream = new ByteArrayOutputStream();
|
||||||
|
N2.exportNode(exportStream);
|
||||||
|
|
||||||
|
// Removal of preference node should always succeed on Solaris/Linux
|
||||||
|
// by successfully acquiring the appropriate file lock (4947349)
|
||||||
|
N1.removeNode();
|
||||||
|
|
||||||
|
if (((exportStream.toString()).lastIndexOf("ExportNodeTestName2")== -1) ||
|
||||||
|
((exportStream.toString()).lastIndexOf("ExportNodeTestName1")!= -1)) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
95
jdk/test/java/util/prefs/ExportSubtree.java
Normal file
95
jdk/test/java/util/prefs/ExportSubtree.java
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* @test
|
||||||
|
@bug 6203576 4700020
|
||||||
|
@summary checks if the output of exportSubtree() is identical to
|
||||||
|
the output from previous release.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.prefs.*;
|
||||||
|
|
||||||
|
public class ExportSubtree {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//File f = new File(System.getProperty("test.src", "."), "TestPrefs.xml");
|
||||||
|
ByteArrayInputStream bais = new ByteArrayInputStream(importPrefs.getBytes("utf-8"));
|
||||||
|
Preferences.importPreferences(bais);
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
Preferences.userRoot().node("testExportSubtree").exportSubtree(baos);
|
||||||
|
Preferences.userRoot().node("testExportSubtree").removeNode();
|
||||||
|
if (!expectedResult.equals(baos.toString())) {
|
||||||
|
//System.out.print(baos.toString());
|
||||||
|
//System.out.print(expectedResult);
|
||||||
|
throw new IOException("exportSubtree does not output expected result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( Exception e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static String ls = System.getProperty("line.separator");
|
||||||
|
static String importPrefs =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
|
+ "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\">"
|
||||||
|
+ "<preferences EXTERNAL_XML_VERSION=\"1.0\">"
|
||||||
|
+ " <root type=\"user\">"
|
||||||
|
+ " <map>"
|
||||||
|
+ " <entry key=\"key1\" value=\"value1\"/>"
|
||||||
|
+ " </map>"
|
||||||
|
+ " <node name=\"testExportSubtree\">"
|
||||||
|
+ " <map>"
|
||||||
|
+ " <entry key=\"key2\" value=\"value2\"/>"
|
||||||
|
+ " </map>"
|
||||||
|
+ " <node name=\"test\">"
|
||||||
|
+ " <map>"
|
||||||
|
+ " <entry key=\"key3\" value=\"value3\"/>"
|
||||||
|
+ " </map>"
|
||||||
|
+ " </node>"
|
||||||
|
+ " </node>"
|
||||||
|
+ " </root>"
|
||||||
|
+ "</preferences>";
|
||||||
|
|
||||||
|
static String expectedResult =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
|
+ ls + "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\">"
|
||||||
|
+ ls + "<preferences EXTERNAL_XML_VERSION=\"1.0\">"
|
||||||
|
+ ls + " <root type=\"user\">"
|
||||||
|
+ ls + " <map/>"
|
||||||
|
+ ls + " <node name=\"testExportSubtree\">"
|
||||||
|
+ ls + " <map>"
|
||||||
|
+ ls + " <entry key=\"key2\" value=\"value2\"/>"
|
||||||
|
+ ls + " </map>"
|
||||||
|
+ ls + " <node name=\"test\">"
|
||||||
|
+ ls + " <map>"
|
||||||
|
+ ls + " <entry key=\"key3\" value=\"value3\"/>"
|
||||||
|
+ ls + " </map>"
|
||||||
|
+ ls + " </node>"
|
||||||
|
+ ls + " </node>"
|
||||||
|
+ ls + " </root>"
|
||||||
|
+ ls + "</preferences>" + ls;
|
||||||
|
}
|
44
jdk/test/java/util/prefs/PrefsSpi.java
Normal file
44
jdk/test/java/util/prefs/PrefsSpi.java
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* main class used by regtest PrefsSpi.sh
|
||||||
|
*/
|
||||||
|
public class PrefsSpi {
|
||||||
|
|
||||||
|
public static void main (String[] args) throws Exception {
|
||||||
|
if (args.length != 1)
|
||||||
|
throw new Exception("Usage: java PrefsSpi REGEXP");
|
||||||
|
|
||||||
|
String className = Preferences.userRoot().getClass().getName();
|
||||||
|
System.out.printf("className=%s%n", className);
|
||||||
|
|
||||||
|
if (! className.matches(args[0]))
|
||||||
|
throw new Exception("Preferences class name \"" + className
|
||||||
|
+ "\" does not match regular expression \""
|
||||||
|
+ args[0] + "\".");
|
||||||
|
}
|
||||||
|
}
|
100
jdk/test/java/util/prefs/PrefsSpi.sh
Normal file
100
jdk/test/java/util/prefs/PrefsSpi.sh
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
#
|
||||||
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License version 2 only, as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
# accompanied this code).
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License version
|
||||||
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
# CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
# have any questions.
|
||||||
|
#
|
||||||
|
|
||||||
|
# @test
|
||||||
|
# @bug 4991526 6514993
|
||||||
|
# @summary Unit test for Preferences jar providers
|
||||||
|
#
|
||||||
|
# @build PrefsSpi
|
||||||
|
# @run shell PrefsSpi.sh
|
||||||
|
# @author Martin Buchholz
|
||||||
|
|
||||||
|
# Command-line usage: sh PrefsSpi.sh /path/to/build
|
||||||
|
|
||||||
|
if [ -z "$TESTJAVA" ]; then
|
||||||
|
if [ $# -lt 1 ]; then exit 1; fi
|
||||||
|
TESTJAVA="$1"; shift
|
||||||
|
TESTSRC="`pwd`"
|
||||||
|
TESTCLASSES="`pwd`"
|
||||||
|
fi
|
||||||
|
|
||||||
|
java="$TESTJAVA/bin/java"
|
||||||
|
javac="$TESTJAVA/bin/javac"
|
||||||
|
jar="$TESTJAVA/bin/jar"
|
||||||
|
|
||||||
|
Die() { printf "%s\n" "$*"; exit 1; }
|
||||||
|
|
||||||
|
Sys() {
|
||||||
|
printf "%s\n" "$*"; "$@"; rc="$?";
|
||||||
|
test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc";
|
||||||
|
}
|
||||||
|
|
||||||
|
cat > StubPreferences.java <<'EOF'
|
||||||
|
import java.util.prefs.*;
|
||||||
|
|
||||||
|
public class StubPreferences extends AbstractPreferences {
|
||||||
|
public StubPreferences() { super(null, ""); }
|
||||||
|
public String getSpi(String x) { return null; }
|
||||||
|
public void putSpi(String x, String y) { }
|
||||||
|
public void removeSpi(String x) { }
|
||||||
|
public AbstractPreferences childSpi(String x) { return null; }
|
||||||
|
public void removeNodeSpi() { }
|
||||||
|
public String[] keysSpi() { return null; }
|
||||||
|
public String[] childrenNamesSpi() { return null; }
|
||||||
|
public void syncSpi() { }
|
||||||
|
public void flushSpi() { }
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > StubPreferencesFactory.java <<'EOF'
|
||||||
|
import java.util.prefs.*;
|
||||||
|
|
||||||
|
public class StubPreferencesFactory implements PreferencesFactory {
|
||||||
|
public Preferences userRoot() { return new StubPreferences(); }
|
||||||
|
public Preferences systemRoot() { return new StubPreferences(); }
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
Sys rm -rf jarDir extDir
|
||||||
|
Sys mkdir -p jarDir/META-INF/services extDir
|
||||||
|
echo "StubPreferencesFactory" \
|
||||||
|
> "jarDir/META-INF/services/java.util.prefs.PreferencesFactory"
|
||||||
|
Sys "$javac" -d jarDir StubPreferencesFactory.java StubPreferences.java
|
||||||
|
|
||||||
|
(cd jarDir && "$jar" "cf" "../extDir/PrefsSpi.jar" ".")
|
||||||
|
|
||||||
|
case "`uname`" in Windows*|CYGWIN* ) CPS=';';; *) CPS=':';; esac
|
||||||
|
|
||||||
|
Sys "$java" "-cp" "$TESTCLASSES${CPS}extDir/PrefsSpi.jar" \
|
||||||
|
-Djava.util.prefs.PreferencesFactory=StubPreferencesFactory \
|
||||||
|
PrefsSpi "StubPreferences"
|
||||||
|
Sys "$java" "-cp" "$TESTCLASSES" \
|
||||||
|
PrefsSpi "java.util.prefs.*"
|
||||||
|
Sys "$java" "-cp" "$TESTCLASSES${CPS}extDir/PrefsSpi.jar" \
|
||||||
|
PrefsSpi "StubPreferences"
|
||||||
|
Sys "$java" "-cp" "$TESTCLASSES" "-Djava.ext.dirs=extDir" \
|
||||||
|
PrefsSpi "StubPreferences"
|
||||||
|
|
||||||
|
rm -rf jarDir extDir
|
63
jdk/test/java/util/prefs/RemoveReadOnlyNode.java
Normal file
63
jdk/test/java/util/prefs/RemoveReadOnlyNode.java
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* @test
|
||||||
|
@bug 6178148
|
||||||
|
@summary check if wrong exception gets thrown if one of the child
|
||||||
|
nodes is readonly on underlying filesystem when node is
|
||||||
|
being removed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.prefs.*;
|
||||||
|
|
||||||
|
public class RemoveReadOnlyNode {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
String osName = System.getProperty("os.name");
|
||||||
|
if (osName.startsWith("Windows"))
|
||||||
|
return;
|
||||||
|
Preferences root = Preferences.userRoot();
|
||||||
|
Preferences node1 = root.node("node1");
|
||||||
|
Preferences node1A = node1.node("node1A");
|
||||||
|
Preferences node1B = node1.node("node1B");
|
||||||
|
node1B.put("mykey", "myvalue");
|
||||||
|
node1.flush();
|
||||||
|
String node1BDirName = System.getProperty("user.home")
|
||||||
|
+ "/.java/.userPrefs"
|
||||||
|
+ "/node1/node1B";
|
||||||
|
File node1BDir = new File(node1BDirName);
|
||||||
|
node1BDir.setReadOnly();
|
||||||
|
try {
|
||||||
|
node1.removeNode();
|
||||||
|
}
|
||||||
|
catch (BackingStoreException ex) {
|
||||||
|
//expected exception
|
||||||
|
} finally {
|
||||||
|
Runtime.getRuntime().exec("chmod 755 " + node1BDirName).waitFor();
|
||||||
|
try {
|
||||||
|
node1.removeNode();
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
jdk/test/java/util/prefs/RemoveUnregedListener.java
Normal file
63
jdk/test/java/util/prefs/RemoveUnregedListener.java
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* @test
|
||||||
|
* @bug 4705094
|
||||||
|
* @summary Checks if correct exception gets thrown when removing an
|
||||||
|
* unregistered NodeChangeListener .
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.prefs.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class RemoveUnregedListener {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
Preferences userRoot = null;
|
||||||
|
Preferences N1 = null;
|
||||||
|
NodeChangeListenerTestAdd ncl = new NodeChangeListenerTestAdd();
|
||||||
|
NodeChangeListenerTestAdd ncl2 = new NodeChangeListenerTestAdd();
|
||||||
|
NodeChangeListenerTestAdd ncl3 = new NodeChangeListenerTestAdd();
|
||||||
|
try {
|
||||||
|
userRoot = Preferences.userRoot();
|
||||||
|
N1 = userRoot.node("N1");
|
||||||
|
userRoot.flush();
|
||||||
|
|
||||||
|
//add ncl nc2
|
||||||
|
N1.addNodeChangeListener(ncl);
|
||||||
|
N1.addNodeChangeListener(ncl2);
|
||||||
|
N1.removeNodeChangeListener(ncl3);
|
||||||
|
throw new RuntimeException();
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
System.out.println("Test Passed!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Test Failed");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
class NodeChangeListenerTestAdd implements NodeChangeListener {
|
||||||
|
public void childAdded(NodeChangeEvent evt) {}
|
||||||
|
public void childRemoved(NodeChangeEvent evt) {}
|
||||||
|
}
|
48
jdk/test/java/util/prefs/SerializeExceptions.java
Normal file
48
jdk/test/java/util/prefs/SerializeExceptions.java
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 4811356
|
||||||
|
* @summary Prefs exceptions were unintentionally not serializable
|
||||||
|
* @author Josh Bloch
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.prefs.*;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class SerializeExceptions {
|
||||||
|
public static void main(String args[]) throws Exception {
|
||||||
|
test(new BackingStoreException("Hi"));
|
||||||
|
test(new InvalidPreferencesFormatException("Mom!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test(Object o) throws IOException {
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
ObjectOutputStream out = new ObjectOutputStream(bos);
|
||||||
|
out.writeObject(o);
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue