Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 94FA518230 for ; Wed, 6 Jan 2016 15:11:38 +0000 (UTC) Received: (qmail 48117 invoked by uid 500); 6 Jan 2016 15:11:38 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 48078 invoked by uid 500); 6 Jan 2016 15:11:38 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 48069 invoked by uid 99); 6 Jan 2016 15:11:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jan 2016 15:11:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 097C8E0941; Wed, 6 Jan 2016 15:11:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cshannon@apache.org To: commits@activemq.apache.org Date: Wed, 06 Jan 2016 15:11:38 -0000 Message-Id: <4676ddf547f44785a92fdccc5e146191@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] activemq git commit: Initial Version of activemq-junit Repository: activemq Updated Branches: refs/heads/master 16bc0f0d7 -> 8317208a1 Initial Version of activemq-junit Added configure method to EmbeddedActiveMQBroker Added support for XBean configuration Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/da3b1380 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/da3b1380 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/da3b1380 Branch: refs/heads/master Commit: da3b1380234c5d1745094f883778f19e58fe9cee Parents: 16bc0f0 Author: Quinn Stevenson Authored: Wed Dec 23 13:29:06 2015 -0700 Committer: Christopher L. Shannon (cshannon) Committed: Wed Jan 6 15:10:02 2016 +0000 ---------------------------------------------------------------------- activemq-tooling/activemq-junit/pom.xml | 70 ++++ .../activemq/junit/EmbeddedActiveMQBroker.java | 404 +++++++++++++++++++ .../junit/EmbeddedActiveMQBrokerConfigTest.java | 110 +++++ .../junit/EmbeddedActiveMQBrokerRuleTest.java | 43 ++ ...mbeddedActiveMQBrokerXbeanUriConfigTest.java | 108 +++++ .../MultipleEmbeddedActiveMQBrokerRuleTest.java | 60 +++ .../src/test/resources/activemq-simple.xml | 28 ++ activemq-tooling/pom.xml | 1 + 8 files changed, 824 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/da3b1380/activemq-tooling/activemq-junit/pom.xml ---------------------------------------------------------------------- diff --git a/activemq-tooling/activemq-junit/pom.xml b/activemq-tooling/activemq-junit/pom.xml new file mode 100644 index 0000000..33f8366 --- /dev/null +++ b/activemq-tooling/activemq-junit/pom.xml @@ -0,0 +1,70 @@ + + + + 4.0.0 + + + org.apache.activemq.tooling + activemq-tooling + 5.14-SNAPSHOT + + + activemq-junit + ActiveMQ :: JUnit Rule + + JUnit Rule for Embedded ActiveMQ Brokers + + + + org.apache.activemq + activemq-broker + ${project.version} + provided + + + org.springframework + spring-context + provided + + + org.apache.activemq + activemq-spring + ${project.version} + provided + + + org.apache.activemq + activemq-pool + ${project.version} + provided + + + junit + junit + provided + + + + org.slf4j + slf4j-simple + ${slf4j-version} + test + + + + http://git-wip-us.apache.org/repos/asf/activemq/blob/da3b1380/activemq-tooling/activemq-junit/src/main/java/org/apache/activemq/junit/EmbeddedActiveMQBroker.java ---------------------------------------------------------------------- diff --git a/activemq-tooling/activemq-junit/src/main/java/org/apache/activemq/junit/EmbeddedActiveMQBroker.java b/activemq-tooling/activemq-junit/src/main/java/org/apache/activemq/junit/EmbeddedActiveMQBroker.java new file mode 100644 index 0000000..3e328e8 --- /dev/null +++ b/activemq-tooling/activemq-junit/src/main/java/org/apache/activemq/junit/EmbeddedActiveMQBroker.java @@ -0,0 +1,404 @@ +/* + * 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.activemq.junit; + +import java.net.URI; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerFactory; +import org.apache.activemq.broker.BrokerPlugin; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.region.Destination; +import org.apache.activemq.broker.region.Queue; +import org.apache.activemq.broker.region.Topic; +import org.apache.activemq.broker.region.policy.PolicyEntry; +import org.apache.activemq.broker.region.policy.PolicyMap; +import org.apache.activemq.plugin.StatisticsBrokerPlugin; +import org.apache.activemq.pool.PooledConnectionFactory; +import org.junit.rules.ExternalResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A JUnit Rule that embeds an ActiveMQ broker into a test. + */ +public class EmbeddedActiveMQBroker extends ExternalResource { + Logger log = LoggerFactory.getLogger(this.getClass()); + + BrokerService brokerService; + + /** + * Create an embedded ActiveMQ broker using defaults + * + * The defaults are: + * - the broker name is 'embedded-broker' + * - JMX is disabled + * - Persistence is disabled + * + */ + public EmbeddedActiveMQBroker() { + brokerService = new BrokerService(); + brokerService.setUseJmx(false); + brokerService.setUseShutdownHook(false); + brokerService.setPersistent(false); + brokerService.setBrokerName("embedded-broker"); + } + + /** + * Create an embedded ActiveMQ broker using a configuration URI + */ + public EmbeddedActiveMQBroker(String configurationURI ) { + try { + brokerService = BrokerFactory.createBroker(configurationURI); + } catch (Exception ex) { + throw new RuntimeException("Exception encountered creating embedded ActiveMQ broker from configuration URI: " + configurationURI, ex); + } + } + + /** + * Create an embedded ActiveMQ broker using a configuration URI + */ + public EmbeddedActiveMQBroker(URI configurationURI ) { + try { + brokerService = BrokerFactory.createBroker(configurationURI); + } catch (Exception ex) { + throw new RuntimeException("Exception encountered creating embedded ActiveMQ broker from configuration URI: " + configurationURI, ex); + } + } + + /** + * Customize the configuration of the embedded ActiveMQ broker + * + * This method is called before the embedded ActiveMQ broker is started, and can + * be overridden to this method to customize the broker configuration. + */ + protected void configure() {} + + /** + * Start the embedded ActiveMQ broker, blocking until the broker has successfully started. + *

