7 Replies Latest reply on Aug 21, 2012 5:29 AM by aslak

    Arquillian integration tests with existing jar files

    arquillianer

      I cant find anything on how to test my ejb jar and utilities jar file using arquillian and gf embedded ... I've got a module that produce ejb.jar and another one that produced utilities.jar and another one entities.jar and they all are depending on each other... i've got to do integration test on these jars on glassfish embedded in a completely different module ... i just can find on how shrinkwrap can allow me to deploy these jars on gf. I found heaps of samples that test single classes but can't find anything that will help me tests 3 different jars created by different modules ?

       

      Can someone please suggest me something ? May be a code snippet that will help me do the above ?

        • 1. Re: Arquillian integration tests with existing jar files
          aslak

          You probably want to look at ShrinkWrap Dependency Resolver: https://github.com/arquillian/arquillian-showcase/blob/master/multinode/src/test/java/com/acme/multinode/grid/Deployments.java

           

          It will allow you to resolve artifacts from the Maven repository. Optionally you can include libraries just as files as well.

           

          e.g. ShrinkWrap.create(WebArchive.class).addAsLibraries(new File(....))

          • 2. Re: Arquillian integration tests with existing jar files
            arquillianer

            Thanks for the reply Aslak.

             

            So my project structure is

             

            -- EJB.jar (has pom.xml)

            -- Entities.jar (has pom.xml)

            -- Utils.jar (has pom.xml)

            parent pom.xml

             

            Integration-test module (has pom.xml does not have any parent project)

             

            I tried you above mentioned solution and i've gotten this far

             

            @Deployment

                public static EnterpriseArchive createTestArchive() {

                    MavenDependencyResolver resolver = DependencyResolvers.use(

                            MavenDependencyResolver.class).loadMetadataFromPom("pom.xml");

                

                    EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "test.ear").

                            addAsLibraries(resolver.artifact(groupid:ejb:version").

                            resolveAsFiles());

             

                    return ear;

                }

             

            I just added the ejb artifact but I see all the projects being added into the target folder's ear file named _DEFAULT___DEFAULT__test.ear and for some reason test.war is also in the ear folder but I don't need a war file ... and when I check the lib folder I see the ejb project added including report's project and a few others which are not need for our testing. I just need it to add ejb, utils and entities projects and somehow deploy it to the server. Please suggest me how do I do that ?

            • 3. Re: Arquillian integration tests with existing jar files
              arquillianer

              the ejb modules pom.xml is having dependencies to all those other projects (reports etc) ... that's why all the jars are being added. How do I make it to just to add specific jars ?

              • 4. Re: Arquillian integration tests with existing jar files
                aslak

                You can use the StrictFilter to avoid transitive deps:

                 

                resolveAsFiles(new StrictFilter())

                 

                The Resolver doesn't know what types it's resolving or where they should go in the Archive, that you control via addAsModules (/) or addAsLibraries  (/lib)

                • 5. Re: Arquillian integration tests with existing jar files
                  arquillianer

                  Hi Aslak,

                   

                  Thanks for the reply. Can you please tell me ... why is there a test.war file in the ear when I'm not adding one ?

                   

                  Glassfish is trying to launch the war file and failing. Why is the war file being added randomly ?

                   

                  Test set: mjs.ejb.MyBeanIT

                  -------------------------------------------------------------------------------

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

                  testInjection(mjs.ejb.MyBeanIT)  Time elapsed: 1.223 sec  <<< ERROR!

                  java.lang.IllegalStateException: Error launching test mjs.ejb.MyBeanIT public void mjs.ejb.MyBeanIT.testInjection()

                            at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.invoke(ServletMethodExecutor.java:126)

                            at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:120)

                            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.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.execution.ClientTestExecuter.execute(ClientTestExecuter.java:57)

                            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.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.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)

                            at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:129)

                            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.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

                            at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                            at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)

                            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.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

                            at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                            at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)

                            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.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

                            at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

                            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:39)

                            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                            at java.lang.reflect.Method.invoke(Method.java:597)

                            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.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)

                            at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)

                            at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)

                            at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

                            at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

                            at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)

                            at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

                            at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

                            at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

                            at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

                            at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

                            at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

                            at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

                            at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

                            at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)

                            at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)

                            at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

                            at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)

                            at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

                            at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)

                            at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:234)

                            at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:133)

                            at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:114)

                            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.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:188)

                            at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:166)

                            at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86)

                            at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:101)

                            at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)

                  Caused by: java.lang.IllegalStateException: Error launching request at http://localhost:8181/test/ArquillianServletRunner?outputMode=serializedObject&className=mjs.ejb.MyBeanIT&methodName=testInjection. No result returned

                            at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.executeWithRetry(ServletMethodExecutor.java:162)

                            at org.jboss.arquillian.protocol.servlet.ServletMethodExecutor.invoke(ServletMethodExecutor.java:122)

                            ... 81 more

                  • 6. Re: Arquillian integration tests with existing jar files
                    arquillianer

                    Aslak, I tried following this post https://community.jboss.org/thread/203023?tstart=0

                     

                    It's not working mate. Please suggest something else ... please have a look at https://community.jboss.org/message/754445#754445

                    • 7. Re: Arquillian integration tests with existing jar files
                      aslak

                      It is far from being added randomly, this is why the test.war is there:

                      https://docs.jboss.org/author/display/ARQ/Protocols

                      https://docs.jboss.org/author/display/ARQ/Servlet+3.0

                       

                       

                      Arquillian is having problems executing the test in container and fails to communicate with your deployment for 'some reason', that's why you get the "No results returned" exception.

                       

                      What does the glassfish console log say  ?