2 Replies Latest reply on Jun 18, 2013 1:41 AM by Flik Shen

    Any suggestion for unit testing of cross-depended EJB projects

    Flik Shen Newbie

      Hi all,

       

      I am a newbie to arquillian and find it is interesting.

      I follow the tutorial of Getting Start to create a simple junit test with Glassfish 3.1 embedded container.

      I also tried to introduce more complexities by adding session bean, entity bean, DAO classes and connection pool.

      I can get the EJB and data source injected and all test cases are successful.

      It is awesome and exciting.

       

      However, when I back to real world, the story is a bit frustrating.

      We have tens of EJB projects and they have cross dependencies.

      I do some configuration for one EJB project as tutorial and set the deployment method as following. (Please refer to atteched test case for more details)

      @Deployment

      public static JavaArchive createDeployment() {

         return ShrinkWrap.create(JavaArchive.class)

             .addPackages(true, "com.aa.bb.stockmgmt.cashlevelservice", "com.aa.bb.stockmgmt.common", "com.aa.bb.stockmgmt.stockservice")

             .addAsManifestResource("ejbModule/META-INF/ejb-jar.xml", "ejb-jar.xml")

             .addAsManifestResource("ejbModule/META-INF/MANIFEST.MF", "MANIFEST.MF")

             .addAsManifestResource("ejbModule/META-INF/persistence.xml", "persistence.xml");

      }

      I get errors when start testing. (Please refer attached startup failure log file for complete errors)

      Jun 17, 2013 11:18:01 AM org.apache.catalina.core.StandardContext callServletContainerInitializers

      SEVERE: PWC1420: Error invoking ServletContainerInitializer com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer

      Throwable occurred: java.lang.NoSuchMethodError: javax/servlet/ServletContext.getServletRegistrations()Ljava/util/Map;

      Is there anything do with the dependences of other projects?

       

      If I package all EJB projects (JAR) into an EAR file in deployment method, test cases could start without problem.

      But it is more like a integration testing not a unit test.

      Is there any suggestion for unit testing with arquillian for my scenarios?

       

      Thanks a lot.

      Flik

        • 1. Re: Any suggestion for unit testing of cross-depended EJB projects
          Flik Shen Newbie

          Hi all,

           

          I start with a new clean environment and I remove all @Resource and @EJB to avoid dependency issue.

          When I try to launch test cases, I get following issue.

          java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
          at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:160)
          at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111)
          at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97)
          at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
          at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:93)
          at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
          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)
          Caused by: java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
          at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:156)
          ... 10 more
          Caused by: java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.setXmlStandalone(Z)V
          at org.jboss.shrinkwrap.descriptor.spi.node.dom.XmlDomDescriptorExporterImpl.to(XmlDomDescriptorExporterImpl.java:62)
          at org.jboss.shrinkwrap.descriptor.spi.node.NodeDescriptorExporterImpl.to(NodeDescriptorExporterImpl.java:55)
          at org.jboss.shrinkwrap.descriptor.spi.node.NodeDescriptorExporterImpl.to(NodeDescriptorExporterImpl.java:30)
          at org.jboss.shrinkwrap.descriptor.spi.node.dom.XmlDomDescriptorExporter.to(XmlDomDescriptorExporter.java:51)
          at org.jboss.shrinkwrap.descriptor.spi.node.dom.XmlDomDescriptorExporter.to(XmlDomDescriptorExporter.java:34)
          at org.jboss.shrinkwrap.descriptor.spi.node.NodeDescriptorImplBase.exportTo(NodeDescriptorImplBase.java:55)
          at org.jboss.shrinkwrap.descriptor.spi.DescriptorImplBase.exportAsString(DescriptorImplBase.java:84)
          at org.jboss.arquillian.config.impl.extension.ConfigurationSysPropResolver.resolveSystemProperties(ConfigurationSysPropResolver.java:54)
          at org.jboss.arquillian.config.impl.extension.ConfigurationRegistrar.loadConfiguration(ConfigurationRegistrar.java:65)
          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.ManagerImpl.start(ManagerImpl.java:261)
          at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:56)
          ... 15 more

           

          it is said this is due to xerces confliction according to following topic.

          http://community.jboss.org/thread/199330

           

          If I delete the xerces from maven repository, I could get glassfish start up, issue occuring as following then stopping.

          Jun 17, 2013 3:56:19 PM org.apache.catalina.core.ContainerBase startChildren
          SEVERE: PWC1240: Container StandardEngine[glassfish-web].StandardHost[server].StandardContext[] has not been started
          org.apache.catalina.LifecycleException: java.lang.RuntimeException: java.io.FileNotFoundException: C:\Users\chonghua.shen\.m2\repository\xerces\xercesImpl\2.0.2\xercesImpl-2.0.2.jar (The system cannot find the path specified)
          at org.apache.catalina.core.StandardContext.start(StandardContext.java:5332)
          at com.sun.enterprise.web.WebModule.start(WebModule.java:498)

          (Please refer attached output file for complete issue description)

           

          It seems that GlassFish embedded container heavily replies on xerces library.

          Is there any idea to solve it?

           

          Thanks a lot,

          Flik

          • 2. Re: Any suggestion for unit testing of cross-depended EJB projects
            Flik Shen Newbie

            Hi all,

             

            The issue is solved.

            The root cause are libraries confliction.

            First of all, the xerces is not mandatory for GlassFish. But when it is declared as a dependency, it will cause GF load inproper xerces.

            It will solve the issue to exclude it from dependencies or remove it if directly depending.

            Secondly, about issue of container initializing, it is alos caused by conflicted library.

            They are "javax.servlet:servlet-api:2.3", "javax:j2ee:1.4" and "sun:j2ee:1.5" which should be already provided by GF.

            Although there is still some issue like JMS and EJBs from other module injuction, test cases are successfully running.

             

            Flik