3 Replies Latest reply: Nov 3, 2011 7:49 AM by José Freitas RSS

    Alpha4 to CR5 tomcat6 embedded migration problem

    Brett Cave Newbie

      I have set up a project to test migration from Alpha4 to CR5.

       

      Dependencies for Alpha4 + tomcat embedded are as follows:

      integrationTestAlpha4Embed "org.jboss.weld.servlet:weld-servlet:1.1.1.Final",
          "org.jboss.arquillian:arquillian-spi:1.0.0.Alpha4.SP1",
          "org.jboss.arquillian:arquillian-junit:1.0.0.Alpha4.SP1",
          "org.jboss.arquillian.protocol:arquillian-protocol-servlet-3:1.0.0.Alpha4.SP1",
          "org.jboss.arquillian.container:arquillian-tomcat-embedded-6:1.0.0.Alpha4"
          "org.jboss.shrinkwrap:shrinkwrap-extension-tomcat-6:1.0.0-alpha-11"

       

      arquillian.xml:

       

      <arquillian xmlns="http://jboss.com/arquillian"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:tomcat6="urn:arq:org.jboss.arquillian.container.tomcat.embedded_6">
      
          <tomcat6:container>
              <tomcat6:tomcatHome>target/tomcat-embedded-6</tomcat6:tomcatHome>
              <tomcat6:workDir>work</tomcat6:workDir>
              <tomcat6:appBase>webapps</tomcat6:appBase>
              <tomcat6:bindHttpPort>8889</tomcat6:bindHttpPort>
              <tomcat6:unpackArchive>true</tomcat6:unpackArchive>
          </tomcat6:container>
      </arquillian>
      

       

      And the test case (referencing a request scoped bean):

       

      @RunWith(Arquillian.class)
      @Run(RunModeType.IN_CONTAINER)
      public class UtilInContainerTestCase {
      
          @Inject
          Util util;
      
          @Deployment
          public static WebArchive createTestArchive() {
              return ShrinkWrap.create(WebArchive.class, "test.war")
                      .addLibrary(MavenArtifactResolver.resolve("org.jboss.weld.servlet:weld-servlet:1.1.1.Final"))
                      .addWebResource("in-container-beans.xml", "META-INF/beans.xml")
                      .addResource("in-container-context.xml", "META-INF/context.xml")
                      .setWebXML("in-container-web.xml");
          }
      

       

      beans.xml is empty. context.xml contains 1 resource definition for weld's BeanManager from the ManagerObjectFactory, which is the referenced by the web.xml, as well as servlet mappings (web.xml below):

       

      <web-app version="2.5"
               xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="
            http://java.sun.com/xml/ns/javaee
            http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      
          <env-entry>
              <env-entry-name>name</env-entry-name>
              <env-entry-type>java.lang.String</env-entry-type>
              <env-entry-value>Tomcat</env-entry-value>
          </env-entry>
      
          <listener>
              <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
          </listener>
      
          <servlet>
              <servlet-name>TestServlet</servlet-name>
              <servlet-class>org.jboss.arquillian.container.tomcat.embedded_6.TestServlet</servlet-class>
          </servlet>
          <servlet-mapping>
              <servlet-name>TestServlet</servlet-name>
              <url-pattern>/Test</url-pattern>
          </servlet-mapping>
      
          <servlet>
              <servlet-name>ServletTestRunner</servlet-name>
              <servlet-class>org.jboss.arquillian.protocol.servlet.ServletTestRunner</servlet-class>
          </servlet>
          <servlet-mapping>
              <servlet-name>ServletTestRunner</servlet-name>
              <url-pattern>/ArquillianServletRunner</url-pattern>
          </servlet-mapping>
      
          <resource-env-ref>
              <resource-env-ref-name>BeanManager</resource-env-ref-name>
              <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
          </resource-env-ref>
      

       

      The test case runs fine.

       

       

      The migration has the following changes:

      Dependencies:

      integrationTestCR5Embed "org.jboss.weld.servlet:weld-servlet:1.1.1.Final",
          "org.jboss.arquillian.junit:arquillian-junit-container:1.0.0.CR5",
          "org.jboss.arquillian.container:arquillian-tomcat-embedded-6:1.0.0.CR1"

       

      arquillian.xml changes to https://github.com/arquillian/arquillian-container-tomcat/blob/master/tomcat-embedded-6/src/test/resources/arquillian.xml, web.xml has not been modified. The @Deployment changes as per Alpha5 migration guide:

       


      @Deployment(testable = true)

      public static WebArchive createTestArchive() {
          return ShrinkWrap.create(WebArchive.class, "test.war")
                  .addAsLibrary(MavenArtifactResolver.resolve("org.jboss.weld.servlet:weld-servlet:1.1.2.Final"))
                  .addAsWebInfResource("in-container-beans.xml", "beans.xml")
                  .addAsManifestResource("in-container-context.xml", "context.xml")
                  .setWebXML("in-container-web.xml");

      }

       

      The test case fails almost immediately, with the following:

       

       

      java.lang.RuntimeException: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor see cause.
          at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:170)
          at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
          at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:72)
      .....
      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:166)
          ... 11 more
      Caused by: java.lang.NoSuchMethodError: org.jboss.shrinkwrap.descriptor.spi.DescriptorImporterBase.from(Ljava/io/InputStream;Z)Lorg/jboss/shrinkwrap/descriptor/api/Descriptor;
          at org.jboss.shrinkwrap.descriptor.spi.DescriptorImporterBase.from(DescriptorImporterBase.java:142)
          at org.jboss.arquillian.config.impl.extension.ConfigurationRegistrar.loadConfiguration(ConfigurationRegistrar.java:50)
          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:90)
          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:134)
          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
          at org.jboss.arquillian.core.impl.ManagerImpl.start(ManagerImpl.java:260)
          at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:56)
          ... 16 more
      
      

       

      The dependancy tree shows shrinkwrap-descriptors-spi:1..1.0-beta-1 is included, which contains the classes and methods from the stack trace.

        • 1. Re: Alpha4 to CR5 tomcat6 embedded migration problem
          Brett Cave Newbie

          Had a suggestion in #jbosstesting to upgrade to the latest shrinkwrap version, so have tried adding:

          org.jboss.shrinkwrap.container:shrinkwrap-container-tomcat-60:1.0.0-beta-1

           

          which pulls in shrinkwrap-api. shrinkwrap-spi-1.0.0-beta-5 is pulled in by arquillian-junit-container and shrinkwrap-descriptors-api-1.0.0-beta-1 is pulled in by arquillian-tomcat-embedded-6-1.0.0.CR1

           

          Issue remains the same after adding this though.

          • 2. Re: Alpha4 to CR5 tomcat6 embedded migration problem
            Brett Cave Newbie

            Shrinkwrap upgrade did in fact resolve the issue (thanks Jose).

             

            Final dependency list for working embedded tomcat 6 with CDI:

             

            integrationTestCR5Embed "org.jboss.weld.servlet:weld-servlet:1.1.1.Final",

                "org.jboss.arquillian.junit:arquillian-junit-container:1.0.0.CR5",

                "org.jboss.arquillian.container:arquillian-tomcat-embedded-6:1.0.0.CR1",

                "org.jboss.shrinkwrap.container:shrinkwrap-container-tomcat-60:1.0.0-beta-1",

                "org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api:1.1.0-beta-1",

                "org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl:1.1.0-beta-1",

                "org.jboss.shrinkwrap:shrinkwrap-api:1.0.0-cr-1",

                "org.jboss.shrinkwrap:shrinkwrap-spi:1.0.0-cr-1"