How to test with classloading isolation?
jginzburg Aug 29, 2011 2:49 PMHi,
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