+ * The broker will normally be started by JUnit using the before() method. This method allows the broker to + * be started manually to support advanced testing scenarios. + */ + public void start() { + try { + this.configure(); + brokerService.start(); + } catch (Exception ex) { + throw new RuntimeException("Exception encountered starting embedded ActiveMQ broker: {}" + this.getBrokerName(), ex); + } + + brokerService.waitUntilStarted(); + } + + /** + * Stop the embedded ActiveMQ broker, blocking until the broker has stopped. + *

+ * The broker will normally be stopped by JUnit using the after() method. This method allows the broker to + * be stopped manually to support advanced testing scenarios. + */ + public void stop() { + if (!brokerService.isStopped()) { + try { + brokerService.stop(); + } catch (Exception ex) { + log.warn("Exception encountered stopping embedded ActiveMQ broker: {}" + this.getBrokerName(), ex); + } + } + + brokerService.waitUntilStopped(); + } + + /** + * Start the embedded ActiveMQ Broker + *

+ * Invoked by JUnit to setup the resource + */ + @Override + protected void before() throws Throwable { + log.info("Starting embedded ActiveMQ broker: {}", this.getBrokerName()); + + this.start(); + + super.before(); + } + + /** + * Stop the embedded ActiveMQ Broker + *

+ * Invoked by JUnit to tear down the resource + */ + @Override + protected void after() { + log.info("Stopping Embedded ActiveMQ Broker: {}", this.getBrokerName()); + + super.after(); + + this.stop(); + } + + /** + * Create an ActiveMQConnectionFactory for the embedded ActiveMQ Broker + * + * @return a new ActiveMQConnectionFactory + */ + public ActiveMQConnectionFactory createConnectionFactory() { + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); + connectionFactory.setBrokerURL(brokerService.getVmConnectorURI().toString()); + return connectionFactory; + } + + /** + * Create an PooledConnectionFactory for the embedded ActiveMQ Broker + * + * @return a new PooledConnectionFactory + */ + public PooledConnectionFactory createPooledConnectionFactory() { + ActiveMQConnectionFactory connectionFactory = createConnectionFactory(); + + PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(connectionFactory); + + return pooledConnectionFactory; + } + + /** + * Get the BrokerService for the embedded ActiveMQ broker. + *

+ * This may be required for advanced configuration of the BrokerService. + * + * @return the embedded ActiveMQ broker + */ + public BrokerService getBrokerService() { + return brokerService; + } + + /** + * Get the VM URL for the embedded ActiveMQ Broker + *

+ * NOTE: The option is precreate=false option is appended to the URL to avoid the automatic creation of brokers + * and the resulting duplicate broker errors + * + * @return the VM URL for the embedded broker + */ + public String getVmURL() { + return String.format("failover:(%s?create=false)", brokerService.getVmConnectorURI().toString()); + } + + /** + * Get the name of the embedded ActiveMQ Broker + * + * @return name of the embedded broker + */ + public String getBrokerName() { + return brokerService.getBrokerName(); + } + + public void setBrokerName(String brokerName) { + brokerService.setBrokerName(brokerName); + } + + public boolean isStatisticsPluginEnabled() { + BrokerPlugin[] plugins = brokerService.getPlugins(); + + if (null != plugins) { + for (BrokerPlugin plugin : plugins) { + if (plugin instanceof StatisticsBrokerPlugin) { + return true; + } + } + } + + return false; + } + + public void enableStatisticsPlugin() { + if (!isStatisticsPluginEnabled()) { + BrokerPlugin[] newPlugins; + BrokerPlugin[] currentPlugins = brokerService.getPlugins(); + if (null != currentPlugins && 0 < currentPlugins.length) { + newPlugins = new BrokerPlugin[currentPlugins.length + 1]; + + System.arraycopy(currentPlugins, 0, newPlugins, 0, currentPlugins.length); + } else { + newPlugins = new BrokerPlugin[1]; + } + + newPlugins[newPlugins.length - 1] = new StatisticsBrokerPlugin(); + + brokerService.setPlugins(newPlugins); + } + } + + public void disableStatisticsPlugin() { + if (isStatisticsPluginEnabled()) { + BrokerPlugin[] currentPlugins = brokerService.getPlugins(); + if (1 < currentPlugins.length) { + BrokerPlugin[] newPlugins = new BrokerPlugin[currentPlugins.length - 1]; + + int i = 0; + for (BrokerPlugin plugin : currentPlugins) { + if (!(plugin instanceof StatisticsBrokerPlugin)) { + newPlugins[i++] = plugin; + } + } + brokerService.setPlugins(newPlugins); + } else { + brokerService.setPlugins(null); + } + + } + } + + public boolean isAdvisoryForDeliveryEnabled() { + return getDefaultPolicyEntry().isAdvisoryForDelivery(); + } + + public void enableAdvisoryForDelivery() { + getDefaultPolicyEntry().setAdvisoryForDelivery(true); + } + + public void disableAdvisoryForDelivery() { + getDefaultPolicyEntry().setAdvisoryForDelivery(false); + } + + public boolean isAdvisoryForConsumedEnabled() { + return getDefaultPolicyEntry().isAdvisoryForConsumed(); + } + + public void enableAdvisoryForConsumed() { + getDefaultPolicyEntry().setAdvisoryForConsumed(true); + } + + public void disableAdvisoryForConsumed() { + getDefaultPolicyEntry().setAdvisoryForConsumed(false); + } + + public boolean isAdvisoryForDiscardingMessagesEnabled() { + return getDefaultPolicyEntry().isAdvisoryForDiscardingMessages(); + } + + public void enableAdvisoryForDiscardingMessages() { + getDefaultPolicyEntry().setAdvisoryForDiscardingMessages(true); + } + + public void disableAdvisoryForDiscardingMessages() { + getDefaultPolicyEntry().setAdvisoryForDiscardingMessages(false); + } + + public boolean isAdvisoryForFastProducersEnabled() { + return getDefaultPolicyEntry().isAdvisoryForFastProducers(); + } + + public void enableAdvisoryForFastProducers() { + getDefaultPolicyEntry().setAdvisoryForFastProducers(true); + } + + public void disableAdvisoryForFastProducers() { + getDefaultPolicyEntry().setAdvisoryForFastProducers(false); + } + + public boolean isAdvisoryForSlowConsumersEnabled() { + return getDefaultPolicyEntry().isAdvisoryForSlowConsumers(); + } + + public void enableAdvisoryForSlowConsumers() { + getDefaultPolicyEntry().setAdvisoryForSlowConsumers(true); + } + + public void disableAdvisoryForSlowConsumers() { + getDefaultPolicyEntry().setAdvisoryForSlowConsumers(false); + } + + /** + * Get the number of messages in a specific JMS Destination. + *

+ * The full name of the JMS destination including the prefix should be provided - i.e. queue:myQueue + * or topic:myTopic. If the destination type prefix is not included in the destination name, a prefix + * of "queue:" is assumed. + * + * @param fullDestinationName the full name of the JMS Destination + * @return the number of messages in the JMS Destination + */ + public int getMessageCount(String fullDestinationName) throws Exception { + final int QUEUE_TYPE = 1; + final int TOPIC_TYPE = 2; + + if (null == brokerService) { + throw new IllegalStateException("BrokerService has not yet been created - was before() called?"); + } + + int destinationType = QUEUE_TYPE; + String destinationName = fullDestinationName; + + if (fullDestinationName.startsWith("queue:")) { + destinationName = fullDestinationName.substring(fullDestinationName.indexOf(':') + 1); + } else if (fullDestinationName.startsWith("topic:")) { + destinationType = TOPIC_TYPE; + destinationName = fullDestinationName.substring(fullDestinationName.indexOf(':') + 1); + } + + int messageCount = -1; + boolean foundDestination = false; + for (Destination destination : brokerService.getBroker().getDestinationMap().values()) { + String tmpName = destination.getName(); + if (tmpName.equalsIgnoreCase(destinationName)) { + switch (destinationType) { + case QUEUE_TYPE: + if (destination instanceof Queue) { + messageCount = destination.getMessageStore().getMessageCount(); + foundDestination = true; + } + break; + case TOPIC_TYPE: + if (destination instanceof Topic) { + messageCount = destination.getMessageStore().getMessageCount(); + foundDestination = true; + } + break; + default: + // Should never see this + log.error("Type didn't match: {}", destination.getClass().getName()); + } + } + if (foundDestination) { + break; + } + } + + if (!foundDestination) { + log.warn("Didn't find destination {} in broker {}", fullDestinationName, getBrokerName()); + } + + return messageCount; + } + + private PolicyEntry getDefaultPolicyEntry() { + PolicyMap destinationPolicy = brokerService.getDestinationPolicy(); + if (null == destinationPolicy) { + destinationPolicy = new PolicyMap(); + brokerService.setDestinationPolicy(destinationPolicy); + } + + PolicyEntry defaultEntry = destinationPolicy.getDefaultEntry(); + if (null == defaultEntry) { + defaultEntry = new PolicyEntry(); + destinationPolicy.setDefaultEntry(defaultEntry); + } + + return defaultEntry; + } +} http://git-wip-us.apache.org/repos/asf/activemq/blob/da3b1380/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerConfigTest.java ---------------------------------------------------------------------- diff --git a/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerConfigTest.java b/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerConfigTest.java new file mode 100644 index 0000000..6d384f0 --- /dev/null +++ b/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerConfigTest.java @@ -0,0 +1,110 @@ +/* + * 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.activemq.junit; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Verify the get/set operations are working properly + */ +public class EmbeddedActiveMQBrokerConfigTest { + + // Don't use @Rule in this case - just testing getters/setters + EmbeddedActiveMQBroker instance; + + @Before + public void setUp() throws Exception { + instance = new EmbeddedActiveMQBroker(); + } + + @Test + public void testGetVmURL() throws Exception { + assertEquals( "Default VM URL in incorrect", "failover:(vm://embedded-broker?create=false)", instance.getVmURL()); + } + + @Test + public void testGetBrokerName() throws Exception { + assertEquals( "Default Broker Name in incorrect", "embedded-broker", instance.getBrokerName()); + } + + @Test + public void testBrokerNameConfig() throws Exception { + String dummyName = "test-broker-name"; + + instance.setBrokerName( dummyName); + + assertEquals( "Broker Name not set correctly", dummyName, instance.getBrokerName()); + } + + @Test + public void testStatisticsPluginConfig() throws Exception { + assertFalse( "Statistics plugin should not be enabled by default", instance.isStatisticsPluginEnabled()); + instance.enableStatisticsPlugin(); + assertTrue( "Statistics plugin not enabled", instance.isStatisticsPluginEnabled()); + instance.disableStatisticsPlugin(); + assertFalse( "Statistics plugin not disabled", instance.isStatisticsPluginEnabled()); + } + + @Test + public void testAdvisoryForDeliveryConfig() throws Exception { + assertFalse( "Advisory messages for delivery should not be enabled by default", instance.isAdvisoryForDeliveryEnabled()); + instance.enableAdvisoryForDelivery(); + assertTrue( "Advisory messages for delivery not enabled", instance.isAdvisoryForDeliveryEnabled()); + instance.disableAdvisoryForDelivery(); + assertFalse( "Advisory messages for delivery not disabled", instance.isAdvisoryForDeliveryEnabled()); + } + + @Test + public void testAdvisoryForConsumedConfig() throws Exception { + assertFalse( "Advisory messages for consumed should not be enabled by default", instance.isAdvisoryForConsumedEnabled()); + instance.enableAdvisoryForConsumed(); + assertTrue( "Advisory messages for consumed not enabled", instance.isAdvisoryForConsumedEnabled()); + instance.disableAdvisoryForConsumed(); + assertFalse( "Advisory messages for consumed not disabled", instance.isAdvisoryForConsumedEnabled()); + } + + @Test + public void testAdvisoryForDiscardingMessagesConfig() throws Exception { + assertFalse( "Advisory messages for discarding messages should not be enabled by default", instance.isAdvisoryForDiscardingMessagesEnabled()); + instance.enableAdvisoryForDiscardingMessages(); + assertTrue( "Advisory messages for discarding messages not enabled", instance.isAdvisoryForDiscardingMessagesEnabled()); + instance.disableAdvisoryForDiscardingMessages(); + assertFalse( "Advisory messages for discarding messages not disabled", instance.isAdvisoryForDiscardingMessagesEnabled()); + } + + @Test + public void testAdvisoryForFastProducersConfig() throws Exception { + assertFalse( "Advisory messages for fast producers should not be enabled by default", instance.isAdvisoryForFastProducersEnabled()); + instance.enableAdvisoryForFastProducers(); + assertTrue( "Advisory messages for fast producers not enabled", instance.isAdvisoryForFastProducersEnabled()); + instance.disableAdvisoryForFastProducers(); + assertFalse( "Advisory messages for fast producers not disabled", instance.isAdvisoryForFastProducersEnabled()); + } + + @Test + public void testAdvisoryForSlowConsumersConfig() throws Exception { + assertFalse( "Advisory messages for slow consumers should not be enabled by default", instance.isAdvisoryForSlowConsumersEnabled()); + instance.enableAdvisoryForSlowConsumers(); + assertTrue( "Advisory messages for slow consumers not enabled", instance.isAdvisoryForSlowConsumersEnabled()); + instance.disableAdvisoryForSlowConsumers(); + assertFalse( "Advisory messages for slow consumers not disabled", instance.isAdvisoryForSlowConsumersEnabled()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq/blob/da3b1380/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerRuleTest.java ---------------------------------------------------------------------- diff --git a/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerRuleTest.java b/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerRuleTest.java new file mode 100644 index 0000000..24a3ecb --- /dev/null +++ b/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerRuleTest.java @@ -0,0 +1,43 @@ +/* + * 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.activemq.junit; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import static org.junit.Assert.*; + +public class EmbeddedActiveMQBrokerRuleTest { + @Rule + public EmbeddedActiveMQBroker broker = new EmbeddedActiveMQBroker(); + + @Before + public void setUp() throws Exception { + assertTrue( "Broker should be started", broker.brokerService.isStarted()); + } + + @After + public void tearDown() throws Exception { + assertTrue( "Broker should still be running", broker.brokerService.isStarted()); + } + + @Test + public void testStart() throws Exception { + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq/blob/da3b1380/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerXbeanUriConfigTest.java ---------------------------------------------------------------------- diff --git a/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerXbeanUriConfigTest.java b/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerXbeanUriConfigTest.java new file mode 100644 index 0000000..db4cdd0 --- /dev/null +++ b/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/EmbeddedActiveMQBrokerXbeanUriConfigTest.java @@ -0,0 +1,108 @@ +/* + * 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.activemq.junit; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Verify the xbean configuration URI is working properly + */ +public class EmbeddedActiveMQBrokerXbeanUriConfigTest { + + @Rule + public EmbeddedActiveMQBroker instance = new EmbeddedActiveMQBroker( "xbean:activemq-simple.xml"); + + @Test + public void testGetVmURL() throws Exception { + assertEquals( "Default VM URL in incorrect", "failover:(vm://embedded-broker?create=false)", instance.getVmURL()); + } + + @Test + public void testGetBrokerName() throws Exception { + assertEquals( "Default Broker Name in incorrect", "embedded-broker", instance.getBrokerName()); + } + + @Test + public void testBrokerNameConfig() throws Exception { + String dummyName = "test-broker-name"; + + instance.setBrokerName( dummyName); + + assertEquals( "Broker Name not set correctly", dummyName, instance.getBrokerName()); + } + + @Test + public void testStatisticsPluginConfig() throws Exception { + assertFalse( "Statistics plugin should not be enabled by default", instance.isStatisticsPluginEnabled()); + instance.enableStatisticsPlugin(); + assertTrue( "Statistics plugin not enabled", instance.isStatisticsPluginEnabled()); + instance.disableStatisticsPlugin(); + assertFalse( "Statistics plugin not disabled", instance.isStatisticsPluginEnabled()); + } + + @Test + public void testAdvisoryForDeliveryConfig() throws Exception { + assertFalse( "Advisory messages for delivery should not be enabled by default", instance.isAdvisoryForDeliveryEnabled()); + instance.enableAdvisoryForDelivery(); + assertTrue( "Advisory messages for delivery not enabled", instance.isAdvisoryForDeliveryEnabled()); + instance.disableAdvisoryForDelivery(); + assertFalse( "Advisory messages for delivery not disabled", instance.isAdvisoryForDeliveryEnabled()); + } + + @Test + public void testAdvisoryForConsumedConfig() throws Exception { + assertFalse( "Advisory messages for consumed should not be enabled by default", instance.isAdvisoryForConsumedEnabled()); + instance.enableAdvisoryForConsumed(); + assertTrue( "Advisory messages for consumed not enabled", instance.isAdvisoryForConsumedEnabled()); + instance.disableAdvisoryForConsumed(); + assertFalse( "Advisory messages for consumed not disabled", instance.isAdvisoryForConsumedEnabled()); + } + + @Test + public void testAdvisoryForDiscardingMessagesConfig() throws Exception { + assertFalse( "Advisory messages for discarding messages should not be enabled by default", instance.isAdvisoryForDiscardingMessagesEnabled()); + instance.enableAdvisoryForDiscardingMessages(); + assertTrue( "Advisory messages for discarding messages not enabled", instance.isAdvisoryForDiscardingMessagesEnabled()); + instance.disableAdvisoryForDiscardingMessages(); + assertFalse( "Advisory messages for discarding messages not disabled", instance.isAdvisoryForDiscardingMessagesEnabled()); + } + + @Test + public void testAdvisoryForFastProducersConfig() throws Exception { + assertFalse( "Advisory messages for fast producers should not be enabled by default", instance.isAdvisoryForFastProducersEnabled()); + instance.enableAdvisoryForFastProducers(); + assertTrue( "Advisory messages for fast producers not enabled", instance.isAdvisoryForFastProducersEnabled()); + instance.disableAdvisoryForFastProducers(); + assertFalse( "Advisory messages for fast producers not disabled", instance.isAdvisoryForFastProducersEnabled()); + } + + @Test + public void testAdvisoryForSlowConsumersConfig() throws Exception { + assertFalse( "Advisory messages for slow consumers should not be enabled by default", instance.isAdvisoryForSlowConsumersEnabled()); + instance.enableAdvisoryForSlowConsumers(); + assertTrue( "Advisory messages for slow consumers not enabled", instance.isAdvisoryForSlowConsumersEnabled()); + instance.disableAdvisoryForSlowConsumers(); + assertFalse( "Advisory messages for slow consumers not disabled", instance.isAdvisoryForSlowConsumersEnabled()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq/blob/da3b1380/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/MultipleEmbeddedActiveMQBrokerRuleTest.java ---------------------------------------------------------------------- diff --git a/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/MultipleEmbeddedActiveMQBrokerRuleTest.java b/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/MultipleEmbeddedActiveMQBrokerRuleTest.java new file mode 100644 index 0000000..6804bdb --- /dev/null +++ b/activemq-tooling/activemq-junit/src/test/java/org/apache/activemq/junit/MultipleEmbeddedActiveMQBrokerRuleTest.java @@ -0,0 +1,60 @@ +/* + * 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.activemq.junit; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class MultipleEmbeddedActiveMQBrokerRuleTest { + final String brokerOneName = "broker-one"; + final String brokerTwoName = "broker-two"; + + @Rule + public EmbeddedActiveMQBroker brokerOne = new EmbeddedActiveMQBroker(); + + @Rule + public EmbeddedActiveMQBroker brokerTwo = new EmbeddedActiveMQBroker(); + + public MultipleEmbeddedActiveMQBrokerRuleTest() { + // Perform and broker configuation here before JUnit starts the brokers + brokerOne.setBrokerName( brokerOneName); + brokerTwo.setBrokerName( brokerTwoName); + } + + @Before + public void setUp() throws Exception { + assertTrue( "Broker One should be started", brokerOne.brokerService.isStarted()); + assertTrue( "Broker Two should be started", brokerTwo.brokerService.isStarted()); + } + + @After + public void tearDown() throws Exception { + assertTrue( "Broker One should still be running", brokerOne.brokerService.isStarted()); + assertTrue( "Broker Two should still be running", brokerTwo.brokerService.isStarted()); + } + + @Test + public void testStart() throws Exception { + assertEquals( "Broker One name is incorrect", brokerOneName, brokerOne.getBrokerName()); + assertEquals( "Broker Two name is incorrect", brokerTwoName, brokerTwo.getBrokerName()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq/blob/da3b1380/activemq-tooling/activemq-junit/src/test/resources/activemq-simple.xml ---------------------------------------------------------------------- diff --git a/activemq-tooling/activemq-junit/src/test/resources/activemq-simple.xml b/activemq-tooling/activemq-junit/src/test/resources/activemq-simple.xml new file mode 100644 index 0000000..4c3978f --- /dev/null +++ b/activemq-tooling/activemq-junit/src/test/resources/activemq-simple.xml @@ -0,0 +1,28 @@ + + + + + + + + http://git-wip-us.apache.org/repos/asf/activemq/blob/da3b1380/activemq-tooling/pom.xml ---------------------------------------------------------------------- diff --git a/activemq-tooling/pom.xml b/activemq-tooling/pom.xml index 5449df7..6502b84 100644 --- a/activemq-tooling/pom.xml +++ b/activemq-tooling/pom.xml @@ -34,5 +34,6 @@ activemq-memtest-maven-plugin activemq-perf-maven-plugin activemq-maven-plugin + activemq-junit