Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSzymon Ptaszkiewicz2013-10-14 07:49:12 +0000
committerGerrit Code Review @ Eclipse.org2013-10-24 09:00:11 +0000
commitc9b101ad6019999bbc60789881427939c6977da2 (patch)
treed84d20930f87138f41ba1aa21c9e8f8ab92d988b /tests
parent7e0b232400cb860bb566abe97003da0408e5e219 (diff)
downloadeclipse.platform.team-c9b101ad6019999bbc60789881427939c6977da2.tar.gz
eclipse.platform.team-c9b101ad6019999bbc60789881427939c6977da2.tar.xz
eclipse.platform.team-c9b101ad6019999bbc60789881427939c6977da2.zip
Bug 419228 - [Net] PreferenceModifyListener pollutes exported preferences
Change-Id: I2907c8cd1e9cd9a0a662c45652a69948e8cc75da Signed-off-by: Szymon Ptaszkiewicz <szymon.ptaszkiewicz@pl.ibm.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java3
-rw-r--r--tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java63
2 files changed, 65 insertions, 1 deletions
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
index 3d2441984..d95358ade 100644
--- a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -25,6 +25,7 @@ public class AllNetTests extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(NetTest.suite());
+ suite.addTest(PreferenceModifyListenerTest.suite());
return suite;
}
}
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java
new file mode 100644
index 000000000..96fc9eb24
--- /dev/null
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/PreferenceModifyListenerTest.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.tests.net;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.eclipse.core.internal.preferences.EclipsePreferences;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IExportedPreferences;
+import org.eclipse.core.runtime.preferences.IPreferencesService;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.osgi.service.prefs.BackingStoreException;
+
+public class PreferenceModifyListenerTest extends TestCase {
+ private static final String NODE_NAME = "bug419228";
+ private static final String KEY = "someKey";
+ private static final String VALUE = "someValue";
+
+ public static Test suite() {
+ return new PreferenceModifyListenerTest("testPreApply");
+ }
+
+ public PreferenceModifyListenerTest(String name) {
+ super(name);
+ }
+
+ public void testPreApply() throws BackingStoreException, CoreException {
+ // create a dummy node and export it to a stream
+ IEclipsePreferences toExport = InstanceScope.INSTANCE.getNode(NODE_NAME);
+ toExport.put(KEY, VALUE);
+ IPreferencesService service = Platform.getPreferencesService();
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ assertTrue(service.exportPreferences(toExport, stream, null).isOK());
+
+ // read preferences from a stream
+ IExportedPreferences exported = service.readPreferences(new ByteArrayInputStream(stream.toByteArray()));
+ exported = (IExportedPreferences) exported.node(InstanceScope.SCOPE).node(NODE_NAME);
+
+ // apply exported preferences to the global preferences hierarchy
+ assertTrue(service.applyPreferences(exported).isOK());
+
+ // verify that the node is not modified
+ String debugString = ((EclipsePreferences) exported.node("/")).toDeepDebugString();
+ assertFalse(debugString, exported.nodeExists("instance/org.eclipse.core.net"));
+ assertFalse(debugString, exported.nodeExists("/instance/org.eclipse.core.net"));
+ assertFalse(debugString, exported.nodeExists("configuration/org.eclipse.core.net"));
+ assertFalse(debugString, exported.nodeExists("/configuration/org.eclipse.core.net"));
+ }
+}

Back to the top