我正在尝试使用Arquillian框架来测试IBM WebSpehere 8.5.5业务应用程序(EJB3.1)。我已经成功地将包含MDB和少量会话bean的业务部署到测试IBM WAS,将测试WAR注入到该耳中,并将测试消息从我的TestMsgSender发送到MDB监听器:
MyArquillianTestCase.java
@RunWith(Arquillian.class)
public class MyArquillianTestCase {
@Deployment
public static Archive createDeployment() throws InterruptedException {
Archive testArch = createEarWithMavenResolver();
printJarXml(testArch);
return testArch;
}
@EJB
TestMsgSender bean;
@Test
public void test() throws JMSException, NamingException, InterruptedException {
bean.sendMessageUsingLookup();
Thread.sleep(5000);
}
public static EnterpriseArchive createEarWithMavenResolver() {
EnterpriseArchive ear = Maven.configureResolver().workOffline()
.withMavenCentralRepo(false).resolve("my.business.ear.groupid:ear-artifact:ear:1.0.0").withoutTransitivity()
.asSingle(EnterpriseArchive.class);
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(TestMsgSender.class, MyArquillianTestCase.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
ear.addAsModule(war);
updateAppXml(ear);
return ear;
}
static EnterpriseArchive updateAppXml(EnterpriseArchive ear) {
...bunch of code here to update ear application XML (insert test.war),
inner JARs (test JMS queues, active specs and other) ejb-jar.xml, ibm-ejb-jar-bnd.xml...
}
}
TestMsgSender.java
@Stateless
public class TestMsgSender {
public void sendMessageUsingLookup() throws NamingException, JMSException {
Connection connection = null;
try {
InitialContext ic = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) ic.lookup("jms/testlocal/not-queue/cf");
connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue requestQueue = (Queue) ic.lookup("jms/cell/request/queue");
MessageProducer requestMsgProducer = session.createProducer(requestQueue);
TextMessage txtRequestMsg = session.createTextMessage();
txtRequestMsg.setText("Request message");
requestMsgProducer.send(txtRequestMsg);
} catch (JMSException e) {
System.out.println("ERROR!");
e.printStackTrace(System.out);
} finally {
if(connection != null) {
connection.close();
}
}
}
}
我使用maven-surefire-plugin为我的测试用例添加了Maven支持,所有这一切都正常 - 我看到我的业务部署已经部署并读取了我的测试发送者发送到相应队列的消息。现在我的问题是,我是否可以同时部署另一个耳朵(比如ear-message-consumer),以便my.business.ear.groupid.ear-artifact-1.0.0.ear可以将收到的消息传递给它? Arquillian提供了多个部署测试的功能,我可以为它编辑一些我的代码:
@Deployment (name = "deployBusinessEar", order = 1)
public static Archive createDeploymentBusinessEar() {
...
}
@Deployment (name = "deployConsumerEar", order = 2)
public static Archive createDeploymentMessageConsumerEar() {
...
}
@Test @OperateOnDeployment("deployBusinessEar")
public void test() {
...
}
但看起来我只能对每个部署使用相应的测试,而不是同时使用。根据测试日志和WAS日志,我可以说当我的test()方法仍在运行时,WAS正在开始取消部署ear-message-consumer应用程序:( 如何根据需要部署如此多的耳朵应用程序,然后在单个test()方法中测试它们?我应该更改arquillian.xml或pom.xml中的任何设置以进行测试吗?