1 22 package org.jboss.test.naming.test; 23 24 import java.util.Properties ; 25 import javax.naming.Context ; 26 import javax.naming.InitialContext ; 27 import javax.naming.NameAlreadyBoundException ; 28 import javax.naming.NameClassPair ; 29 import javax.naming.NameNotFoundException ; 30 import javax.naming.NamingEnumeration ; 31 import javax.naming.NamingException ; 32 33 import junit.framework.Test; 34 import org.jboss.test.JBossTestCase; 35 36 41 public class PooledInvokerUnitTestCase extends JBossTestCase 42 { 43 48 public PooledInvokerUnitTestCase(String name) 49 { 50 super(name); 51 } 52 53 58 public void testCreateSubcontext() throws Exception 59 { 60 getLog().debug("+++ testCreateSubcontext"); 61 Properties env = new Properties (); 62 env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 63 env.setProperty(Context.PROVIDER_URL, "jnp://localhost:10999/"); 64 env.setProperty("jnp.disableDiscovery", "true"); 65 InitialContext ctx = new InitialContext (env); 66 ctx.createSubcontext("foo"); 67 try 68 { 69 ctx.createSubcontext("foo"); 70 fail("Second createSubcontext(foo) did NOT fail"); 71 } 72 catch (NameAlreadyBoundException e) 73 { 74 getLog().debug("Second createSubcontext(foo) failed as expected"); 75 } 76 ctx.createSubcontext("foo/bar"); 77 ctx.unbind("foo/bar"); 78 ctx.unbind("foo"); 79 } 80 81 85 public void testLookup() throws Exception 86 { 87 getLog().debug("+++ testLookup"); 88 Properties env = new Properties (); 89 env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 90 env.setProperty(Context.PROVIDER_URL, "jnp://localhost:10999/"); 91 env.setProperty("jnp.disableDiscovery", "true"); 92 InitialContext ctx = new InitialContext (env); 93 Object obj = ctx.lookup(""); 94 getLog().debug("lookup('') = "+obj); 95 } 96 97 public void testListing() throws Exception 98 { 99 log.debug("+++ testListing"); 100 InitialContext ctx = getInitialContext(); 101 NamingEnumeration names = ctx.list(""); 102 int count = 0; 103 while( names.hasMore() ) 104 { 105 NameClassPair ncp = (NameClassPair ) names.next(); 106 log.info(ncp); 107 count ++; 108 } 109 log.info("list count = "+count); 110 assertTrue("list count > 0 ", count > 0); 111 ctx.close(); 112 } 113 114 118 public void testLookupFailures() throws Exception 119 { 120 log.debug("+++ testLookupFailures"); 121 Properties env = new Properties (); 123 env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 124 env.setProperty(Context.PROVIDER_URL, "jnp://localhost:10999/"); 125 env.setProperty("jnp.disableDiscovery", "true"); 126 InitialContext ctx = new InitialContext (env); 127 try 128 { 129 Object obj = ctx.lookup("__bad_name__"); 130 fail("lookup(__bad_name__) should have thrown an exception, obj="+obj); 131 } 132 catch(NameNotFoundException e) 133 { 134 log.debug("lookup(__bad_name__) failed as expected", e); 135 } 136 137 env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 139 env.setProperty(Context.PROVIDER_URL, "jnp://localhost:65535/"); 140 env.setProperty("jnp.disableDiscovery", "true"); 141 log.debug("Creating InitialContext with env="+env); 142 try 143 { 144 ctx = new InitialContext (env); 145 Object obj = ctx.lookup(""); 146 fail("lookup('') should have thrown an exception, obj="+obj); 147 } 148 catch(NamingException e) 149 { 150 log.debug("lookup('') failed as expected", e); 151 } 152 } 153 154 public static Test suite() throws Exception 155 { 156 return getDeploySetup(PooledInvokerUnitTestCase.class, "naming-pooled.sar"); 157 } 158 159 } 160 | Popular Tags |