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

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

commit c9794d52064da451b5fbb7aad9440f5673478b58
Author: Jonathan S. Fisher <jonathan.fis...@emoneyusa.com>
AuthorDate: Tue Sep 3 09:33:01 2019 -0500

    Add @jgallimore 's JMX Context Tests
---
 .../tests/jms/JMSContextInjectionTest.java         | 79 ++++++++++++++++++++++
 .../arquillian/tests/jms/JMSReceiverBean.java      | 41 +++++++++++
 .../arquillian/tests/jms/JMSSenderBean.java        | 44 ++++++++++++
 .../arquillian/tests/jms/MessageCounter.java       | 38 +++++++++++
 .../src/test/resources/arquillian.xml              | 28 ++++++--
 5 files changed, 225 insertions(+), 5 deletions(-)

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..b6a4d2c
--- /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,79 @@
+/**
+ * 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.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;
+
+@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");
+        }
+        Thread.sleep(100L);
+        assertEquals(200, messageCounter.getValue());
+    }
+
+    @Test
+    public void testTransactionShouldRollback() throws Exception {
+        messageCounter.reset();
+
+        try {
+            senderBean.sendToQueue("test", "Hello world", true);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        Thread.sleep(100L);
+        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..76beebf
--- /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,41 @@
+/**
+ * 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.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+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")
+})
+@TransactionAttribute(TransactionAttributeType.REQUIRED)
+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..9790cfd 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,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
         openejb.descriptors.output=true
+        
+        AMQResourceAdapter = new://Resource?type=ActiveMQResourceAdapter
+        AMQResourceAdapter.BrokerXmlConfig = 
broker:(vm://localhost)?useJmx=false&amp;persistent=false&amp;deleteAllMessagesOnStartup=true
+        AMQMessageContainer = new://Container?type=MESSAGE
+        AMQMessageContainer.ResourceAdapter = AMQResourceAdapter
+        AMQConnectionFactory = new://Resource?type=javax.jms.ConnectionFactory
+        AMQConnectionFactory.ResourceAdapter = AMQResourceAdapter
       </property>
     </configuration>
   </container>
@@ -43,11 +49,17 @@
       <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:(vm://localhost)?useJmx=false&amp;persistent=false&amp;deleteAllMessagesOnStartup=true
+        AMQMessageContainer = new://Container?type=MESSAGE
+        AMQMessageContainer.ResourceAdapter = AMQResourceAdapter
+        AMQConnectionFactory = new://Resource?type=javax.jms.ConnectionFactory
+        AMQConnectionFactory.ResourceAdapter = AMQResourceAdapter
       </property>
     </configuration>
   </container>
@@ -65,12 +77,12 @@
         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
+        AMQResourceAdapter.BrokerXmlConfig = 
broker:(vm://localhost)?useJmx=false&amp;persistent=false&amp;deleteAllMessagesOnStartup=true
         AMQMessageContainer = new://Container?type=MESSAGE
         AMQMessageContainer.ResourceAdapter = AMQResourceAdapter
         AMQConnectionFactory = new://Resource?type=javax.jms.ConnectionFactory
         AMQConnectionFactory.ResourceAdapter = AMQResourceAdapter
+        
         javax.security.jacc.policy.provider=sun.security.provider.PolicyFile
       </property>
     </configuration>
@@ -83,11 +95,17 @@
       <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:(vm://localhost)?useJmx=false&amp;persistent=false&amp;deleteAllMessagesOnStartup=true
+        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