geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r434502 - in /geronimo/xbean/branches/colossus/xbean-naming/src: main/java/org/apache/xbean/naming/context/ test/java/org/apache/xbean/naming/context/
Date Thu, 24 Aug 2006 20:13:59 GMT
Author: dain
Date: Thu Aug 24 13:13:58 2006
New Revision: 434502

URL: http://svn.apache.org/viewvc?rev=434502&view=rev
Log:
Added tests for bind, rebind, unbind, rename, createSubcontext, and destroySubcontext.
Added exception tests for lookup, lookupLink, list and listBindings. 

Modified:
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
    geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/AbstractContextTest.java
    geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/ContextAccessControlListTest.java
    geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java?rev=434502&r1=434501&r2=434502&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
Thu Aug 24 13:13:58 2006
@@ -63,7 +63,7 @@
     protected ContextAccess getContextAccess() {
         return contextAccess;
     }
-    
+
     //
     //  Lookup Binding
     //
@@ -156,7 +156,11 @@
         if (value != null) {
             return value;
         }
-        throw new NameNotFoundException(stringName);
+        if (parsedName.size() > 1) {
+            throw new NotContextException(stringName);
+        } else {
+            throw new NameNotFoundException(stringName);
+        }
     }
 
     /**
@@ -691,7 +695,12 @@
         }
 
         // lookup the target context
-        Object target = lookup(name);
+        Object target = null;
+        try {
+            target = lookup(name);
+        } catch (NamingException e) {
+            throw new NotContextException(name);
+        }
 
         if (target == this) {
             return list();
@@ -711,7 +720,12 @@
         }
 
         // lookup the target context
-        Object target = lookup(name);
+        Object target = null;
+        try {
+            target = lookup(name);
+        } catch (NamingException e) {
+            throw new NotContextException(name.toString());
+        }
 
         if (target == this) {
             return list();
@@ -731,7 +745,12 @@
         }
 
         // lookup the target context
-        Object target = lookup(name);
+        Object target = null;
+        try {
+            target = lookup(name);
+        } catch (NamingException e) {
+            throw new NotContextException(name.toString());
+        }
 
         if (target == this) {
             return listBindings();
@@ -751,7 +770,12 @@
         }
 
         // lookup the target context
-        Object target = lookup(name);
+        Object target = null;
+        try {
+            target = lookup(name);
+        } catch (NamingException e) {
+            throw new NotContextException(name.toString());
+        }
 
         if (target == this) {
             return listBindings();

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/AbstractContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/AbstractContextTest.java?rev=434502&r1=434501&r2=434502&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/AbstractContextTest.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/AbstractContextTest.java
Thu Aug 24 13:13:58 2006
@@ -409,4 +409,12 @@
 
         assertNoBinding(context, name);
     }
+
+    public static boolean bindingExists(Context context, Name contextName) {
+        try {
+            return context.lookup(contextName) != null;
+        } catch (NamingException e) {
+        }
+        return false;
+    }
 }

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/ContextAccessControlListTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/ContextAccessControlListTest.java?rev=434502&r1=434501&r2=434502&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/ContextAccessControlListTest.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/ContextAccessControlListTest.java
Thu Aug 24 13:13:58 2006
@@ -17,7 +17,6 @@
 package org.apache.xbean.naming.context;
 
 import javax.naming.Context;
-import javax.naming.NamingException;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java?rev=434502&r1=434501&r2=434502&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java
Thu Aug 24 13:13:58 2006
@@ -16,79 +16,38 @@
  */
 package org.apache.xbean.naming.context;
 
-import javax.naming.NamingException;
 import javax.naming.Context;
 import javax.naming.Name;
