Create tests

Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/978be21b
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/978be21b
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/978be21b

Branch: refs/heads/tomee-1.7.x
Commit: 978be21b59483cd002bb6eb278b89831d51d4f8c
Parents: ab26c04
Author: Otavio Santana <[email protected]>
Authored: Thu Jul 6 09:21:06 2017 -0300
Committer: Otavio Santana <[email protected]>
Committed: Thu Jul 6 09:21:06 2017 -0300

----------------------------------------------------------------------
 .../openejb/core/mdb/MdbContainerFailTest.java  | 147 +++++++++++++++++++
 .../openejb/core/mdb/MdbContainerTest.java      |  24 +++
 .../META-INF/org.apache.openejb/service-jar.txt |  53 +++++++
 .../META-INF/org.apache.openejb/service-jar.xml |  53 -------
 4 files changed, 224 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/978be21b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerFailTest.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerFailTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerFailTest.java
new file mode 100644
index 0000000..fa570b0
--- /dev/null
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerFailTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.core.mdb;
+
+import org.apache.activemq.ActiveMQXAConnectionFactory;
+import org.apache.openejb.activemq.AMQXASupportTest;
+import org.apache.openejb.jee.MessageDrivenBean;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Configuration;
+import org.apache.openejb.testing.Module;
+import org.apache.openejb.testng.PropertiesBuilder;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.XAConnectionFactory;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+
+@RunWith(ApplicationComposer.class)
+public class MdbContainerFailTest {
+
+    private static final String TEXT = "foo";
+
+
+    @Configuration
+    public Properties config() {
+        return new PropertiesBuilder()
+
+                .p("amq", "new://Resource?type=ActiveMQResourceAdapter")
+                .p("amq.DataSource", "")
+                .p("amq.BrokerXmlConfig", "broker:(vm://localhost)")
+
+                .p("target", "new://Resource?type=Queue")
+
+                .p("mdbs", "new://Container?type=MESSAGE")
+                .p("mdbs.ResourceAdapter", "amq")
+
+                .p("cf", "new://Resource?type=" + 
ConnectionFactory.class.getName())
+                .p("cf.ResourceAdapter", "amq")
+
+                .p("xaCf", "new://Resource?class-name=" + 
ActiveMQXAConnectionFactory.class.getName())
+                .p("xaCf.BrokerURL", "vm://localhost")
+                .p("mdb.activation.ignore", "testString")
+                .p("mdb.activation.ignore2", "testString")
+                .build();
+    }
+
+    @Module
+    public MessageDrivenBean jar() {
+        return new MessageDrivenBean(AMQXASupportTest.Listener.class);
+    }
+
+    @Resource(name = "target")
+    private Queue destination;
+
+    @Resource(name = "xaCf")
+    private XAConnectionFactory xacf;
+
+    @Resource(name = "cf")
+    private ConnectionFactory cf;
+
+    @Before
+    public void resetLatch() {
+        AMQXASupportTest.Listener.reset();
+    }
+
+    @Test
+    public void standardCode() throws Exception {
+        assertNotNull(cf);
+
+
+        final Connection connection = cf.createConnection();
+        try {
+            final Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+            final MessageProducer producer = 
session.createProducer(destination);
+            producer.send(session.createTextMessage(TEXT));
+            assertTrue(AMQXASupportTest.Listener.sync());
+        } finally {
+            connection.close();
+        }
+    }
+
+    @MessageDriven(activationConfig = {
+            @ActivationConfigProperty(propertyName = "destinationType", 
propertyValue = "javax.jms.Queue"),
+            @ActivationConfigProperty(propertyName = "destination", 
propertyValue = "target")
+    })
+    public static class Listener implements MessageListener {
+        public static CountDownLatch latch;
+        public static boolean ok = false;
+
+        @Override
+        public void onMessage(final Message message) {
+            try {
+                try {
+                    ok = TextMessage.class.isInstance(message) && 
TEXT.equals(TextMessage.class.cast(message).getText());
+                } catch (final JMSException e) {
+                    // no-op
+                }
+            } finally {
+                latch.countDown();
+            }
+        }
+
+        public static void reset() {
+            latch = new CountDownLatch(1);
+            ok = false;
+        }
+
+        public static boolean sync() throws InterruptedException {
+            latch.await(1, TimeUnit.MINUTES);
+            return ok;
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tomee/blob/978be21b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerTest.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerTest.java
index 6dcb202..2511584 100644
--- 
a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerTest.java
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbContainerTest.java
@@ -23,7 +23,10 @@ import org.apache.openejb.junit.ApplicationComposer;
 import org.apache.openejb.testing.Configuration;
 import org.apache.openejb.testing.Module;
 import org.apache.openejb.testng.PropertiesBuilder;
+import org.apache.openjpa.lib.util.Files;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -40,6 +43,11 @@ import javax.jms.Queue;
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.jms.XAConnectionFactory;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.Properties;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -53,6 +61,22 @@ public class MdbContainerTest {
 
     private static final String TEXT = "foo";
 
+    @BeforeClass
+    public static void beforeClass() throws URISyntaxException, IOException {
+        URL url = 
MdbContainerTest.class.getResource("/META-INF/org.apache.openejb/service-jar.txt");
+        File txtFile = new File(url.toURI());
+        File xmlFile = new File(txtFile.getParentFile(), "service-jar.xml");
+        Files.copy(txtFile, xmlFile);
+
+    }
+
+    @AfterClass
+    public static void afterClass() throws URISyntaxException {
+        URL stream = 
MdbContainerTest.class.getResource("/META-INF/org.apache.openejb/service-jar.xml");
+        File file = new File(stream.toURI());
+        file.delete();
+    }
+
     @Configuration
     public Properties config() {
         return new PropertiesBuilder()

http://git-wip-us.apache.org/repos/asf/tomee/blob/978be21b/container/openejb-core/src/test/resources/META-INF/org.apache.openejb/service-jar.txt
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/resources/META-INF/org.apache.openejb/service-jar.txt
 
b/container/openejb-core/src/test/resources/META-INF/org.apache.openejb/service-jar.txt
new file mode 100644
index 0000000..f391584
--- /dev/null
+++ 
b/container/openejb-core/src/test/resources/META-INF/org.apache.openejb/service-jar.txt
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  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.
+-->
+
+<!-- $Rev$ $Date$ -->
+
+<ServiceJar>
+
+
+  <ServiceProvider
+      id="Default MDB Container"
+      service="Container"
+      types="MESSAGE"
+      constructor="id, securityService, ResourceAdapter, 
MessageListenerInterface, ActivationSpecClass, InstanceLimit, 
FailOnUnknowActivationSpec"
+      class-name="org.apache.openejb.core.mdb.MdbContainer">
+
+    # The resource adapter delivers messages to the container
+
+    ResourceAdapter Default JMS Resource Adapter
+
+    # Specifies the message listener interface handled by this container
+
+    MessageListenerInterface javax.jms.MessageListener
+
+    # Specifies the activation spec class
+
+    ActivationSpecClass org.apache.activemq.ra.ActiveMQActivationSpec
+
+    # Specifies the maximum number of bean instances that are
+    # allowed to exist for each MDB deployment.
+
+    InstanceLimit 10
+
+    # log a warning if true or throw an exception if false is an activation 
spec can't be respected
+
+    FailOnUnknowActivationSpec = false
+
+  </ServiceProvider>
+</ServiceJar>

http://git-wip-us.apache.org/repos/asf/tomee/blob/978be21b/container/openejb-core/src/test/resources/META-INF/org.apache.openejb/service-jar.xml
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/resources/META-INF/org.apache.openejb/service-jar.xml
 
b/container/openejb-core/src/test/resources/META-INF/org.apache.openejb/service-jar.xml
deleted file mode 100644
index f391584..0000000
--- 
a/container/openejb-core/src/test/resources/META-INF/org.apache.openejb/service-jar.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  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.
--->
-
-<!-- $Rev$ $Date$ -->
-
-<ServiceJar>
-
-
-  <ServiceProvider
-      id="Default MDB Container"
-      service="Container"
-      types="MESSAGE"
-      constructor="id, securityService, ResourceAdapter, 
MessageListenerInterface, ActivationSpecClass, InstanceLimit, 
FailOnUnknowActivationSpec"
-      class-name="org.apache.openejb.core.mdb.MdbContainer">
-
-    # The resource adapter delivers messages to the container
-
-    ResourceAdapter Default JMS Resource Adapter
-
-    # Specifies the message listener interface handled by this container
-
-    MessageListenerInterface javax.jms.MessageListener
-
-    # Specifies the activation spec class
-
-    ActivationSpecClass org.apache.activemq.ra.ActiveMQActivationSpec
-
-    # Specifies the maximum number of bean instances that are
-    # allowed to exist for each MDB deployment.
-
-    InstanceLimit 10
-
-    # log a warning if true or throw an exception if false is an activation 
spec can't be respected
-
-    FailOnUnknowActivationSpec = false
-
-  </ServiceProvider>
-</ServiceJar>

Reply via email to