I need to create a real IT test using Arquillian for my EAR application.
Since ShrinkWrap methods addClasses or addPackages are useless in real world - because of too many imports needed - I'd like to use Maven.resolver() which works with pom.xml.
Therefore I've created a Test like this:
@RunWith(Arquillian.class)
public class ArqTest {
@Deployment
public static Archive<?> createTestArchive() {
System.out.println("START CREATE ARCHIVE");
//create ear archive
EnterpriseArchive ear = ShrinkWrap
.create(EnterpriseArchive.class);
System.out.println("RESOLVING EJB DEPENDENCIES");
// resolve and add ejbDependencies to ear lib
File[] ejbDependencies = Maven.resolver()
.loadPomFromFile("../ejb/pom.xml")
.importRuntimeDependencies()
.resolve()
.withTransitivity()
.asFile();
System.out.println("ADDING DEPENDENCIES TO EAR");
for (File archive : ejbDependencies) {
ear.addAsLibrary(archive);
}
System.out.println("START CREATE EJB");
// resolve ejb (actually jar file cause as of now mavenimporter doesn't support ejb-types ony war and jars so don't be fooled by my naming convention)
// then add some external resources, and an empty beans.xml for CDI to work
JavaArchive ejb = ShrinkWrap
.create(MavenImporter.class)
.loadPomFromFile("../ejb/pom.xml")
.importBuildOutput()
.as(JavaArchive.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsResource("app.properties")
;
System.out.println("START CREATE WAR");
//resolve war and add beans.xml and my html files manually
WebArchive war = ShrinkWrap
.create(MavenImporter.class)
.loadPomFromFile("pom.xml")
.importBuildOutput()
.as(WebArchive.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
;
//add built modules to ear and my application.xml
ear.addAsModule(ejb);
ear.addAsModule(war);
ear.setApplicationXML("application.xml");
System.out.println("END CREATE ARCHIVE");
return ear;
}
However, it fails creating archive while "RESOLVING EJB DEPENDENCIES" and throw this error
Caused by: java.lang.IllegalArgumentException: No dependencies were set for resolution
at org.jboss.shrinkwrap.resolver.impl.maven.util.Validate.notEmpty(Validate.java:78)
at org.jboss.shrinkwrap.resolver.impl.maven.MavenStrategyStageBaseImpl.using(MavenStrategyStageBaseImpl.java:65)
at org.jboss.shrinkwrap.resolver.impl.maven.MavenStrategyStageBaseImpl.withTransitivity(MavenStrategyStageBaseImpl.java:49)
at org.jboss.shrinkwrap.resolver.impl.maven.MavenStrategyStageBaseImpl.withTransitivity(MavenStrategyStageBaseImpl.java:38)
at ArqEjbTest.createTestArchive(ArqEjbTest.java:39)
... 61 more
Anyone had success with creating an archive ?