Rename activations tests
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/86f20fec Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/86f20fec Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/86f20fec Branch: refs/heads/master Commit: 86f20fec7b6d6b09e52c346e738dad0215b7afaa Parents: 1909894 Author: Otavio Santana <[email protected]> Authored: Wed Jul 12 12:26:20 2017 -0300 Committer: Otavio Santana <[email protected]> Committed: Wed Jul 12 12:26:20 2017 -0300 ---------------------------------------------------------------------- ...ContainerOverwriteBothConfigurationTest.java | 152 +++++++++++++++++++ ...erOverwriteIdContainerConfigurationTest.java | 150 ++++++++++++++++++ ...tainerOverwriteMessageConfigurationTest.java | 150 ++++++++++++++++++ ...tainerReadTheContainerConfigurationTest.java | 147 ++++++++++++++++++ .../activemq/ActivationContainerTest.java | 150 ------------------ .../activemq/ActivationContainerTest2.java | 150 ------------------ 6 files changed, 599 insertions(+), 300 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/86f20fec/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteBothConfigurationTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteBothConfigurationTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteBothConfigurationTest.java new file mode 100644 index 0000000..fb7542a --- /dev/null +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteBothConfigurationTest.java @@ -0,0 +1,152 @@ +/** + * 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.activemq; + +import org.apache.activemq.ActiveMQXAConnectionFactory; +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 ActivationContainerOverwriteBothConfigurationTest { + 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("mdb.container.amq.activation.destination","wrongTarget") + .p("mdbs.activation.destination", "target") + .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") + + .build(); + } + + @Module + public MessageDrivenBean jar() { + return new MessageDrivenBean(Listener.class); + } + + @Resource(name = "target") + private Queue destination; + + @Resource(name = "xaCf") + private XAConnectionFactory xacf; + + @Resource(name = "cf") + private ConnectionFactory cf; + + @Before + public void resetLatch() { + Listener.reset(); + } + + @Test + public void test() throws Exception { + assertNotNull(cf); + + + final Connection connection = cf.createConnection(); + testConnection(connection); + } + + + private void testConnection(final Connection connection) throws JMSException, InterruptedException { + try { + final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = session.createProducer(destination); + producer.send(session.createTextMessage(TEXT)); + assertTrue(Listener.sync()); + } finally { + try { + connection.close(); + } catch (final JMSException e) { + //no-op + } + } + } + + @MessageDriven(activationConfig = { + @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), + @ActivationConfigProperty(propertyName = "destination", propertyValue = "toBeOverwrite") + }) + 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; + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/86f20fec/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteIdContainerConfigurationTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteIdContainerConfigurationTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteIdContainerConfigurationTest.java new file mode 100644 index 0000000..6369f0c --- /dev/null +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteIdContainerConfigurationTest.java @@ -0,0 +1,150 @@ +/** + * 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.activemq; + +import org.apache.activemq.ActiveMQXAConnectionFactory; +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 ActivationContainerOverwriteIdContainerConfigurationTest { + 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("mdb.container.amq.activation.destination","wrongTarget") + .p("mdbs.activation.destination", "target") + .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") + + .build(); + } + + @Module + public MessageDrivenBean jar() { + return new MessageDrivenBean(Listener.class); + } + + @Resource(name = "target") + private Queue destination; + + @Resource(name = "xaCf") + private XAConnectionFactory xacf; + + @Resource(name = "cf") + private ConnectionFactory cf; + + @Before + public void resetLatch() { + Listener.reset(); + } + + @Test + public void test() throws Exception { + assertNotNull(cf); + + + final Connection connection = cf.createConnection(); + testConnection(connection); + } + + + private void testConnection(final Connection connection) throws JMSException, InterruptedException { + try { + final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = session.createProducer(destination); + producer.send(session.createTextMessage(TEXT)); + assertTrue(Listener.sync()); + } finally { + try { + connection.close(); + } catch (final JMSException e) { + //no-op + } + } + } + + @MessageDriven(activationConfig = { + @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") + }) + 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; + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/86f20fec/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteMessageConfigurationTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteMessageConfigurationTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteMessageConfigurationTest.java new file mode 100644 index 0000000..e2a1f2d --- /dev/null +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteMessageConfigurationTest.java @@ -0,0 +1,150 @@ +/** + * 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.activemq; + +import org.apache.activemq.ActiveMQXAConnectionFactory; +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 ActivationContainerOverwriteMessageConfigurationTest { + 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("mdbs.activation.destination", "target") + + .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") + + .build(); + } + + @Module + public MessageDrivenBean jar() { + return new MessageDrivenBean(Listener.class); + } + + @Resource(name = "target") + private Queue destination; + + @Resource(name = "xaCf") + private XAConnectionFactory xacf; + + @Resource(name = "cf") + private ConnectionFactory cf; + + @Before + public void resetLatch() { + Listener.reset(); + } + + @Test + public void test() throws Exception { + assertNotNull(cf); + + + final Connection connection = cf.createConnection(); + testConnection(connection); + } + + + private void testConnection(final Connection connection) throws JMSException, InterruptedException { + try { + final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = session.createProducer(destination); + producer.send(session.createTextMessage(TEXT)); + assertTrue(Listener.sync()); + } finally { + try { + connection.close(); + } catch (final JMSException e) { + //no-op + } + } + } + + @MessageDriven(activationConfig = { + @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") + }) + 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; + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/86f20fec/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerReadTheContainerConfigurationTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerReadTheContainerConfigurationTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerReadTheContainerConfigurationTest.java new file mode 100644 index 0000000..e534903 --- /dev/null +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerReadTheContainerConfigurationTest.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 + * <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.activemq; + +import org.apache.activemq.ActiveMQXAConnectionFactory; +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.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 ActivationContainerReadTheContainerConfigurationTest { + 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("mdbs.activation.destination", "target") + .p("mdbs.activation.destinationType", "javax.jms.Queue") + .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") + + .build(); + } + + @Module + public MessageDrivenBean jar() { + return new MessageDrivenBean(Listener.class); + } + + @Resource(name = "target") + private Queue destination; + + @Resource(name = "xaCf") + private XAConnectionFactory xacf; + + @Resource(name = "cf") + private ConnectionFactory cf; + + @Before + public void resetLatch() { + Listener.reset(); + } + + @Test + public void test() throws Exception { + assertNotNull(cf); + + + final Connection connection = cf.createConnection(); + testConnection(connection); + } + + + private void testConnection(final Connection connection) throws JMSException, InterruptedException { + try { + final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = session.createProducer(destination); + producer.send(session.createTextMessage(TEXT)); + assertTrue(Listener.sync()); + } finally { + try { + connection.close(); + } catch (final JMSException e) { + //no-op + } + } + } + + @MessageDriven + 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; + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/86f20fec/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest.java deleted file mode 100644 index cc35275..0000000 --- a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/** - * 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.activemq; - -import org.apache.activemq.ActiveMQXAConnectionFactory; -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 ActivationContainerTest { - 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("mdbs.activation.destination", "target") - - .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") - - .build(); - } - - @Module - public MessageDrivenBean jar() { - return new MessageDrivenBean(Listener.class); - } - - @Resource(name = "target") - private Queue destination; - - @Resource(name = "xaCf") - private XAConnectionFactory xacf; - - @Resource(name = "cf") - private ConnectionFactory cf; - - @Before - public void resetLatch() { - Listener.reset(); - } - - @Test - public void test() throws Exception { - assertNotNull(cf); - - - final Connection connection = cf.createConnection(); - testConnection(connection); - } - - - private void testConnection(final Connection connection) throws JMSException, InterruptedException { - try { - final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - final MessageProducer producer = session.createProducer(destination); - producer.send(session.createTextMessage(TEXT)); - assertTrue(Listener.sync()); - } finally { - try { - connection.close(); - } catch (final JMSException e) { - //no-op - } - } - } - - @MessageDriven(activationConfig = { - @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") - }) - 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; - } - } -} http://git-wip-us.apache.org/repos/asf/tomee/blob/86f20fec/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest2.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest2.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest2.java deleted file mode 100644 index ba9be74..0000000 --- a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest2.java +++ /dev/null @@ -1,150 +0,0 @@ -/** - * 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.activemq; - -import org.apache.activemq.ActiveMQXAConnectionFactory; -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 ActivationContainerTest2 { - 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("mdb.container.amq.activation.destination","wrongTarget") - .p("mdbs.activation.destination", "target") - .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") - - .build(); - } - - @Module - public MessageDrivenBean jar() { - return new MessageDrivenBean(Listener.class); - } - - @Resource(name = "target") - private Queue destination; - - @Resource(name = "xaCf") - private XAConnectionFactory xacf; - - @Resource(name = "cf") - private ConnectionFactory cf; - - @Before - public void resetLatch() { - Listener.reset(); - } - - @Test - public void test() throws Exception { - assertNotNull(cf); - - - final Connection connection = cf.createConnection(); - testConnection(connection); - } - - - private void testConnection(final Connection connection) throws JMSException, InterruptedException { - try { - final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - final MessageProducer producer = session.createProducer(destination); - producer.send(session.createTextMessage(TEXT)); - assertTrue(Listener.sync()); - } finally { - try { - connection.close(); - } catch (final JMSException e) { - //no-op - } - } - } - - @MessageDriven(activationConfig = { - @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") - }) - 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; - } - } -}
