1 Reply Latest reply on Sep 18, 2003 2:22 PM by Dennis Cartier

    Using Junit with JNDI Datasources

    Dennis Cartier Newbie

      Hello,

      I am going to ask this in the Beginners Corner as I am not sure which forum it really belongs in.

      I am attempting to use junit to test a Command bean that uses a pooled datasource bound to JNDI. When this bean is used from inside the App server, everything works fine. When junit attempts to instantiate and test the bean, the bean is unable to lookup the JNDI context.

      Here is the first section of the output. The complete trace is quite long so I truncated it.

      junit:
      [junit] Running com.blkbk.cbbonline.TestCBBOnlineAuthCmdBean
      [junit] javax.naming.NameNotFoundException: MSSQLDS not bound
      [junit] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      [junit] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      [junit] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      [junit] at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
      [junit] at sun.reflect.GeneratedMethodAccessor175.invoke(Unknown Source)
      [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
      [junit] at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
      [junit] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:278)
      [junit] at sun.rmi.transport.Transport$1.run(Transport.java:163)
      [junit] at java.security.AccessController.doPrivileged(Native Method)
      [junit] at sun.rmi.transport.Transport.serviceCall(Transport.java:159)
      [junit] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:477)
      [junit] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:718)
      [junit] at java.lang.Thread.run(Thread.java:568)
      [junit] at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:263)
      [junit] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:239)
      [junit] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:148)
      [junit] at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      [junit] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:484)
      [junit] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:463)
      [junit] at javax.naming.InitialContext.lookup(InitialContext.java:360)
      [junit] at com.blkbk.cbbonline.CBBOnlineAuthCmdBean.execute(CBBOnlineAuthCmdBean.java:50)
      [junit] at com.blkbk.cbbonline.TestCBBOnlineAuthCmdBean.testGoodLogin(TestCBBOnlineAuthCmdBean.java:26)
      [junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
      [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:41)
      [junit] at java.lang.reflect.Method.invoke(Method.java:371)
      [junit] at junit.framework.TestCase.runTest(TestCase.java:154)
      [junit] at junit.framework.TestCase.runBare(TestCase.java:127)
      [junit] at junit.framework.TestResult$1.protect(TestResult.java:106)
      [junit] at junit.framework.TestResult.runProtected(TestResult.java:124)
      [junit] at junit.framework.TestResult.run(TestResult.java:109)
      [junit] at junit.framework.TestCase.run(TestCase.java:118)
      [junit] at junit.framework.TestSuite.runTest(TestSuite.java:208)
      [junit] at junit.framework.TestSuite.run(TestSuite.java:203)
      [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:325)
      [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:848)
      [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:556)
      [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:532)
      [junit] at org.apache.tools.ant.Task.perform(Task.java:341)
      [junit] at org.apache.tools.ant.Target.execute(Target.java:309)
      [junit] at org.apache.tools.ant.Target.performTasks(Target.java:336)
      [junit] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
      [junit] at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
      [junit] at org.apache.tools.ant.Main.runBuild(Main.java:609)
      [junit] at org.apache.tools.ant.Main.start(Main.java:196)
      [junit] at org.apache.tools.ant.Main.main(Main.java:235)
      [junit] Failed to lookup the JNDI context
      [junit] javax.naming.NameNotFoundException: MSSQLDS not bound


      Contents of my jndi.properties file (in the classpath of the build.xml)

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=localhost


      I would guess this relates to the bean not running inside the app server while junit is testing it. I have the all the jar files in the JBoss client directory in the build.xml classpath.

      I am dawing a blank on how to fix this. Any pointers would be appreciated.

      Dennis