directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r123173 - /incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java
Date Thu, 23 Dec 2004 07:15:41 GMT
Author: psteitz
Date: Wed Dec 22 23:15:39 2004
New Revision: 123173

URL: http://svn.apache.org/viewcvs?view=rev&rev=123173
Log:
Added test cases verifying name parsing and context delegation.
Modified:
   incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java

Modified: incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java?view=diff&rev=123173&p1=incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java&r1=123172&p2=incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java&r2=123173
==============================================================================
--- incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java
(original)
+++ incubator/directory/naming/trunk/core/src/test/org/apache/naming/SelectorContextTest.java
Wed Dec 22 23:15:39 2004
@@ -18,6 +18,8 @@
 import java.util.Hashtable;
 
 import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.NameNotFoundException;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -47,5 +49,53 @@
     
     protected Context makeInitialContext() {
     	return new SelectorContext(new Hashtable(), true);
+    }
+    
+    public void testGetNameInNamespace() throws Exception {
+        assertEquals(SelectorContext.prefix, initialContext.getNameInNamespace());
+    }
+        
+    public void testParseName() throws Exception {
+        try {
+            initialContext.lookup("java:x");
+        } catch (NameNotFoundException ex) {
+            // expected 
+        }
+        try {
+            initialContext.lookup("hava:x");
+        } catch (NamingException ex) {
+            // expected 
+        }     
+    }
+    
+    public void testGetBoundContext() throws Exception {
+       
+        Context initCtx = new SelectorContext(new Hashtable(), true);
+        // Initial context should be bound under the name IC_PREFIX
+        initCtx.bind("java:comp:a", "initial");
+        assertEquals("initial", ContextBindings.getContext
+                (SelectorContext.IC_PREFIX).lookup("java:comp:a"));
+        
+        // Bind classloader 
+        Context clContext = new NamingContext(new Hashtable(), "cl");
+        clContext.bind("a", "classloader");
+        ContextBindings.bindContext("cl", clContext);
+        ContextBindings.bindClassLoader("cl");  
+        
+        // Get a SelectorContext that is not an initial context 
+        Context selCtx = new SelectorContext(new Hashtable(), false);
+        // lookup should strip URL header, then delegate to clContext
+        assertEquals("classloader", (String) selCtx.lookup("java:a")); // URL is stripped
+        
+        // Now bind thread 
+        Context threadContext = new NamingContext(new Hashtable(), "th");
+        threadContext.bind("a", "thread");
+        ContextBindings.bindContext("th", threadContext);
+        ContextBindings.bindThread("th");
+        // thread binding takes precedence, so threadContext should get the call
+        assertEquals("thread", (String) selCtx.lookup("java:a")); // URL is stripped
+        
+        // Fix up so teardown does not blow
+        initialContext.createSubcontext(firstContextName());
     }
 }

Mime
View raw message