-import java.util.Map;
+import javax.naming.NameNotFoundException;
+import javax.naming.NotContextException;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
 /**
  * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
  */
 public class WritableContextTest extends AbstractContextTest {
     private static final String STRING_VAL = "some string";
+    private Map bindings;
+    private Context context;
 
-    public void testBasic() throws Exception {
-        Map map = new HashMap();
-        map.put("string", WritableContextTest.STRING_VAL);
-        map.put("nested/context/string", WritableContextTest.STRING_VAL);
-        map.put("a/b/c/d/e/string", WritableContextTest.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));
-
-        Context context = new WritableContext();
-        bind(context, map);
-
-        assertEq(map, context);
-    }
-
-    public void testAddBinding() throws Exception {
-        Map map = new HashMap();
-        map.put("string", WritableContextTest.STRING_VAL);
-        map.put("nested/context/string", WritableContextTest.STRING_VAL);
-        map.put("a/b/c/d/e/string", WritableContextTest.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));
-
-        Context context = new WritableContext();
-        bind(context, map);
-
-        assertEq(map, context);
-
-        // 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));
-
-        assertEq(map, context);
-
-    }
+    public void setUp() throws Exception {
+        super.setUp();
 
+        // initialize the bindings map
+        bindings = new HashMap();
+        bindings.put("string", WritableContextTest.STRING_VAL);
+        bindings.put("nested/context/string", WritableContextTest.STRING_VAL);
+        bindings.put("a/b/c/d/e/string", WritableContextTest.STRING_VAL);
+        bindings.put("a/b/c/d/e/one", new Integer(1));
+        bindings.put("a/b/c/d/e/two", new Integer(2));
+        bindings.put("a/b/c/d/e/three", new Integer(3));
 
-    public void testRemoveBinding() throws Exception {
-        Map map = new HashMap();
-        map.put("string", WritableContextTest.STRING_VAL);
-        map.put("nested/context/string", WritableContextTest.STRING_VAL);
-        map.put("a/b/c/d/e/string", WritableContextTest.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));
+        // create the contxt
+        context = new WritableContext();
 
-        Context context = new WritableContext();
-        bind(context, map);
-
-        assertEq(map, context);
-
-        // remove from an exisitng node
-        map.remove("a/b/c/d/e/three");
-        context.unbind("a/b/c/d/e/three");
-
-        assertEq(map, context);
-    }
-
-    public static void bind(Context context, Map bindings) throws NamingException {
+        // bind the bindings
         for (Iterator iterator = bindings.entrySet().iterator(); iterator.hasNext();) {
             Map.Entry entry = (Map.Entry) iterator.next();
             String name = (String) entry.getKey();
@@ -104,11 +63,326 @@
         }
     }
 
