aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2012-02-10 15:57:18 (EST)
committerOleg Besedin2012-02-10 15:57:18 (EST)
commit4c234aebf3f0816838898b88a2b46747cfb1f8c4 (patch)
treeb29e2aebfe8cdcb61ee8832de7a69ae65f26dd18
parentee416e9c5c1c6d14da0671c57a7e231fe7a88458 (diff)
downloadeclipse.platform.runtime-4c234aebf3f0816838898b88a2b46747cfb1f8c4.zip
eclipse.platform.runtime-4c234aebf3f0816838898b88a2b46747cfb1f8c4.tar.gz
eclipse.platform.runtime-4c234aebf3f0816838898b88a2b46747cfb1f8c4.tar.bz2
-rw-r--r--tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java
index 8c12eb4..b33efd4 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/contexts/ActivationTest.java
@@ -11,11 +11,16 @@
package org.eclipse.e4.core.internal.tests.contexts;
+import javax.inject.Inject;
+import javax.inject.Named;
+
import junit.framework.TestCase;
import org.eclipse.e4.core.contexts.ContextFunction;
+import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.contexts.RunAndTrack;
public class ActivationTest extends TestCase {
@@ -104,4 +109,82 @@ public class ActivationTest extends TestCase {
assertEquals(child22, child2.getActiveLeaf());
assertEquals("child22", child2.get("testRAT"));
}
+
+ public void testGetActive() {
+ IEclipseContext root = EclipseContextFactory.create("root");
+
+ IEclipseContext child1 = root.createChild("child1");
+ IEclipseContext child11 = child1.createChild("child11");
+ IEclipseContext child12 = child1.createChild("child12");
+
+ IEclipseContext child2 = root.createChild("child2");
+ IEclipseContext child21 = child2.createChild("child21");
+ IEclipseContext child22 = child2.createChild("child22");
+
+ child11.set("var", "1");
+ child12.set("var", "2");
+ child1.set("var", "3");
+ child21.set("var", "4");
+ child22.set("var", "5");
+ child2.set("var", "6");
+ root.set("var", "7");
+
+ // nothing is active - we get value from the node
+ assertEquals("7", child2.getActive("var"));
+
+ child11.activateBranch();
+ assertEquals("1", child2.getActive("var"));
+ child12.activateBranch();
+ assertEquals("2", child2.getActive("var"));
+ child22.activateBranch();
+ assertEquals("5", child2.getActive("var"));
+ }
+
+ public void testGetActiveRAT() {
+ IEclipseContext root = EclipseContextFactory.create("root");
+
+ IEclipseContext child1 = root.createChild("child1");
+ IEclipseContext child11 = child1.createChild("child11");
+ IEclipseContext child12 = child1.createChild("child12");
+
+ IEclipseContext child2 = root.createChild("child2");
+ IEclipseContext child21 = child2.createChild("child21");
+ IEclipseContext child22 = child2.createChild("child22");
+
+ child11.set("var", "1");
+ child12.set("var", "2");
+ child1.set("var", "3");
+ child21.set("var", "4");
+ child22.set("var", "5");
+ child2.set("var", "6");
+ root.set("var", "7");
+
+ final String[] result = new String[1];
+
+ child2.runAndTrack(new RunAndTrack() {
+ public boolean changed(IEclipseContext context) {
+ result[0] = (String) context.getActive("var");
+ return true;
+ }});
+
+ // nothing is active - we get value from the node
+ assertEquals("7", result[0]);
+
+ child11.activateBranch();
+ assertEquals("1", result[0]);
+ child12.activateBranch();
+ assertEquals("2", result[0]);
+ child22.activateBranch();
+ assertEquals("5", result[0]);
+ }
+
+ public static class ActiveInject {
+ //@Inject @Named("var")
+ public String value;
+
+ @Inject
+ public void setValue(@Named("var") String value) {
+ this.value = value;
+ }
+ }
}