0
我試圖測試一個主題可以填充到我的容器中。但是,在我的工廠中調用createConnection方法時,我總是收到空指針異常。下面是如何被執行我的代碼:JMS與Arquillian的集成測試
@RunWith(Arquillian.class)
public class TopicPublishTest {
@Resource(mappedName = "java:jboss/jms/topic/sample/MySample")
private Topic topic;
@Resource(mappedName = "java:/ConnectionFactory")
private ConnectionFactory factory;
@Test
public void testMessageInTopic() throws Exception {
final Connection connection = factory.createConnection();
connection.start();
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageConsumer consumer = session.createConsumer(topic);
final TextMessage message = (TextMessage) consumer.receiveNoWait();
System.out.println("### the mssage is " + message);
}
}
我有一個的Arquillian部署這樣的:
@Deployment(name = "my-service", order = 1, testable = true)
public static Archive<?> targetDeployment() {
final WebArchive archive = ShrinkWrap.createFromZipFile(WebArchive.class, new File(
"target/my-service.war"));
return archive;
}
我的Jboss EAP 6.0.0 G2實現包含下面的代碼行:
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
....
<jms-topic name="MySample">
<entry name="java:jboss/jms/topic/sample/MySample"/>
<entry name="java:jboss/exported/jms/topic/sample/MySample"/>
</jms-topic>
我不能爲我的生命弄清楚爲什麼
final Connection connection = factory.createConnection();
正在拋出一個NullPinter。顯然,工廠無法實例化,導致我相信Arquillian無法查看我的jndi綁定。然而,即使試圖加載工廠資源的這些組合拋出了同樣的錯誤:
@Resource(mappedName = "/ConnectionFactory")
@Resource(mappedName = "ConnectionFactory")