-
1. Re: JUnit testing EJBs: NoInitialContextException
peterj Sep 7, 2006 2:15 PM (in response to humm)Create a jndi.properties file, place it in the classpath (usually in the base directory of the jar file), with these contents:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=localhost:1099 java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Of course, replace locahost with your host name if you are attempting remote access.
You can also provide those same properties within the application by creating a hash map and passing it to the InitialContext constructor. -
2. Re: JUnit testing EJBs: NoInitialContextException
alrubinger Sep 7, 2006 2:20 PM (in response to humm)From within the container, your InitialContext will be configured properly when using the default constructor. From a remote client (another JVM, like your JUnit Test), this isn't the case, and you'll have to get your context:
Hashtable<String, String> props= new Hashtable<String, String>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(Context.PROVIDER_URL,"jnp://localhost:1099" ); props.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces" ); Context ctx = new InitialContext( props );
..replacing the host and port in Context.PROVIDER_URL with something appropriate.
Dependency injection...you'll have to do a lookup for that bean using the Context above - you'll only be able to inject container-managed resources into other container-managed resources.
S,
ALR -
3. Re: JUnit testing EJBs: NoInitialContextException
aberezin Sep 7, 2006 2:37 PM (in response to humm)Also, for a remote client junit test, I didnt see a jboss client jar in the lastest 4.04ga release. I found I had to add a bunch of jboss jars to the client runtime classpath. I cant recall what all i added but if it still a problem, I can find out and post another response.
-
4. Re: JUnit testing EJBs: NoInitialContextException
treespace Sep 8, 2006 4:35 PM (in response to humm)Cactus provides an excellent in-container test facility:
http://jakarta.apache.org/cactus/
I am using with JBoss 4.X to test session and by extension entity beans.