我想使用 arquillian(拥有容器服务)测试我的 glassfish 应用程序中包含的 JMS-worker。我的工人看起来如下:
package queue.worker;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.MessageListener;
@MessageDriven(mappedName = "java:app/jms/MailQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") })
public class MailWorker implements MessageListener {
public MailWorker() {
}
@Override
public void onMessage(javax.jms.Message inMessage) {
}
}
这是测试:
package queueTest.worker;
import java.io.File;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import queue.worker.MailWorker;
@RunWith(Arquillian.class)
public class MailWorkerTest {
@Deployment
public static WebArchive createDeployment() {
WebArchive archive = ShrinkWrap
.create(WebArchive.class)
.addClasses(MailWorker.class)
.addAsWebInfResource(new File("src/test/resources/WEB-INF/glassfish-resources.xml"),
"glassfish-resources.xml")
.addAsWebInfResource(new File("src/main/webapp/WEB-INF/beans.xml"), "beans.xml");
return archive;
}
@Inject
protected MailWorker mailWorker;
@Test
public void sendRegisterMail() {
Assert.assertTrue(true);
}
}
执行此测试,Glassfish-JSM-Queue 已启动 [1],但出现以下错误:
org.jboss.weld.exceptions.DeploymentException: WELD-001408 在注入点 [[field] @Inject protected queueTest.worker.MailWorkerTest.mailWorker] 具有限定符 [@Default] 的类型 [MailWorker] 的依赖关系不满足
当我在 Mailworker.class 中删除“@MessageDrivern[...]”并将其替换为“@ApplicationScoped”时,例如,一切正常 - 所以 Arquillian 似乎没有问题,但与 JMS 相关。
如何测试 JMS/Queue-Worker?
[1] Dez 23, 2012 12:42:08 AM com.sun.messaging.jms.ra.ResourceAdapter start 信息:MQJMSRA_RA1101:GlassFish MQ JMS Resource Adapter 启动:broker is EMBEDDED, connection mode is Direct Dez 23, 2012 12:上午 42:10 com.sun.messaging.jms.ra.ResourceAdapter 启动信息:MQJMSRA_RA1101:GlassFish MQ JMS 资源适配器已启动:EMBEDDED