This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch tomee-7.1.x
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 675f9da47e563bc03302d9a786499264df7c7f56
Author: Jonathan Gallimore <j...@jrg.me.uk>
AuthorDate: Thu Apr 4 13:46:33 2019 +0100

    TOMEE-2506 adding tests (@Ignore 'd) to demonstrate TX issues with @Inject 
'd JMSContext for JMS 2.0.
---
 .../arquillian-tomee-jms-tests/pom.xml             |  4 ++
 .../tests/jms/JMSContextInjectionTest.java         | 83 ++++++++++++++++++++++
 .../arquillian/tests/jms/JMSReceiverBean.java      | 38 ++++++++++
 .../arquillian/tests/jms/JMSSenderBean.java        | 44 ++++++++++++
 .../arquillian/tests/jms/MessageCounter.java       | 38 ++++++++++
 .../src/test/resources/arquillian.xml              | 27 ++++++-
 6 files changed, 231 insertions(+), 3 deletions(-)

diff --git 
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/pom.xml 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/pom.xml
index 7db7bbe..a4c247c 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/pom.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/pom.xml
@@ -33,6 +33,10 @@
     <!-- cause mojarra only works with CDI for now -->
     <skip.remote.plume>true</skip.remote.plume>
     <skip.webapp.plume>true</skip.webapp.plume>
+
+    <!-- no JMS in webprofile -->
+    <skip.remote.webprofile>true</skip.remote.webprofile>
+    <skip.webapp.webprofile>true</skip.webapp.webprofile>
   </properties>
 
   <dependencies>
diff --git 
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSContextInjectionTest.java
 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSContextInjectionTest.java
new file mode 100644
index 0000000..e71f8f1
--- /dev/null
+++ 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSContextInjectionTest.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.jms;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.jms.ConnectionFactory;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@Ignore // we know these are failing
+@RunWith(Arquillian.class)
+public class JMSContextInjectionTest {
+
+    @ArquillianResource
+    private URL url;
+
+    @Inject
+    private JMSSenderBean senderBean;
+
+    @Inject
+    private MessageCounter messageCounter;
+
+    @Resource
+    private ConnectionFactory connectionFactory;
+
+    @Deployment(testable = false)
+    public static WebArchive getArchive() {
+
+        return ShrinkWrap.create(WebArchive.class, "jms-context.war")
+                .addClasses(JMSSenderBean.class, JMSReceiverBean.class, 
MessageCounter.class);
+    }
+
+    @Test
+    public void testShouldSendAndReceiveTwoHundredMessages() throws Exception {
+        messageCounter.reset();
+
+        for (int i = 0; i < 200; i++) {
+            senderBean.sendToQueue("test", "Hello world");
+        }
+
+        assertEquals(200, messageCounter.getValue());
+    }
+
+    @Test
+    public void testTransactionShouldRollback() throws Exception {
+        messageCounter.reset();
+
+        try {
+            senderBean.sendToQueue("test", "Hello world", true);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        assertEquals(0, messageCounter.getValue());
+    }
+
+
+}
diff --git 
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSReceiverBean.java
 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSReceiverBean.java
new file mode 100644
index 0000000..0047f69
--- /dev/null
+++ 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSReceiverBean.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.jms;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.inject.Inject;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+@MessageDriven(activationConfig = {
+        @ActivationConfigProperty(propertyName = "destinationType", 
propertyValue = "javax.jms.Queue"),
+        @ActivationConfigProperty(propertyName = "destination", propertyValue 
= "test")
+})
+public class JMSReceiverBean implements MessageListener {
+
+    @Inject
+    private MessageCounter counter;
+
+    @Override
+    public void onMessage(Message message) {
+        counter.increment();
+    }
+}
diff --git 
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSSenderBean.java
 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSSenderBean.java
new file mode 100644
index 0000000..0411112
--- /dev/null
+++ 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/JMSSenderBean.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.jms;
+
+import javax.ejb.*;
+import javax.inject.Inject;
+import javax.jms.JMSContext;
+import javax.jms.Queue;
+
+@Singleton
+@Lock(LockType.READ)
+@TransactionAttribute(TransactionAttributeType.REQUIRED)
+public class JMSSenderBean {
+
+    @Inject
+    private JMSContext jmsContext;
+
+    public void sendToQueue(final String queueName, final String message) {
+        sendToQueue(queueName, message, false);
+    }
+
+    public void sendToQueue(final String queueName, final String message, 
final boolean rollback) {
+        final Queue queue = jmsContext.createQueue(queueName);
+        jmsContext.createProducer().send(queue, message);
+
+        if (rollback) {
+            throw new RuntimeException("Should rollback");
+        }
+    }
+}
diff --git 
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MessageCounter.java
 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MessageCounter.java
new file mode 100644
index 0000000..577dda3
--- /dev/null
+++ 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MessageCounter.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.jms;
+
+import javax.enterprise.context.ApplicationScoped;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@ApplicationScoped
+public class MessageCounter {
+
+    private AtomicInteger count = new AtomicInteger(0);
+
+    public int getValue() {
+        return count.get();
+    }
+
+    public void increment() {
+        count.incrementAndGet();
+    }
+
+    public void reset() {
+        count.set(0);
+    }
+}
diff --git 
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/resources/arquillian.xml
 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/resources/arquillian.xml
index 4743854..a73adfe 100644
--- 
a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/resources/arquillian.xml
+++ 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/resources/arquillian.xml
@@ -26,12 +26,19 @@
       <property name="dir">target/apache-tomee-remote</property>
       <property 
name="appWorkingDir">target/arquillian-test-working-dir</property>
       <property name="properties">
-        Default\ JMS\ Resource\ Adapter.BrokerXmlConfig = 
broker:(tcp://localhost:61616)?useJmx=false&amp;persistent=false
         My\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
         My\ Unmanaged\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
 
         openejb.classloader.forced-load=org.apache.openejb.arquillian.tests.jms
         openejb.descriptors.output=true
+
+        AMQResourceAdapter = new://Resource?type=ActiveMQResourceAdapter
+        AMQResourceAdapter.BrokerXmlConfig = 
broker:(tcp://localhost:61616)?useJmx=false&amp;persistent=false
+        AMQResourceAdapter.ServerUrl = vm://jvm_broker
+        AMQMessageContainer = new://Container?type=MESSAGE
+        AMQMessageContainer.ResourceAdapter = AMQResourceAdapter
+        AMQConnectionFactory = new://Resource?type=javax.jms.ConnectionFactory
+        AMQConnectionFactory.ResourceAdapter = AMQResourceAdapter
       </property>
     </configuration>
   </container>
@@ -43,11 +50,18 @@
       <property name="dir">target/apache-tomee-remote</property>
       <property 
name="appWorkingDir">target/arquillian-test-working-dir</property>
       <property name="properties">
-        Default\ JMS\ Resource\ Adapter.BrokerXmlConfig = 
broker:(tcp://localhost:61616)?useJmx=false&amp;persistent=false
         My\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
         My\ Unmanaged\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
 
         openejb.classloader.forced-load=org.apache.openejb.arquillian.tests.jms
+
+        AMQResourceAdapter = new://Resource?type=ActiveMQResourceAdapter
+        AMQResourceAdapter.BrokerXmlConfig = 
broker:(tcp://localhost:61616)?useJmx=false&amp;persistent=false
+        AMQResourceAdapter.ServerUrl = vm://jvm_broker
+        AMQMessageContainer = new://Container?type=MESSAGE
+        AMQMessageContainer.ResourceAdapter = AMQResourceAdapter
+        AMQConnectionFactory = new://Resource?type=javax.jms.ConnectionFactory
+        AMQConnectionFactory.ResourceAdapter = AMQResourceAdapter
       </property>
     </configuration>
   </container>
@@ -83,11 +97,18 @@
       <property name="dir">target/apache-tomee-remote</property>
       <property 
name="appWorkingDir">target/arquillian-test-working-dir</property>
       <property name="properties">
-        Default\ JMS\ Resource\ Adapter.BrokerXmlConfig = 
broker:(tcp://localhost:61616)?useJmx=false&amp;persistent=false
         My\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
         My\ Unmanaged\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
 
         openejb.classloader.forced-load=org.apache.openejb.arquillian.tests.jms
+
+        AMQResourceAdapter = new://Resource?type=ActiveMQResourceAdapter
+        AMQResourceAdapter.BrokerXmlConfig = 
broker:(tcp://localhost:61616)?useJmx=false&amp;persistent=false
+        AMQResourceAdapter.ServerUrl = vm://jvm_broker
+        AMQMessageContainer = new://Container?type=MESSAGE
+        AMQMessageContainer.ResourceAdapter = AMQResourceAdapter
+        AMQConnectionFactory = new://Resource?type=javax.jms.ConnectionFactory
+        AMQConnectionFactory.ResourceAdapter = AMQResourceAdapter
       </property>
     </configuration>
   </container>

Reply via email to