I have create a JUnit test to which attempts to communicate with a Remote object (EJB 3.0). Because I am outside the container of the app server I accomplish the following:
[code]
public class JtdiSiteFinderTest {
//String JNDI_NAME_SITE_FINDER ="java:comp/env/ejb/JtdiSiteFinder";
String JNDI_NAME_SITE_FINDER ="java:comp/env/ejb/JtdiSiteFinder#jtdi.cm.ejb.bean.session.finder.JtdiSiteFinderRemote";
private JtdiSiteFinderRemote jtdiSiteFinder = null;
@Before
public void prepareFinder(){
try{
Properties p = new Properties();
p.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
p.put("java.naming.provider.url", "corbaloc:iiop:1.2_at_127.0.0.1:3700");
InitialContext ctx = new InitialContext();
//jtdiSiteFinder = (JtdiSiteFinderRemote)ctx.lookup(JtdiSiteFinderRemote.class.getName());
jtdiSiteFinder = (JtdiSiteFinderRemote) ctx.lookup(JNDI_NAME_SITE_FINDER);
}catch(Exception e){
e.printStackTrace();
}
}//end method
@After
public void cleanupFinder(){
}//end method
@Test
public void findJtdiSiteBySiteId(){
JtdiSite jtdiSite = null;
jtdiSite = jtdiSiteFinder.findJtdiSiteBySiteID(9L, 1L);
assertEquals(4, jtdiSite.getSiteId().intValue());
}//end method
}
[/code]
I have tried with the properties file and without. I am getting the following error when I attempt to connect using no properties:
[code]
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at jtdi.cm.ejb.session.finder.test.JtdiSiteFinderTest.prepareFinder(JtdiSiteFinderTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
[/code]
All I am trying to accomplish is connect to a EJB 3.0 bean and call one method from a JUnit client. I have googled most of this information and have created the above method. Any suggestions would be greatly appreciated.
Russ
[Message sent by forum member 'russ205' (russ205)]
http://forums.java.net/jive/thread.jspa?messageID=265782