12 Replies Latest reply on Dec 6, 2010 8:38 PM by Michael Schuetz

    Running tests against OpenEJB Embedded container

    Michael Schuetz Novice

      Hi to all,

       

      here you can find an easy and ready to use example for running EJB3 integration tests against Apache OpenEJB 3.1 Embedded container:

       

      http://github.com/arquillian/arquillian-examples/tree/master/ejb3-openejb

       

       

      There are three issues I noticed:

       

      1) no EJB3.1 interface view

      Obviously, container supports EJB3 only.

       

      2) cdi dependency is required

      There is an open issue: https://jira.jboss.org/browse/ARQ-157

       

      3) undeploy exception

       

       

      {code}

      INFO - Undeploying app: C:\Users\m.schuetz\AppData\Local\Temp\b931ec60-140c-48d8-b320-e0b7c06cb256\helloEJB.jar
      ERROR - Unable to clear Sun JarFileFactory cache
      java.lang.ClassCastException: java.lang.String cannot be cast to java.net.URL
              at org.apache.openejb.ClassLoaderUtil.clearSunJarFileFactoryCache(ClassLoaderUtil.java:173)
              at org.apache.openejb.ClassLoaderUtil.destroyClassLoader(ClassLoaderUtil.java:130)
              at org.apache.openejb.assembler.classic.Assembler.destroyApplication(Assembler.java:918)
              at org.apache.openejb.assembler.classic.Assembler.destroyApplication(Assembler.java:785)
              at org.jboss.arquillian.container.openejb.embedded_3_1.OpenEJBContainer.undeploy(OpenEJBContainer.java:145)
              at org.jboss.arquillian.impl.handler.ContainerUndeployer.callback(ContainerUndeployer.java:61)
              at org.jboss.arquillian.impl.handler.ContainerUndeployer.callback(ContainerUndeployer.java:47)
              at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)
              at org.jboss.arquillian.impl.context.AbstractEventContext.fire(AbstractEventContext.java:115)
              at org.jboss.arquillian.impl.EventTestRunnerAdaptor.afterClass(EventTestRunnerAdaptor.java:86)
              at org.jboss.arquillian.junit.Arquillian$3$2.evaluate(Arquillian.java:190)
              at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:297)
              at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:182)
              at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
              at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:127)
              at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
              at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
              at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
              at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
              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.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
              at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)

      {code}

       

      BTW, I did use Maven3Beta2.

       

       

       

      Regards

      Michael

        • 1. Re: Running tests against OpenEJB Embedded container
          Michael Schuetz Novice

          This issue seems to be related: https://issues.apache.org/jira/browse/OPENEJB-1131

           

          I did use JDK1.6.0_18. I will try again with latest JDK version later on.

          • 2. Re: Running tests against OpenEJB Embedded container
            alex soto Newbie

            Hello,

             

             

            I am trying to run a test against OpenEJB embedded container.  I am following the example you provided, but I get this exception:

             

             

            -------------------------------------------------------------------------------
            Test set: com.tandf.crcpress.ecommerce.business.wishlist.WishListImplTest
            -------------------------------------------------------------------------------
            Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.389 sec <<< FAILURE!
            com.tandf.crcpress.ecommerce.business.wishlist.WishListImplTest  Time elapsed: 0 sec  <<< ERROR!
            java.lang.IllegalAccessError: tried to access method org.junit.runners.ParentRunner.getTestClass()Lorg/junit/runners/model/TestClass; from class org.jboss.arquillian.junit.Arquillian$2
            at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:162)
            at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
            at org.jboss.arquillian.junit.Arquillian$3$1.evaluate(Arquillian.java:186)
            at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:297)
            at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:182)
            at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
            at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:127)
            at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
            at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
            at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
            at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
            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.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
            at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
            
            

             

             

            Any idea what the problem might be?

             

            Thanks

            • 3. Re: Running tests against OpenEJB Embedded container
              alex soto Newbie

              Figured it out.  Needed version 4.8.1 of JUnit.

              Problem solved.

              • 4. Re: Running tests against OpenEJB Embedded container
                Michael Schuetz Novice

                Hi Alex,

                 

                glad you found it.

                 

                BTW, did you also get OpenEJB UndeployException?

                java.lang.ClassCastException: java.lang.String cannot be cast to java.net.URL

                 

                I thought the reason for that was jdk version 1.6.0_18. But error remains even after switching to jdk version 1.6.0_21.

                 

                 

                Michael

                • 5. Re: Running tests against OpenEJB Embedded container
                  alex soto Newbie

                  Yes, I think I saw that error, but then I realized my EJB had dependencies on JBoss cache, which of course is not part of OpenEJB.  Seems like JBoss embedded is available, although it is not mentioned in the online documentation I was following.  Then I was trying to get the source code from the SVN address referenced in the online documentation (and in the Wiki) and that did not work either, since apparently the source was moved to something called github, which is totally strange to me.  Once I visited github, I could not figure out how to download the whole project at once.  In conclusion, it is hard to get something working quickly with so many bad pointers, so I will wait until I have more time.

                  • 6. Re: Running tests against OpenEJB Embedded container
                    Dan Allen Master

                    Michael,

                     

                    I can confirm that I saw all three of the issues you listed above during my Arquillian presentation demo yesterday. The dependency on the CDI api does not bother me, personally, but I do agree that it shouldn't be required when solely testing an EJB.

                     

                    You mention that OpenEJB only supports EJB 3, but in fact it does have support for many EJB 3.1 features. It's just that no-interface views aren't one of them

                     

                    The undeploy exception is unfortunate because in a demo it makes it appear as though the test failed, when in fact it passes.

                    • 7. Re: Running tests against OpenEJB Embedded container
                      Dan Allen Master

                      I should mention the version of Java I'm using:

                      java version "1.6.0_20" (linux)
                      Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
                      Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)
                      • 8. Re: Running tests against OpenEJB Embedded container
                        Michael Schuetz Novice

                        Hi Alex,

                         

                        if you don't mind, it would be my pleasure helping to get you started, quickly.

                         

                        I do provide two ZIPs for you for direct download:
                        http://github.com/arquillian/arquillian-examples/downloads

                         

                        ZIP files contain simple EJB ready to use example for testing against OpenEJB 3.1 Embedded container and JBoss AS 6 Embedded container, respectively.

                         

                        Just download one of those files. You don't need Git for that. After downloading, you need to do:
                        1) extract the stuff
                        2) configure maven repos as stated in README.txt
                        3) go to projects root and run *mvn test*

                         

                        Recommend using one of those examples as base and do copy your EJB-config step by step.

                         

                        How far did you get with that?

                         


                        Regards
                        Michael

                        • 9. Re: Running tests against OpenEJB Embedded container
                          Michael Schuetz Novice

                          Hi Dan,

                           

                          thanks for pointing this out.

                           

                          Yes, *unfortunate* is the right word, because the container itseld does perform very smart and fast.

                           

                          I opened an new JIRA issue: https://issues.apache.org/jira/browse/OPENEJB-1347

                           

                           

                          Regards

                          Michael

                          • 10. Re: Running tests against OpenEJB Embedded container
                            alex soto Newbie

                            Thanks Michael,

                             

                            Is JBoss 5.1 embedded a supported container?

                            We are currently using 5.1, not 6, at least until is GA.

                             

                            Thanks Again.

                            • 11. Re: Running tests against OpenEJB Embedded container
                              Michael Schuetz Novice

                              Hi Alex,

                               

                              No, there is no AS5.1 Embedded support.

                               

                              See list of supported containers here: http://docs.jboss.org/arquillian/reference/latest/en-US/html_single/#d0e672

                               

                              I do use Arquillian in current project for testing against JBoss AS 5.1, as well.

                               

                              So I recommend using JBossAS 5.1 Remote for manual testing: testing against running container, no lifecycle support, really fast.

                              For automated testing (Hudson etc.) usage of JBossAS 5.1 Managed does make sense: lifecycle support.

                               

                              (For professional configuration, you can let Maven download AS first and unpack to target or so..)

                               

                              Your next step: See configuration of JBoss AS 5.1 Remote: http://docs.jboss.org/arquillian/reference/latest/en-US/html_single/#container.jbossas-remote-51

                               

                              Hint: As it uses JSR-88 container implementation it connects through JMX. Therefore, jndi.properties is needed:

                               

                              src/test/resources

                               

                              {code}

                              java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory


                              java.naming.factory.url.pkgs=org.jboss.naming\:org.jnp.interfaces

                              java.naming.provider.url=jnp://localhost:1099

                              {code}

                               

                               

                              If you do need help, it would be my pleasure to push simple EJB3 + JBoss AS 5.1 Remote example to github and provide a ZIP-download for you.

                               

                               

                              Regards

                              Michael

                              • 12. Re: Running tests against OpenEJB Embedded container
                                Michael Schuetz Novice

                                BTW, with OpenEJB Embedded 3.1.4 everything runs just fine.

                                 

                                 

                                Michael