You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2006/08/24 04:15:01 UTC
svn commit: r434289 -
/geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/FederationTest.java
Author: dain
Date: Wed Aug 23 19:15:00 2006
New Revision: 434289
URL: http://svn.apache.org/viewvc?rev=434289&view=rev
Log:
Added better tests for federation
Modified:
geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/FederationTest.java
Modified: geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/FederationTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/FederationTest.java?rev=434289&r1=434288&r2=434289&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/FederationTest.java (original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/FederationTest.java Wed Aug 23 19:15:00 2006
@@ -27,83 +27,122 @@
* @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
*/
public class FederationTest extends AbstractContextTest {
- private static final String STRING_VAL = "some string";
+ private Context rootContext;
+ private Map env2Bindings;
+ private MutableContext actualEnv2Context;
+ private Map rootBindings;
+
+ private final class MutableContext extends WritableContext {
+ public MutableContext(Map bindings) throws NamingException {
+ super("", bindings, ContextAccess.UNMODIFIABLE);
+ }
+
+ public void addDeepBinding(Name name, Object value, boolean rebind, boolean createIntermediateContexts) throws NamingException {
+ super.addDeepBinding(name, value, rebind, createIntermediateContexts);
+ }
+
+ protected void removeDeepBinding(Name name, boolean pruneEmptyContexts) throws NamingException {
+ super.removeDeepBinding(name, pruneEmptyContexts);
+ }
+ }
- public void testBasic() throws Exception {
- Map map = new HashMap();
- map.put("string", FederationTest.STRING_VAL);
- map.put("nested/context/string", FederationTest.STRING_VAL);
- map.put("java:comp/env/string", FederationTest.STRING_VAL);
- map.put("java:comp/env/one", new Integer(1));
- map.put("java:comp/env/two", new Integer(2));
- map.put("java:comp/env/three", new Integer(3));
+ public void setUp() throws Exception {
+ super.setUp();
+
+ rootBindings = new HashMap();
+ rootBindings.put("string", "blah");
+ rootBindings.put("nested/context/string", "blah");
+ rootBindings.put("java:comp/env/string", "blah");
+ rootBindings.put("java:comp/env/one", new Integer(1));
+ rootBindings.put("java:comp/env/two", new Integer(2));
+ rootBindings.put("java:comp/env/three", new Integer(3));
+
+ rootContext = new WritableContext();
+ FederationTest.bind(rootContext, rootBindings);
+
+ assertEq(rootBindings, rootContext);
+
+ env2Bindings = new HashMap();
+ env2Bindings.put("string", "blah");
+ env2Bindings.put("one", new Integer(1));
+ env2Bindings.put("two", new Integer(2));
+ env2Bindings.put("three", new Integer(3));
- Context context = new WritableContext();
- FederationTest.bind(context, map);
+ actualEnv2Context = new MutableContext(env2Bindings);
+ assertEq(env2Bindings, actualEnv2Context);
- assertEq(map, context);
+ rootContext.bind("java:comp/env2", actualEnv2Context);
+ putAllBindings(rootBindings, "java:comp/env2", env2Bindings);
+ }
+
+ public void testBasic() throws Exception {
+ assertEq(rootBindings, rootContext);
+ }
- Map env2Map = new HashMap();
- env2Map.put("string", FederationTest.STRING_VAL);
- env2Map.put("one", new Integer(1));
- env2Map.put("two", new Integer(2));
- env2Map.put("three", new Integer(3));
+ public void testMutability() throws Exception {
+ assertModifiable(rootContext);
+ assertUnmodifiable(actualEnv2Context);
+ assertModifiable(lookupSubcontext(rootContext, "java:comp/env2"));
+ }
- ImmutableContext actualEnv2Context = new ImmutableContext(env2Map);
- assertEq(env2Map, actualEnv2Context);
+ public void testBindOverFederated() throws Exception {
+ // update the verification map
+ rootBindings.put("java:comp/env2/TEST", "TEST_VALUE");
- context.bind("java:comp/env2", actualEnv2Context);
+ // bind into root context OVER the env2 context
+ rootContext.bind("java:comp/env2/TEST", "TEST_VALUE");
- Context env2Context = (Context) context.lookup("java:comp/env2");
- assertEq(env2Map, env2Context);
+ // visible from root context
+ assertEq(rootBindings, rootContext);
- putAllBindings(map, "java:comp/env2", env2Map);
- assertEq(map, context);
+ // not-visible from actualEnv2Context
+ assertEq(env2Bindings, actualEnv2Context);
}
- public void testAddBinding() throws Exception {
- Map map = new HashMap();
- map.put("string", FederationTest.STRING_VAL);
- map.put("nested/context/string", FederationTest.STRING_VAL);
- map.put("a/b/c/d/e/string", FederationTest.STRING_VAL);
- map.put("a/b/c/d/e/one", new Integer(1));
- map.put("a/b/c/d/e/two", new Integer(2));
- map.put("a/b/c/d/e/three", new Integer(3));
+ public void testBindDirectIntoFederated() throws Exception {
+ // update the verification maps
+ rootBindings.put("java:comp/env2/DIRECT", "DIRECT_VALUE");
+ env2Bindings.put("DIRECT", "DIRECT_VALUE");
- Context context = new WritableContext();
- FederationTest.bind(context, map);
+ // bind directly into the actual env2 context
+ actualEnv2Context.addDeepBinding(parse("DIRECT"), "DIRECT_VALUE", false, true);
- assertEq(map, context);
+ // visible from root context
+ assertEq(rootBindings, rootContext);
- // add a new deep tree
- map.put("a/b/c/d/e/forty-two", new Integer(42));
- context.bind("a/b/c/d/e/forty-two", new Integer(42));
+ // visible from actualEnv2Context
+ assertEq(env2Bindings, actualEnv2Context);
+ }
- assertEq(map, context);
+ public void testUnbindOverFederated() throws Exception {
+ // unbind value under env2... no exception occurs since unbind is idempotent
+ rootContext.unbind("java:comp/env2/three");
- }
+ // no change in root context
+ assertEq(rootBindings, rootContext);
+ // no change in actualEnv2Context
+ assertEq(env2Bindings, actualEnv2Context);
- public void testRemoveBinding() throws Exception {
- Map map = new HashMap();
- map.put("string", FederationTest.STRING_VAL);
- map.put("nested/context/string", FederationTest.STRING_VAL);
- map.put("a/b/c/d/e/string", FederationTest.STRING_VAL);
- map.put("a/b/c/d/e/one", new Integer(1));
- map.put("a/b/c/d/e/two", new Integer(2));
- map.put("a/b/c/d/e/three", new Integer(3));
+ // unbind value deep env2... no exception occurs since unbind is idempotent
+ rootContext.unbind("java:comp/env2/three");
+ }
- Context context = new WritableContext();
- FederationTest.bind(context, map);
+ public void testUnbindDirectIntoFederated() throws Exception {
+ // update the verification maps
+ rootBindings.remove("java:comp/env2/three");
+ env2Bindings.remove("three");
- assertEq(map, context);
+ // bind directly into the actual env2 context
+ actualEnv2Context.removeDeepBinding(parse("three"), true);
- // remove from an exisitng node
- map.remove("a/b/c/d/e/three");
- context.unbind("a/b/c/d/e/three");
+ // visible from root context
+ assertEq(rootBindings, rootContext);
- assertEq(map, context);
+ // visible from actualEnv2Context
+ assertEq(env2Bindings, actualEnv2Context);
}
+
public static void putAllBindings(Map rootBindings, String nestedPath, Map nestedBindings) {
for (Iterator iterator = nestedBindings.entrySet().iterator(); iterator.hasNext();) {