Repository: tomee Updated Branches: refs/heads/tomee-1.7.x c72ef140a -> 74021cdfc
Adds backpot Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/74021cdf Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/74021cdf Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/74021cdf Branch: refs/heads/tomee-1.7.x Commit: 74021cdfc6cc9c73b127f01308947ee0eadbc8af Parents: c72ef14 Author: Otavio Santana <[email protected]> Authored: Fri Jul 14 11:45:33 2017 -0300 Committer: Otavio Santana <[email protected]> Committed: Thu Jul 20 08:36:15 2017 -0300 ---------------------------------------------------------------------- .../ActivationConfigPropertyOverride.java | 36 ++++- .../apache/openejb/core/mdb/MdbContainer.java | 7 + ...ContainerOverwriteBothConfigurationTest.java | 152 ++++++++++++++++++ ...erOverwriteIdContainerConfigurationTest.java | 150 ++++++++++++++++++ ...tainerOverwriteMessageConfigurationTest.java | 150 ++++++++++++++++++ ...rwriteReadTheContainerConfigurationTest.java | 147 +++++++++++++++++ ...ContainerOverwriteSystemContainerIdTest.java | 158 +++++++++++++++++++ .../ActivationContainerOverwriteSystemTest.java | 158 +++++++++++++++++++ .../ActivationConfigPropertyOverrideTest.java | 45 ++++-- 9 files changed, 991 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/74021cdf/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java b/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java index 3bd5903..c4f3914 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java @@ -17,7 +17,9 @@ package org.apache.openejb.config; +import org.apache.openejb.Container; import org.apache.openejb.OpenEJBException; +import org.apache.openejb.core.mdb.MdbContainer; import org.apache.openejb.jee.ActivationConfig; import org.apache.openejb.jee.ActivationConfigProperty; import org.apache.openejb.jee.EjbJar; @@ -26,6 +28,7 @@ import org.apache.openejb.jee.MessageDrivenBean; import org.apache.openejb.jee.oejb3.EjbDeployment; import org.apache.openejb.jee.oejb3.OpenejbJar; import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.spi.ContainerSystem; import org.apache.openejb.util.LogCategory; import org.apache.openejb.util.Logger; @@ -73,7 +76,15 @@ public class ActivationConfigPropertyOverride implements DynamicDeployer { final MessageDrivenBean mdb = (MessageDrivenBean) bean; - final Properties overrides = ConfigurationFactory.getOverrides(properties, "mdb.activation", "EnterpriseBean"); + final Properties overrides = new Properties(); + + final MdbContainer mdbContainer = getMdbContainer(ejbDeployment.getContainerId()); + if (mdbContainer != null) { + overrides.putAll(ConfigurationFactory.getOverrides(properties, "mdb.container." + mdbContainer.getContainerID() + ".activation", "EnterpriseBean")); + overrides.putAll(ConfigurationFactory.getOverrides(mdbContainer.getProperties(), "activation", "EnterpriseBean")); + } + + overrides.putAll(ConfigurationFactory.getOverrides(properties, "mdb.activation", "EnterpriseBean")); overrides.putAll(ConfigurationFactory.getOverrides(properties, mdb.getMessagingType() + ".activation", "EnterpriseBean")); overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbName + ".activation", "EnterpriseBean")); overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbDeployment.getDeploymentId() + ".activation", "EnterpriseBean")); @@ -115,6 +126,29 @@ public class ActivationConfigPropertyOverride implements DynamicDeployer { return appModule; } + private MdbContainer getMdbContainer(final String containerId) { + + final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); + + if (containerId == null || containerId.length() == 0) { + final Container[] containers = containerSystem.containers(); + for (Container container : containers) { + if (MdbContainer.class.isInstance(container)) { + return MdbContainer.class.cast(container); + } + } + + return null; + } + + final Container container = containerSystem.getContainer(containerId); + if (MdbContainer.class.isInstance(container)) { + return MdbContainer.class.cast(container); + } + return null; + + } + private ActivationConfigProperty findActivationProperty(final List<ActivationConfigProperty> activationConfigList, final String nameOfProperty) { for (final ActivationConfigProperty activationProp : activationConfigList) { if (activationProp.getActivationConfigPropertyName().equals(nameOfProperty)) { http://git-wip-us.apache.org/repos/asf/tomee/blob/74021cdf/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java index 40c11db..87b079c 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java @@ -73,6 +73,7 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; @@ -103,6 +104,8 @@ public class MdbContainer implements RpcContainer { private final InboundRecovery inboundRecovery; private final boolean failOnUnknownActivationSpec; + private final Properties properties = new Properties(); + public MdbContainer(final Object containerID, final SecurityService securityService, final ResourceAdapter resourceAdapter, final Class messageListenerInterface, final Class activationSpecClass, final int instanceLimit, final boolean failOnUnknownActivationSpec) { this.containerID = containerID; @@ -144,6 +147,10 @@ public class MdbContainer implements RpcContainer { return activationSpecClass; } + public Properties getProperties() { + return properties; + } + public void deploy(final BeanContext beanContext) throws OpenEJBException { final Object deploymentId = beanContext.getDeploymentID(); if (!beanContext.getMdbInterface().equals(messageListenerInterface)) { http://git-wip-us.apache.org/repos/asf/tomee/blob/74021cdf/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..6a66fc4 --- /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; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/74021cdf/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..13c61e5 --- /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; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/74021cdf/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..0aa5c72 --- /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; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/74021cdf/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteReadTheContainerConfigurationTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteReadTheContainerConfigurationTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteReadTheContainerConfigurationTest.java new file mode 100644 index 0000000..e51b211 --- /dev/null +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteReadTheContainerConfigurationTest.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 ActivationContainerOverwriteReadTheContainerConfigurationTest { + 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; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/74021cdf/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteSystemContainerIdTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteSystemContainerIdTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteSystemContainerIdTest.java new file mode 100644 index 0000000..a9cbfa8 --- /dev/null +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteSystemContainerIdTest.java @@ -0,0 +1,158 @@ +/** + * 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.AfterClass; +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 ActivationContainerOverwriteSystemContainerIdTest { + private static final String TEXT = "foo"; + + @Configuration + public Properties config() { + + System.setProperty("mdb.container.amq.activation.destination", "wrongTarget"); + + 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(); + } + + @AfterClass + public static void afterTest() { + System.clearProperty("mdb.container.amq.activation.destination"); + } + + @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; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/74021cdf/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteSystemTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteSystemTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteSystemTest.java new file mode 100644 index 0000000..bcb2ebd --- /dev/null +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerOverwriteSystemTest.java @@ -0,0 +1,158 @@ +/** + * 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.AfterClass; +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 ActivationContainerOverwriteSystemTest { + private static final String TEXT = "foo"; + + @Configuration + public Properties config() { + + System.setProperty("mdbs.activation.destination", "wrongTarget"); + + 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(); + } + + @AfterClass + public static void afterTest() { + System.clearProperty("mdbs.activation.destination"); + } + + @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; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/74021cdf/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java b/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java index 402af7f..05866a1 100755 --- a/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java +++ b/container/openejb-core/src/test/java/org/apache/openejb/config/ActivationConfigPropertyOverrideTest.java @@ -16,8 +16,8 @@ */ package org.apache.openejb.config; -import junit.framework.TestCase; import org.apache.openejb.OpenEJBException; +import org.apache.openejb.activemq.ActivationContainerOverwriteBothConfigurationTest; import org.apache.openejb.assembler.classic.Assembler; import org.apache.openejb.assembler.classic.EjbJarInfo; import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo; @@ -29,13 +29,21 @@ import org.apache.openejb.jee.ActivationConfigProperty; import org.apache.openejb.jee.EjbJar; import org.apache.openejb.jee.MessageDrivenBean; import org.apache.openejb.jee.oejb3.OpenejbJar; +import org.apache.openejb.junit.ApplicationComposer; import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.testing.Module; +import org.junit.Test; +import org.junit.runner.RunWith; import javax.ejb.MessageDriven; import javax.jms.Message; import javax.jms.MessageListener; import java.util.Properties; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /* 1 -D<deploymentId>.activation.<property>=<value> 2. -D<ejbName>.activation.<property>=<value> @@ -43,12 +51,19 @@ import java.util.Properties; 4. -Dmdb.activation.<property>=<value> Order: 4 is overriden by 3 (and so on) */ -public class ActivationConfigPropertyOverrideTest extends TestCase { +@RunWith(ApplicationComposer.class) +public class ActivationConfigPropertyOverrideTest{ + + @Module + public MessageDrivenBean jar() { + return new MessageDrivenBean(ActivationContainerOverwriteBothConfigurationTest.Listener.class); + } /** * Test internal method used in ActivationConfigPropertyOverride */ + @Test public void testGetOverridesShouldTrimAwayPrefixesCorrectly() { final Properties properties = new Properties(); properties.put("ENTERPRISEBEAN.mdb.activation.destinationType", "something"); @@ -61,6 +76,7 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { * * @throws OpenEJBException */ + @Test public void testOverrideActivationConfigProperty() throws OpenEJBException { // set overrides for destinationType and check @@ -81,6 +97,7 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { * * @throws OpenEJBException */ + @Test public void testAddActivationConfigPropertyIfNotAlreadyPresent() throws OpenEJBException { // set overrides @@ -110,6 +127,7 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { return false; } + @Test public void testNoOverrideSetShouldNotOverride() throws OpenEJBException { if (SystemInstance.get().getProperties().containsKey("ENTERPRISEBEAN.mdb.activation.destinationType")) { SystemInstance.get().getProperties().remove("ENTERPRISEBEAN.mdb.activation.destinationType"); @@ -124,6 +142,7 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { assertTrue(containsActivationKeyValuePair(mdb, "destinationType", "shouldNotBeOverriddenString")); } + @Test public void testNotOverridden() throws Exception { SystemInstance.reset(); final Assembler assembler = new Assembler(); @@ -151,6 +170,7 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { assertEquals("YELLOW.TOPIC", yellow.activationProperties.get("destination")); } + @Test public void testMdbOverrideSystem() throws Exception { SystemInstance.reset(); final Properties systProps = SystemInstance.get().getProperties(); @@ -190,6 +210,7 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { } } + @Test public void testMdbOverrideOpenejbJar() throws Exception { SystemInstance.reset(); @@ -253,6 +274,7 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { } + @Test public void testEjbNameOverrideSystem() throws Exception { SystemInstance.reset(); final Properties properties = SystemInstance.get().getProperties(); @@ -286,6 +308,7 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination")); } + @Test public void testEjbNameOverrideOpenejbJar() throws Exception { SystemInstance.reset(); @@ -351,10 +374,10 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { @MessageDriven(activationConfig = { - @javax.ejb.ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "7"), - @javax.ejb.ActivationConfigProperty(propertyName = "maxMessagesPerSessions", propertyValue = "4"), - @javax.ejb.ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), - @javax.ejb.ActivationConfigProperty(propertyName = "destination", propertyValue = "ORANGE.QUEUE") + @javax.ejb.ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "7"), + @javax.ejb.ActivationConfigProperty(propertyName = "maxMessagesPerSessions", propertyValue = "4"), + @javax.ejb.ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), + @javax.ejb.ActivationConfigProperty(propertyName = "destination", propertyValue = "ORANGE.QUEUE") }) public static class Orange implements MessageListener { @@ -364,10 +387,10 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { } @MessageDriven(activationConfig = { - @javax.ejb.ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "5"), - @javax.ejb.ActivationConfigProperty(propertyName = "maxMessagesPerSessions", propertyValue = "10"), - @javax.ejb.ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"), - @javax.ejb.ActivationConfigProperty(propertyName = "destination", propertyValue = "YELLOW.TOPIC") + @javax.ejb.ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "5"), + @javax.ejb.ActivationConfigProperty(propertyName = "maxMessagesPerSessions", propertyValue = "10"), + @javax.ejb.ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"), + @javax.ejb.ActivationConfigProperty(propertyName = "destination", propertyValue = "YELLOW.TOPIC") }) public static class Yellow implements MessageListener { @@ -376,4 +399,4 @@ public class ActivationConfigPropertyOverrideTest extends TestCase { } } -} +} \ No newline at end of file
