1 Reply Latest reply on Aug 29, 2011 6:34 PM by Aslak Knutsen

    How to test with classloading isolation?

    Jeronimo Ginzburg Newbie

      Hi,

      I'm trying to do an integration test with Arquillian 1.0.0.Alpha5 and EAP 5.1. I need the test running using an specific jboss-classloading configuration.

      I was able to create test.ear containing META-INF/jboss-classloading.xml. The problem I'm having now is that the ServletTestRunner is not able to locate my test class (because now it is in other classloader):

      java.lang.ClassNotFoundException: com.example.services.MyServiceTest

              at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

              at java.security.AccessController.doPrivileged(Native Method)

              at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

              at java.lang.ClassLoader.loadClass(ClassLoader.java:307)

              at java.lang.ClassLoader.loadClass(ClassLoader.java:252)

              at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:80)

       

      I suppose that this can be solved if I'm able to insert jboss-classloading.xml into test.ear/arquillian-protocol.war/WEB-INF. Am I wrong? Is there any way to do this (I'm using a JEE 5 container)?

       

      BTW I tried the following but nothing happened:

      - I extended ProtocolDeploymentAppender overriding createAuxiliaryArchive:

      public class MyProtocolDeploymentAppender extends ProtocolDeploymentAppender implements AuxiliaryArchiveAppender{

          @Override

          public WebArchive createAuxiliaryArchive() {

              WebArchive archive = super.createAuxiliaryArchive();

              archive.addAsManifestResource("jboss-classloading.xml");

              return archive;       

          }

      }

       

      Then I created a file META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender containg the text com.example.MyProtocolDeploymentAppender

       

      And on my test file:

          @Deployment

          public static Archive createTestArchive() {

              EnterpriseArchive moduleFile = ShrinkWrap.create(EnterpriseArchive.class);

              //adding other resources to the archive....

       

              moduleFile.addAsManifestResource("jboss-classloading.xml"); // (this works)

              moduleFile.addAsResource("META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender");

              moduleFile.addAsServiceProvider(MyProtocolDeploymentAppender.class);

              return moduleFile;                       

          }

       

      And MyProtocolDeploymentAppender is never executed....

       

      Thanks,

      Jero


        • 1. Re: How to test with classloading isolation?
          Aslak Knutsen Master

          from the SPI side you can do the following:

           

          Create a impl of org.jboss.arquillian.core.spi.LoadableExtension, register it as a SPI by adding a file containg the fully qualified class name of the impl in META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension

           

          Create a impl of org.jboss.arquillian.container.test.spi.client.deployment.ProtocolArchiveProcessor and register it in your LoadableExtension impl

           

          ProtocolArchiveProcessor gives you access to the TestDeployment(contains all the Auxiliary Archives and the Application Archive(@Deployment)) and the Archive where the Protocol is located(what this is depends on the Application Archive and the packaging rules, https://docs.jboss.org/author/display/ARQ/Servlet+2.5).