使用Maven解析器,使用Arquillian创建耳朵测试
作者:互联网
我需要使用Arquillian为我的EAR应用程序创建一个真正的IT测试.
由于ShrinkWrap方法addClasses或addPackages在现实世界中没用 – 因为需要太多的导入 – 我想使用与pom.xml一起使用的Maven.resolver().
因此我创建了一个这样的测试:
@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;
}
但是,在“解决EJB依赖关系”时无法创建存档并抛出此错误
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
有人创建档案有成功吗?
解决方法:
我终于解决了以下代码:
System.out.println("RESOLVING EJB DEPENDENCIES");
// resolve and add ejbDependencies to ear lib
File[] ejbDependencies = Maven.resolver()
.loadPomFromFile("../project-ejb/pom.xml")
.importRuntimeDependencies()
.resolve()
.withTransitivity()
.asFile();
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(JavaArchive.class, "project-test-ejb.jar")
.addPackage("it.blah..")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
;
其余的保持不变.
将此行添加到arquillian.xml
<engine>
<property name="deploymentExportPath">target/deployment</property>
</engine>
也有很多帮助因为上面的属性arquillian创建了可以分析的结果包来摆脱错误.
标签:java,maven,jboss-arquillian,shrinkwrap 来源: https://codeday.me/bug/20190702/1352532.html