1 16 package org.apache.naming.java; 17 18 import java.util.Hashtable ; 19 import javax.naming.Context ; 20 21 import org.apache.naming.ContextBindings; 22 import org.apache.naming.NamingContext; 23 import org.apache.naming.SelectorContext; 24 import org.apache.naming.SynchronizedContext; 25 26 import junit.framework.Test; 27 import junit.framework.TestCase; 28 import junit.framework.TestSuite; 29 import junit.textui.TestRunner; 30 31 35 public class JavaURLContextFactoryTest extends TestCase { 36 37 public JavaURLContextFactoryTest(String name) { 38 super(name); 39 } 40 41 public static void main(String [] args) { 42 TestRunner.run(suite()); 43 } 44 45 public static Test suite() { 46 TestSuite suite = new TestSuite(JavaURLContextFactoryTest.class); 47 suite.setName("JavaURLContextFactory Tests"); 48 return suite; 49 } 50 51 protected javaURLContextFactory contextFactory = new javaURLContextFactory(); 52 53 public void testGetInitialContext() throws Exception { 54 Hashtable env = new Hashtable (); 56 Context ctx = contextFactory.getInitialContext(env); 57 assertTrue(ctx instanceof NamingContext); 58 ContextBindings.bindContext("ctxName", ctx); 59 60 ContextBindings.bindThread("ctxName"); 62 Context selCtx = contextFactory.getInitialContext(env); 63 assertTrue(selCtx instanceof SelectorContext); 64 65 env.put(SynchronizedContext.SYNCHRONIZED, "true"); 68 Context unSynchCtx = contextFactory.getInitialContext(env); 69 assertTrue(unSynchCtx instanceof SelectorContext); 70 71 ContextBindings.unbindThread("ctxName"); 73 unSynchCtx = contextFactory.getInitialContext(env); 74 assertTrue(unSynchCtx instanceof NamingContext); 75 javaURLContextFactory.initialContext = null; 77 78 env.put(SynchronizedContext.SYNCHRONIZED, "true"); 80 Context synchCtx = contextFactory.getInitialContext(env); 81 assertTrue(synchCtx instanceof SynchronizedContext); 82 } 83 84 public void testGetObjectInstance() throws Exception { 85 Hashtable env = new Hashtable (); 87 Context ctx = contextFactory.getInitialContext(env); 88 ContextBindings.bindContext("ctxName", ctx); 89 90 Object obj = contextFactory.getObjectInstance(null, null, null, env); 92 assertNull(obj); 93 94 ContextBindings.bindThread("ctxName"); 96 Context getCtx = (Context ) contextFactory.getObjectInstance(null, null, null, env); 97 assertTrue(getCtx instanceof SelectorContext); 98 } 99 } 100 | Popular Tags |