geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r759067 - in /geronimo/xbean/trunk/xbean-naming/src: main/java/org/apache/xbean/naming/context/WritableContext.java test/java/org/apache/xbean/naming/context/WritableContextTest.java
Date Fri, 27 Mar 2009 09:16:12 GMT
Author: xuhaihong
Date: Fri Mar 27 09:16:06 2009
New Revision: 759067

URL: http://svn.apache.org/viewvc?rev=759067&view=rev
Log:
XBEAN-122 Object cannot be removed from context in many circumstances, Thanks for the patch,
Jack Cai !

Modified:
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
    geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java?rev=759067&r1=759066&r2=759067&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
Fri Mar 27 09:16:06 2009
@@ -120,11 +120,11 @@
         if (super.removeBinding(name, removeNotEmptyContext)) {
             return true;
         }
-        removeBinding(bindingsRef, name, removeNotEmptyContext);
+        removeBinding(bindingsRef, name, getNameInNamespace(name), removeNotEmptyContext);
         return true;
     }
 
-    private boolean removeBinding(AtomicReference<Map<String, Object>> bindingsRef,
String name, boolean removeNotEmptyContext) throws NamingException {
+    private boolean removeBinding(AtomicReference<Map<String, Object>> bindingsRef,
String name, String nameInNamespace, boolean removeNotEmptyContext) throws NamingException
{
         writeLock.lock();
         try {
             Map<String, Object> bindings = bindingsRef.get();
@@ -140,7 +140,7 @@
             }
             bindingsRef.set(newBindings);
 
-            Map<String, Object> newIndex = removeFromIndex(name);
+            Map<String, Object> newIndex = removeFromIndex(nameInNamespace);
             indexRef.set(newIndex);
             return true;
         } finally {
@@ -234,7 +234,7 @@
         }
 
         protected boolean removeBinding(String name, boolean removeNotEmptyContext) throws
NamingException {
-            if (WritableContext.this.removeBinding(bindingsRef, name, false)) {
+            if (WritableContext.this.removeBinding(bindingsRef, name, getNameInNamespace(name),
removeNotEmptyContext)) {
                 return true;
             }
             return super.removeBinding(name, false);

Modified: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java?rev=759067&r1=759066&r2=759067&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java
Fri Mar 27 09:16:06 2009
@@ -908,5 +908,67 @@
         w.rebind("test/test/GBean/resourceSource", 1);
         assertEquals(new Integer(1), w.lookup("test/test/GBean/resourceSource"));
     }
+    
+    public void testRemoveDeepBinding_Leaf() throws Exception {
+        WritableContext w = new WritableContext("jca:");
+        // Test when only one object
+        w.addDeepBinding(w.getNameParser("").parse("test/test/GBean/resourceSource"), WritableContextTest.STRING_VAL,
true, true);
+        assertEquals(WritableContextTest.STRING_VAL, w.lookup("test/test/GBean/resourceSource"));
+        w.removeDeepBinding(w.getNameParser("").parse("test/test/GBean/resourceSource"),
true, true);
+        try {
+        	w.lookup("test");
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+        w.addDeepBinding(w.getNameParser("").parse("test/test/GBean/resourceSource"), WritableContextTest.STRING_VAL,
true, true);
+        assertEquals(WritableContextTest.STRING_VAL, w.lookup("test/test/GBean/resourceSource"));
+        w.addDeepBinding(w.getNameParser("").parse("test/test/GBean/rresourceSource2"), new
Integer(2), true, true);
+        assertEquals(new Integer(2), w.lookup("test/test/GBean/rresourceSource2"));
+
+        w.removeDeepBinding(w.getNameParser("").parse("test/test/GBean/resourceSource"),
true, true);
+        assertEquals(new Integer(2), w.lookup("test/test/GBean/rresourceSource2"));
+        try {
+            w.lookup("test/test/GBean/resourceSource");
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+        w.removeDeepBinding(w.getNameParser("").parse("test/test/GBean/rresourceSource2"),
true, true);
+        try {
+        	w.lookup("test");
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+    }
+    
+    public void testRemoveDeepBinding_Intermediate() throws Exception {
+        WritableContext w = new WritableContext("jca:");
+        // Test when only one object
+        w.addDeepBinding(w.getNameParser("").parse("test/test1/GBean/resourceSource"), WritableContextTest.STRING_VAL,
true, true);
+        assertEquals(WritableContextTest.STRING_VAL, w.lookup("test/test1/GBean/resourceSource"));
+        w.removeDeepBinding(w.getNameParser("").parse("test/test1/GBean/resourceSource"),
true, true);
+        try {
+        	w.lookup("test");
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+        w.addDeepBinding(w.getNameParser("").parse("test/test1/GBean/resourceSource"), WritableContextTest.STRING_VAL,
true, true);
+        assertEquals(WritableContextTest.STRING_VAL, w.lookup("test/test1/GBean/resourceSource"));
+        w.addDeepBinding(w.getNameParser("").parse("test/test2/GBean/rresourceSource2"),
new Integer(2), true, true);
+        assertEquals(new Integer(2), w.lookup("test/test2/GBean/rresourceSource2"));
+
+        w.removeDeepBinding(w.getNameParser("").parse("test/test1/GBean/resourceSource"),
true, true);
+        assertEquals(new Integer(2), w.lookup("test/test2/GBean/rresourceSource2"));
+        try {
+            w.lookup("test/test1");
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+        w.removeDeepBinding(w.getNameParser("").parse("test/test2/GBean/rresourceSource2"),
true, true);
+        try {
+        	w.lookup("test");
+            fail("Expected NameNotFoundException");
+        } catch (NameNotFoundException expected) {
+        }
+    }
 
 }



Mime
View raw message