1 16 package org.apache.naming; 17 18 import java.util.Hashtable ; 19 20 import javax.naming.Context ; 21 import javax.naming.NamingException ; 22 import javax.naming.NameNotFoundException ; 23 24 import junit.framework.Test; 25 import junit.framework.TestSuite; 26 import junit.textui.TestRunner; 27 28 29 34 public class SelectorContextTest extends AbstractContextTest { 35 36 public SelectorContextTest(String name) { 37 super(name); 38 } 39 40 public static void main(String [] args) { 41 TestRunner.run(suite()); 42 } 43 44 public static Test suite() { 45 TestSuite suite = new TestSuite(SelectorContextTest.class); 46 suite.setName("Selector Context Tests"); 47 return suite; 48 } 49 50 protected Context makeInitialContext() { 51 return new SelectorContext(new Hashtable (), true); 52 } 53 54 public void testGetNameInNamespace() throws Exception { 55 assertEquals(SelectorContext.prefix, initialContext.getNameInNamespace()); 56 } 57 58 public void testParseName() throws Exception { 59 try { 60 initialContext.lookup("java:x"); 61 } catch (NameNotFoundException ex) { 62 } 64 try { 65 initialContext.lookup("hava:x"); 66 } catch (NamingException ex) { 67 } 69 } 70 71 public void testGetBoundContext() throws Exception { 72 73 Context initCtx = new SelectorContext(new Hashtable (), true); 74 initCtx.bind("java:comp:a", "initial"); 76 assertEquals("initial", ContextBindings.getContext 77 (SelectorContext.IC_PREFIX).lookup("java:comp:a")); 78 79 Context clContext = new NamingContext(new Hashtable (), "cl"); 81 clContext.bind("a", "classloader"); 82 ContextBindings.bindContext("cl", clContext); 83 ContextBindings.bindClassLoader("cl"); 84 85 Context selCtx = new SelectorContext(new Hashtable (), false); 87 assertEquals("classloader", (String ) selCtx.lookup("java:a")); 90 Context threadContext = new NamingContext(new Hashtable (), "th"); 92 threadContext.bind("a", "thread"); 93 ContextBindings.bindContext("th", threadContext); 94 ContextBindings.bindThread("th"); 95 assertEquals("thread", (String ) selCtx.lookup("java:a")); 98 initialContext.createSubcontext(firstContextName()); 100 } 101 } 102 | Popular Tags |