-    public static boolean bindingExists(Context context, Name contextName) {
+
+    public void testLookupAndList() throws Exception {
+        assertEq(bindings, context);
+    }
+
+    public void testLookupExceptions() throws Exception{
+        //
+        // lookup a non-existing value of an exisitng context
+        //
+        try {
+            context.lookup("a/b/c/d/e/NoSuchValue");
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+
+        try {
+            context.lookup(parse("a/b/c/d/e/NoSuchValue"));
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+
+        //
+        // lookup a non-existing value of a non-exisitng context
+        //
+        try {
+            context.list("a/b/NoSuchContext/NoSuchContext");
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        try {
+            context.list(parse("a/b/NoSuchContext/NoSuchContext"));
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        //
+        // lookup null
+        //
+        try {
+            context.lookup((String)null);
+            fail("Expected NotContextException");
+        } catch (NullPointerException expected) {
+        }
+
+        try {
+            context.lookup((Name)null);
+        } catch (NullPointerException expected) {
+        }
+
+    }
+
+    public void testLookupLinkExceptions() throws Exception{
+        //
+        // lookupLink a non-existing value of an exisitng context
+        //
+        try {
+            context.lookupLink("a/b/c/d/e/NoSuchValue");
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+
+        try {
+            context.lookupLink(parse("a/b/c/d/e/NoSuchValue"));
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+
+        //
+        // lookupLink a non-existing value of a non-exisitng context
+        //
+        try {
+            context.list("a/b/NoSuchContext/NoSuchContext");
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        try {
+            context.list(parse("a/b/NoSuchContext/NoSuchContext"));
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        //
+        // lookupLink null
+        //
+        try {
+            context.lookupLink((String)null);
+            fail("Expected NotContextException");
+        } catch (NullPointerException expected) {
+        }
+
+        try {
+            context.lookupLink((Name)null);
+        } catch (NullPointerException expected) {
+        }
+
+    }
+
+    public void testListExceptions() throws Exception{
+        //
+        // list a non-existing subcontext of an exisitng context
+        //
+        try {
+            context.list("a/b/c/d/e/NoSuchContext");
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        try {
+            context.list(parse("a/b/c/d/e/NoSuchContext"));
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        //
+        // list a non-existing subcontext of a non-exisitng context
+        //
+        try {
+            context.list("a/b/NoSuchContext/NoSuchContext");
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        try {
+            context.list(parse("a/b/NoSuchContext/NoSuchContext"));
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        //
+        // list a binding that is a value instead of a context
+        //
+        try {
+            context.list("a/b/c/d/e/three");
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        try {
+            context.list(parse("a/b/c/d/e/three"));
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        //
+        // list null
+        //
+        try {
+            context.list((String)null);
+            fail("Expected NotContextException");
+        } catch (NullPointerException expected) {
+        }
+
+        try {
+            context.list((Name)null);
+        } catch (NullPointerException expected) {
+        }
+
+    }
+
+    public void testListBindingsExceptions() throws Exception{
+        //
+        // listBindings a non-existing subcontext of an exisitng context
+        //
+        try {
+            context.listBindings("a/b/c/d/e/NoSuchContext");
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        try {
+            context.listBindings(parse("a/b/c/d/e/NoSuchContext"));
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        //
+        // listBindings a non-existing subcontext of a non-exisitng context
+        //
         try {
-            return context.lookup(contextName) != null;
-        } catch (NamingException e) {
+            context.listBindings("a/b/NoSuchContext/NoSuchContext");
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
         }
-        return false;
+
+        try {
+            context.listBindings(parse("a/b/NoSuchContext/NoSuchContext"));
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        //
+        // listBindings a binding that is a value instead of a context
+        //
+        try {
+            context.listBindings("a/b/c/d/e/three");
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        try {
+            context.listBindings(parse("a/b/c/d/e/three"));
+            fail("Expected NameNotFoundException");
+        } catch (NotContextException expected) {
+        }
+
+        //
+        // listBindings null
+        //
+        try {
+            context.listBindings((String)null);
+            fail("Expected NotContextException");
+        } catch (NullPointerException expected) {
+        }
+
+        try {
+            context.listBindings((Name)null);
+        } catch (NullPointerException expected) {
+        }
+
+    }
+
+    public void testBind() throws Exception {
+        // bind(String)
+        bindings.put("a/b/c/d/e/forty-two", new Integer(42));
+        context.bind("a/b/c/d/e/forty-two", new Integer(42));
+
+        assertEq(bindings, context);
+
+        // bind(Name)
+        bindings.put("a/b/c/d/e/forty-four", new Integer(44));
+        context.bind(parse("a/b/c/d/e/forty-four"), new Integer(44));
+
+        assertEq(bindings, context);
+    }
+
+    public void testUnbind() throws Exception {
+        // unbind(String)
+        bindings.remove("a/b/c/d/e/three");
+        context.unbind("a/b/c/d/e/three");
+
+        assertEq(bindings, context);
+
+        // unbind(Name)
+        bindings.remove("a/b/c/d/e/two");
+        context.unbind(parse("a/b/c/d/e/two"));
+
+        assertEq(bindings, context);
+    }
+
+    public void testRebind() throws Exception {
+        // rebind(String)
+        bindings.put("a/b/c/d/e/three", new Integer(33));
+        context.rebind("a/b/c/d/e/three", new Integer(33));
+
+        assertEq(bindings, context);
+
+        // rebind(Name)
+        bindings.put("a/b/c/d/e/three", new Integer(33333));
+        context.rebind(parse("a/b/c/d/e/three"), new Integer(33333));
+
+        assertEq(bindings, context);
+    }
+
+    public void testRename() throws Exception {
+        // rename(String, String)
+        Object value = bindings.remove("a/b/c/d/e/three");
+        bindings.put("a/b/c/d/e/boo", value);
+        context.rename("a/b/c/d/e/three", "a/b/c/d/e/boo");
+
+        assertEq(bindings, context);
+
+        // rename(Name, Name)
+        value = bindings.remove("a/b/c/d/e/boo");
+        bindings.put("a/b/c/d/e/moo", value);
+        context.rename(parse("a/b/c/d/e/boo"), parse("a/b/c/d/e/moo"));
+
+        assertEq(bindings, context);
+    }
+
+    public void testCreateSubcontext() throws Exception {
+        // createSubcontext(String)
+        bindings.put("a/b/c/d/e/f/foo", "bar");
+        context.createSubcontext("a/b/c/d/e/f");
+        context.bind("a/b/c/d/e/f/foo", "bar");
+
+        assertEq(bindings, context);
+
+        // createSubcontext(Name)
+        bindings.put("a/b/c/d/e/f2/foo", "bar");
+        context.createSubcontext(parse("a/b/c/d/e/f2"));
+        context.bind(parse("a/b/c/d/e/f2/foo"), "bar");
+
+        assertEq(bindings, context);
+    }
+
+    public void testDestroySubcontext() throws Exception {
+        // destroySubcontext(String)
+        bindings.put("a/b/c/d/e/f/foo", "bar");
+        context.createSubcontext("a/b/c/d/e/f");
+        context.bind("a/b/c/d/e/f/foo", "bar");
+        assertEq(bindings, context);
+
+        bindings.remove("a/b/c/d/e/f/foo");
+        context.unbind("a/b/c/d/e/f/foo");
+        context.destroySubcontext("a/b/c/d/e/f");
+
+        assertEq(bindings, context);
+
+        // destroySubcontext(Name)
+        bindings.put("a/b/c/d/e/f2/foo", "bar");
+        context.createSubcontext(parse("a/b/c/d/e/f2"));
+        context.bind(parse("a/b/c/d/e/f2/foo"), "bar");
+        assertEq(bindings, context);
+
+        bindings.remove("a/b/c/d/e/f2/foo");
+        context.unbind(parse("a/b/c/d/e/f2/foo"));
+        context.destroySubcontext(parse("a/b/c/d/e/f2"));
+
+        assertEq(bindings, context);
     }
 }



Mime
View raw message