我有一个接缝2.2.2应用程序,我正在迁移到jboss eap 6(AS7)。 由于测试是在旧的jboss嵌入式容器中进行的,所以我开始使用arquillian,但是我无法发现创建部署包的热点。
这是我的一次尝试:
@Deployment
@OverProtocol("Servlet 3.0")
public static Archive<?> createDeployment() throws IOException {
// Build the ear with Maven by hand before run the test!
final EnterpriseArchive ear = ShrinkWrap.createFromZipFile(
EnterpriseArchive.class, new File("../Sin-ear/target/Sin.ear"));
final JavaArchive testjar = ShrinkWrap.createFromZipFile(
JavaArchive.class, new File("./target/test.jar"));
//final JavaArchive testjar = ShrinkWrap.create(JavaArchive.class, "test.jar") //other attempt
// .addPackages(true, "com.miles.knowledge.test");
ear.addAsModule(testjar);
return ear;
}
当我将测试类作为JUnit测试运行时,它失败了(我可以看到没有错误的aplication部署):
java.lang.ClassNotFoundException: com.miles.knowledge.test.GreeterTest from [Module "deployment.Sin.ear.Sin.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213)
...
似乎我必须将测试类打包成war包,但我有点迷失,我需要一些帮助。
答案 0 :(得分:1)
这种部署应该有效(注意将测试类添加到战争中)......
@RunWith(Arquillian.class)
public class JsfTest extends org.jboss.seam.mock.JUnitSeamTest{
@Deployment(name="UserLoginTest")
@OverProtocol("Servlet 3.0")
public static Archive<?> createDeployment(){
EnterpriseArchive er = Deployments.webAppDeployment();
WebArchive web = er.getAsType(WebArchive.class, "WebApp-web.war");
er.addAsModule(Testable.archiveToTest(web));
web.addClasses(JsfTest.class)
.addAsResource(EmptyAsset.INSTANCE, "seam.properties")
.delete("/WEB-INF/web.xml");
web.addAsWebInfResource("mock-web.xml", "web.xml");
return er;
}
}
public class Deployments {
public static EnterpriseArchive webAppDeployment() {
return ShrinkWrap.create(ZipImporter.class, "WebApp.ear")
.importFrom(new File("../WebApp-ear/target/WebApp.ear"))
.as(EnterpriseArchive.class);
}
}