0 Replies Latest reply on May 23, 2014 3:59 AM by Andy Ng

    Using Arquillian without maven on RSA Java project

    Andy Ng Newbie

      I'm trying to use Arquillian in my project to unit test my EJB 3 session bean. Since my project is not build and manage using maven, I have manually include the dependency into my project (Rational Software Architect java project). When I try to start my JUnit test, I received following error during start up of glassfish-embedded 3.1.2:

      WARNING: Problem in publishing temp proxy for MEJB: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
      javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
        at com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:102)
        at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:84)
        at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:601)
        at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:550)
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:398)
        at javax.naming.InitialContext.rebind(InitialContext.java:431)
        at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:206)
        at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:189)
        at org.glassfish.kernel.javaee.MEJBService.postConstruct(MEJBService.java:81)
        at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)
        at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
        at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
        at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
        at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
        at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:78)
        at com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:229)
        at com.sun.enterprise.v3.server.AppServerStartup.doStart(AppServerStartup.java:145)
        at com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:136)
        at com.sun.enterprise.glassfish.bootstrap.GlassFishImpl.start(GlassFishImpl.java:79)
        at org.jboss.arquillian.container.glassfish.embedded_3_1.GlassFishContainer.start(GlassFishContainer.java:153)
        at org.jboss.arquillian.container.impl.ContainerImpl.start(ContainerImpl.java:199)
        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$8.perform(ContainerLifecycleController.java:163)
        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$8.perform(ContainerLifecycleController.java:157)
        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forContainer(ContainerLifecycleController.java:255)
        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.startContainer(ContainerLifecycleController.java:156)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
        at org.jboss.arquillian.container.impl.client.ContainerDeploymentContextHandler.createContainerContext(ContainerDeploymentContextHandler.java:57)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$2.perform(ContainerLifecycleController.java:77)
        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$2.perform(ContainerLifecycleController.java:70)
        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forEachSuiteContainer(ContainerLifecycleController.java:221)
        at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.startSuiteContainers(ContainerLifecycleController.java:69)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
        at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:86)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeSuite(EventTestRunnerAdaptor.java:68)
        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:97)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      
      
      
      
      
      

       

      If I understood the problem correctly, there is a problem setting up the JNDI context for glassfish. Even though I have included a jndi.properties in my classpath, specifying the following:

      java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory
      java.naming.factory.url.pkgs=com.sun.enterprise.naming
      java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
      
      
      
      
      
      

       

      However, glassfish-embedded doesn't seems to pickup my jndi.properties and it continue to use the IBM ws runtime jndi configuration thus the same error occur. The IBM jndi configuration is as follow:

      java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
      java.naming.factory.url.pkgs=com.ibm.ws.naming
      
      
      
      
      
      

       

      Here's my code:

      @RunWith(Arquillian.class)
      public class TestSubmissionService {
      
           @Deployment
           public static Archive<?> createDeployment() {
                WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
                     .addPackage(FlowInstance.class.getPackage())
                     .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                     .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
                return war;
           }
      
           @EJB
           private FlowServiceLocal service;
      
           @PersistenceContext(unitName = "myPU")
           private EntityManager em;
      
           private FlowType flowType;
           private List<FlowEngineStep<?>> flowSteps;
      
           @Before
           public void setup() {
                flowType = new FlowType();
                flowType.setOid(Long.valueOf(1l));
                flowType.setType("SUBMISSION");
                em.persist(flowType);
      
                flowSteps.add(new StoreAttachmentsStep());
                flowSteps.add(new SaveBizDataStep());
           }
      
           @Test
           public void testCreateSubmission() {
                FlowInstance flowInstance = service.createFlowInstance(flowType, flowSteps);
                Assert.assertNotNull(flowInstance);
           }
      
      }
      
      
      
      
      

       

      persistence.xml

      ...
      <persistence-unit name="myPU" transaction-type="JTA">
           <provider>org.hibernate.ejb.HibernatePersistence</provider>
           <jta-data-source>jdbc/customer</jta-data-source>
      
           <class>dk.sebpension.flow.entity.FlowInstance</class>
           <class>dk.sebpension.flow.entity.FlowStep</class>
           ...
      
           <exclude-unlisted-classes>true</exclude-unlisted-classes>
           <properties>
                <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
                <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                <property name="hibernate.show_sql" value="true"/>
           </properties>
      </persistence-unit>
      
      
      
      
      
      

       

      glassfish-resources.xml

      <resources>
         
           
      <jdbc-resource pool-name="ArquillianEmbeddedH2Pool"
        jndi-name="jdbc/customer"/>
        <jdbc-connection-pool name="ArquillianEmbeddedH2Pool"
        res-type="javax.sql.DataSource"
        datasource-classname="org.h2.jdbcx.JdbcDataSource">
        <property name="user" value="sa"/>
        <property name="password" value=""/>
        <property name="url" value="jdbc:h2:file:target/databases/h2/db"/>
        </jdbc-connection-pool>
      
      
      </resources>
      
      
      
      
      
      

       

      I'm running my test class from within RSA as a JUnit Test. Thus I setup all dependency in eclipse "Java Build Path" and my installed JRE is a standard JDK7 instead of the default RSA IBM JRE.