我有以下真实的项目结构:
EAR
- lib/commons.jar
- lib/another dependencies
- ejb.jar
我想用arquillian测试它,但我总是得到一个例外。
这是构建EAR的java方法:
@Deployment
public static Archive<?> createTestArchive() {
//create ear
EnterpriseArchive ear = ShrinkWrap
.create(EnterpriseArchive.class, "test-app.ear");
// create ejb-jar
JavaArchive ejb = ShrinkWrap
.create(JavaArchive.class, "test-ejb.jar")
.addPackage("a.b.ejb")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
// resolve ejb dependencies
File[] dependencies = Maven.resolver()
.loadPomFromFile("pom.xml")
.importDependencies(ScopeType.COMPILE, ScopeType.TEST)
.resolve()
.withTransitivity()
.asFile();
ear.addAsModule(ejb);
ear.addAsLibraries(dependencies);
ear.setApplicationXML("glassfish-resources.xml");
LOGGER.debug("content: " + ear.toString(true));
return ear;
}
内容看起来很好,但有些东西不合适,因为我得到了这个例外:
ArquillianServletRunner not found.
Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.
JAR内容:
/a/
/a/b/
/a/b/ejb/
/a/b/ejb/MyEjb.class
...
/META-INF/
/META-INF/beans.xml
EAR内容
/test-ejb.jar
/lib/
/lib/commons-444750341265461918.jar
/lib/slf4j-api-1.7.21.jar
/lib/slf4j-log4j12-1.7.21.jar
/lib/guava-21.0.jar
...
/lib/arquillian-testenricher-initialcontext-1.1.13.Final.jar
/lib/payara-embedded-all-4.1.1.171.0.1.jar
/lib/postgresql-42.0.0.jar
/META-INF/
/META-INF/application.xml
答案 0 :(得分:0)
我得到&#34; ArquillianServletRunner not found
&#34;错误是因为EJB级别出现错误。
以下测试代码正常运行:
@RunWith(Arquillian.class)
public class EchoServiceBeanTest {
@EJB
private EchoService echoService;
@Deployment
public static Archive<?> createDeployment() {
// create ear
EnterpriseArchive ear = ShrinkWrap
.create(EnterpriseArchive.class, "test-app.ear");
// create ejb.jar
JavaArchive ejb = ShrinkWrap
.create(JavaArchive.class, "test-ejb.jar")
.addPackages(true, "a.b.ejb")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
LOGGER.debug("EJB content: " + ejb.toString(true));
// build ear
ear.addAsModule(ejb);
LOGGER.debug("EAR deployment content: " + ear.toString(true));
return ear;
}
@Test
public void echo() throws Exception {
Assert.assertNotNull(echoService);
String expected = "hello";
String returned = echoService.echo(expected);
Assert.assertEquals(expected, returned);
}
}
使用了maven依赖项:
<dependencies>
<!-- provided jars -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<!-- arquillian -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.1.13.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.Final</version>
<scope>test</scope>
</dependency>
<!-- embedded EE container -->
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>payara-embedded-all</artifactId>
<version>4.1.1.171.1</version>
<scope>test</scope>
</dependency>
</dependencies>