5 Replies Latest reply on Dec 15, 2011 11:58 AM by Aslak Knutsen

    Cannot use JNDI lookup in Arquillian

    Hiep Le Canh Newbie

      I have an issue when I am getting a bean by using EJB injection. Below is what I am doing:

       

      @RunWith(Arquillian.class)

      public class ITArquillianTest {

       

          //MyManager interface already exist in myear's module.

          @EJB

          MyManager myManager;

         

          @Deployment(testable=false)

          public static EnterpriseArchive  createDeployment() {

              EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class,"myear.ear");

             

              //this ear file is already deploy successfully in JBoss 7, so I extract to D:\\cygwin\\home\\...\\myear for creating Arquillian ear.

              ear.as(ExplodedImporter.class).

                  importDirectory(new File("D:\\cygwin\\home\\...\\myear"));

             

              return ear; 

          }

         

          @Test

          public void testIfNotNull() throws Exception {

              Assert.assertNotNull("null", myManager);     //----> myManager return null

          }

      }

       

      I do not know why myManager always return null. Please let me know how to fix it

       

      Thanks

        • 2. Re: Cannot use JNDI lookup in Arquillian
          Hiep Le Canh Newbie

          Thanks Aslak for your answer but it seems not working. I am using @EJB(mappedName="MyManagerBean") and add @Stateless(mappedName="MyManagerBean") in MyManagerBean class but it does not work.

           

          I also try to get that object by using JNDI name like:

           

          Context ic = getContext();
          obj = ic.lookup("java:global/earName/jarName/beanName");  
          //.........


          Below is getContext() method:

          Context getContext() throws NamingException {
              Hashtable<String, String> ht = new Hashtable<String, String>();
              ht.put(Context.INITIAL_CONTEXT_FACTORY,
                      "org.jboss.as.naming.InitialContextFactory");

              return new InitialContext(ht);
          }

           

          but the exception is thrown. Could you please give me some idea to fix it?

           

          Thanks

          • 3. Re: Cannot use JNDI lookup in Arquillian
            Aslak Knutsen Master

            When you run the test, in eht ejboss as 7 console output you should see where the EJB is bound.. Does it not work to put on of those jndi names in EJB.mappedName ?

            • 4. Re: Cannot use JNDI lookup in Arquillian
              Hiep Le Canh Newbie

              Yes, Aslak. I try to use these JNDI names:

               

              java:global/projectname/aa-api/MyBean!com.projectname.aa.api.MyInterface

              java:app/aa-api/MyBean!com.projectname.aa.api.MyInterface

              java:module/MyBean!com.projectname.aa.api.MyInterface

              java:global/projectname/aa-api/MyInterface

              java:app/aa-api/MyInterface

              java:module/MyInterface

               

              But all of them do not work (MyBean still null). I am wondering that I am using the right annotation for deployment method or not. Currently I am using :

               

              @Deployment(testable=false)

                  public static EnterpriseArchive  createDeployment() {...}

               

              I think I should change testable to true instead of false, right?. But when I change it to true. The exception is thrown (after both arquillian-service and my ear was deployed successful) . Below is the exception:

               

              Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 69.044 sec <<< FAILURE!

              23:36:14,275 INFO  [org.jboss.as.osgi] (MSC service thread 1-2) JBAS011922: Unregister module: Module "deployment.arquillian-service:main" f

              rom Service Module Loader

              23:36:14,277 ERROR [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-2) Cannot find bundle associated with module: dep

              loyment.arquillian-service:main

              23:36:14,279 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) Stopped deployment arquillian-service in 5ms

              23:36:14,289 INFO  [org.jboss.as.server.controller] (pool-1-thread-1) Undeployed "arquillian-service"

               

              Results :

               

              Tests in error:

              .....

               

              Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

               

              Please let my know you idea on that.

               

              Thanks

              • 5. Re: Cannot use JNDI lookup in Arquillian
                Aslak Knutsen Master

                testable=false means you will executing on the client side and all your EJBs need to be Remoteable to be reached.

                 

                The exception your seeing is most likely related to this, or atleast you can try the same solution: http://community.jboss.org/message/623963