"Crossing" jar boundaries in a ShrinkWrap WebArchive when using Weld
bertil.karlsson Apr 13, 2012 8:14 AMLet me start with saying that I definitelly qualify as a Aquillian noob!
I have been able to follow the Getting started guide without problems, but when I try to convert that into a real test case I get into trouble ...
I have a WebArchive that I setup according to following:
{code}
@Deployment
public static WebArchive createWebDeployment() {
String aPom = "pom.xml";
MavenDependencyResolver aResolver = DependencyResolvers.use(MavenDependencyResolver.class).loadMetadataFromPom(aPom);
WebArchive aWebArchive = ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(Resources.class) // Adds EntityManager through usage of @Produces
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsManifestResource("MANIFEST.MF") // Adds classpath handling according JBoss7 concept
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsLibraries(aResolver.artifact("com.metria.saerimner.system.server:saerimner-logger").resolveAsFiles())
.addAsLibraries(aResolver.artifact("com.metria.saerimner.system.server:saerimner-service").resolveAsFiles());
System.out.println(aWebArchive.toString(true));
return aWebArchive;
}
{code}
In the artifact saerimner-logger I have a @Produces definition of a qualified logger according to:
{code}
@Produces
@SaerimnerLogger
Logger createLogger(InjectionPoint injectionPoint) {
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
{code}
In the artifact saerimner-service I have an SLSB that I wan't to test. This SLSB is injecting a EntityManager among other things.
In the Aquillian test class I have:
{code}
@Inject
SaerimnerServiceBean itsService;
{code}
I have a pom.xml according to the Getting started guide, except that I am using weld-core:1.1.7.Final (for the embedded test)
If I run according to the profile arquillian-jbossas-managed (see Getting started guide), i.e. remote jboss (7.1.1.Final), everything works!
But if I try profile arquillian-weld-ee-embedded (embedded conatiner) I get an error:
Tests in error:
com.metria.saerimner.service.ServiceIntegrationTest: WELD-001408 Unsatisfied dependencies for type [SaerimnerServiceBean] with qualifiers [@Default] at injection point [[field] @Inject com.metria.saerimner.service.ServiceIntegrationTest.itsService]
I have tried to add the SaerimnerServiceBean.class to the test archive, but encounters the following:
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@SaerimnerLogger] at injection point [[field] @Inject @SaerimnerLogger private transient com.metria.saerimner.service.SaerimnerServiceBean.itsLog]
And on top of that I found that the remote profile is then not working anymore due to duplcate definitions of classes (both in a jar and included with the WebArchive).
Am I expecting to much here or am I doing a classic noob "error"??
I have also tried to clean up a bit so I cannot promise that a compiler will not complain over my example here :-)
The reason I'm going for the "jar-version" of a testcase, instead of including classes, is that we have a rather large framework in place that needs to be in place too and also the JBoss7 classpath handling are in place in the jar's.
Perhaps I should say that we are planning on using Aquillian for "intergration" tests and as such it has to be fully functional when executing the tests
Any pointers appreciated!! For now I will stick to the remote version only ...
BRGDS
/B