activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [05/52] [abbrv] [partial] activemq-artemis git commit: ARTEMIS-127 Adding activemq unit test module to Artemis
Date Tue, 09 Jun 2015 16:36:36 GMT
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/console/command/PurgeCommandTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/console/command/PurgeCommandTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/console/command/PurgeCommandTest.java
new file mode 100644
index 0000000..57fffa0
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/console/command/PurgeCommandTest.java
@@ -0,0 +1,464 @@
+/**
+ * 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.console.command;
+
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.QueueConnection;
+import javax.jms.QueueRequestor;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.QueueViewMBean;
+import org.apache.activemq.console.CommandContext;
+import org.apache.activemq.console.formatter.CommandShellOutputFormatter;
+import org.apache.activemq.console.util.JmxMBeansUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class PurgeCommandTest extends TestCase {
+    private static final Logger LOG = LoggerFactory
+            .getLogger(PurgeCommandTest.class);
+
+    protected static final int MESSAGE_COUNT = 10;
+    protected static final String PROPERTY_NAME = "XTestProperty";
+    protected static final String PROPERTY_VALUE = "1:1";
+
+    // check for existence of property
+    protected static final String MSG_SEL_WITH_PROPERTY = PROPERTY_NAME
+            + " is not null";
+
+    // check for non-existence of property
+    protected static final String MSG_SEL_WITHOUT_PROPERTY = PROPERTY_NAME
+            + " is null";
+
+    // complex message selector query using XTestProperty and JMSPriority
+    protected static final String MSG_SEL_COMPLEX = PROPERTY_NAME + "='" +
+            "1:1" + "',JMSPriority>3";
+
+    // complex message selector query using XTestProperty AND JMSPriority
+    // but in SQL-92 syntax
+    protected static final String MSG_SEL_COMPLEX_SQL_AND = "(" + PROPERTY_NAME + "='" +
+            "1:1" + "') AND (JMSPriority>3)";
+
+    // complex message selector query using XTestProperty OR JMSPriority
+    // but in SQL-92 syntax
+    protected static final String MSG_SEL_COMPLEX_SQL_OR = "(" + PROPERTY_NAME + "='" +
+            "1:1" + "') OR (JMSPriority>3)";
+
+
+    protected static final String QUEUE_NAME = "org.apache.activemq.network.jms.QueueBridgeTest";
+
+    protected AbstractApplicationContext context;
+    protected QueueConnection localConnection;
+    protected QueueRequestor requestor;
+    protected QueueSession requestServerSession;
+    protected MessageConsumer requestServerConsumer;
+    protected MessageProducer requestServerProducer;
+    protected Queue theQueue;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        context = createApplicationContext();
+
+        createConnections();
+
+        requestServerSession = localConnection.createQueueSession(false,
+                Session.AUTO_ACKNOWLEDGE);
+        theQueue = requestServerSession.createQueue(QUEUE_NAME);
+        requestServerConsumer = requestServerSession.createConsumer(theQueue);
+        requestServerProducer = requestServerSession.createProducer(null);
+
+        QueueSession session = localConnection.createQueueSession(false,
+                Session.AUTO_ACKNOWLEDGE);
+        requestor = new QueueRequestor(session, theQueue);
+    }
+
+    protected void createConnections() throws JMSException {
+        ActiveMQConnectionFactory fac = (ActiveMQConnectionFactory) context
+                .getBean("localFactory");
+        localConnection = fac.createQueueConnection();
+        localConnection.start();
+    }
+
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/activemq/console/command/activemq.xml");
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        localConnection.close();
+        BrokerService broker = (BrokerService) context.getBean("localbroker");
+        broker.stop();
+        broker = (BrokerService) context.getBean("default");
+        broker.stop();
+        super.tearDown();
+    }
+
+    public int getMessageCount(QueueBrowser browser, String prefix) throws JMSException {
+        Enumeration<?> e = browser.getEnumeration();
+        int with = 0;
+        while (e.hasMoreElements()) {
+            Object o = e.nextElement();
+            System.out.println(prefix + o);
+            with++;
+        }
+        return with;
+    }
+
+    public void cleanup() throws JMSException {
+        for (int i = 0; i < MESSAGE_COUNT * 2; i++) {
+            requestServerConsumer.receive();
+        }
+    }
+
+    protected MBeanServerConnection createJmxConnection() throws IOException {
+        return ManagementFactory.getPlatformMBeanServer();
+    }
+
+    @SuppressWarnings("unchecked")
+    public void purgeAllMessages() throws IOException, Exception {
+            List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(
+                    createJmxConnection(), "type=Broker,brokerName=localbroker,destinationType=Queue,destinationName=*");
+            for (ObjectInstance oi : queueList) {
+                ObjectName queueName = oi.getObjectName();
+                LOG.info("Purging all messages in queue: "
+                        + queueName.getKeyProperty("Destination"));
+                createJmxConnection().invoke(queueName, "purge",
+                        new Object[] {}, new String[] {});
+            }
+    }
+
+    public void addMessages() throws IOException, Exception {
+        // first clean out any messages that may exist.
+        purgeAllMessages();
+
+        for (int i = 0; i < MESSAGE_COUNT; i++) {
+            TextMessage msg = requestServerSession
+                    .createTextMessage("test msg: " + i);
+            msg.setStringProperty(PROPERTY_NAME, PROPERTY_VALUE);
+            requestServerProducer.send(theQueue, msg);
+        }
+        for (int i = 0; i < MESSAGE_COUNT; i++) {
+            TextMessage msg = requestServerSession
+                    .createTextMessage("test msg: " + i);
+            requestServerProducer.send(theQueue, msg);
+        }
+
+    }
+
+    public void validateCounts(int expectedWithCount, int expectedWithoutCount,
+            int expectedAllCount) throws JMSException {
+        QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
+                theQueue, MSG_SEL_WITH_PROPERTY);
+        QueueBrowser withoutPropertyBrowser = requestServerSession
+                .createBrowser(theQueue, MSG_SEL_WITHOUT_PROPERTY);
+        QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
+
+        int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
+        int withoutCount = getMessageCount(withoutPropertyBrowser,
+                "withoutProperty ");
+        int allCount = getMessageCount(allBrowser, "allMessages ");
+
+        withPropertyBrowser.close();
+        withoutPropertyBrowser.close();
+        allBrowser.close();
+
+        assertEquals("Expected withCount to be " + expectedWithCount + " was "
+                + withCount, expectedWithCount, withCount);
+        assertEquals("Expected withoutCount to be " + expectedWithoutCount
+                + " was " + withoutCount, expectedWithoutCount, withoutCount);
+        assertEquals("Expected allCount to be " + expectedAllCount + " was "
+                + allCount, expectedAllCount, allCount);
+        LOG.info("withCount = " + withCount + "\n withoutCount = "
+                + withoutCount + "\n allCount = " + allCount + "\n  = " + "\n");
+    }
+
+    /**
+     * This test ensures that the queueViewMbean will work.
+     *
+     * @throws Exception
+     */
+    @SuppressWarnings("unchecked")
+    public void testQueueViewMbean() throws Exception {
+
+        try {
+            addMessages();
+
+            validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
+
+            List<String> tokens = Arrays.asList(new String[] { "*" });
+            for (String token : tokens) {
+                List<ObjectInstance> queueList = JmxMBeansUtil.queryMBeans(
+                        createJmxConnection(), "type=Broker,brokerName=localbroker,destinationType=Queue,destinationName="
+                                + token);
+
+                for (ObjectInstance queue : queueList) {
+                    ObjectName queueName = queue
+                            .getObjectName();
+                    QueueViewMBean proxy = MBeanServerInvocationHandler
+                            .newProxyInstance(createJmxConnection(), queueName,
+                                    QueueViewMBean.class, true);
+                    int removed = proxy
+                            .removeMatchingMessages(MSG_SEL_WITH_PROPERTY);
+                    LOG.info("Removed: " + removed);
+                }
+            }
+
+            validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);
+
+        } finally {
+            purgeAllMessages();
+        }
+    }
+
+    public void testPurgeCommandSimpleSelector() throws Exception {
+        try {
+            PurgeCommand purgeCommand = new PurgeCommand();
+            CommandContext context = new CommandContext();
+
+            context.setFormatter(new CommandShellOutputFormatter(System.out));
+
+            purgeCommand.setCommandContext(context);
+            purgeCommand.setJmxUseLocal(true);
+
+            List<String> tokens = new ArrayList<String>();
+            tokens.add("--msgsel");
+            tokens.add(MSG_SEL_WITH_PROPERTY);
+
+            addMessages();
+            validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
+
+            purgeCommand.execute(tokens);
+
+            validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);
+        } finally {
+            purgeAllMessages();
+        }
+    }
+
+    public void testPurgeCommandComplexSelector() throws Exception {
+        try {
+            PurgeCommand purgeCommand = new PurgeCommand();
+            CommandContext context = new CommandContext();
+
+            context.setFormatter(new CommandShellOutputFormatter(System.out));
+
+            purgeCommand.setCommandContext(context);
+            purgeCommand.setJmxUseLocal(true);
+
+            List<String> tokens = new ArrayList<String>();
+            tokens.add("--msgsel");
+            tokens.add(MSG_SEL_COMPLEX);
+
+            addMessages();
+            validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
+
+            purgeCommand.execute(tokens);
+
+            QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
+                    theQueue, MSG_SEL_COMPLEX);
+            QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
+
+            int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
+            int allCount = getMessageCount(allBrowser, "allMessages ");
+
+            withPropertyBrowser.close();
+            allBrowser.close();
+
+            assertEquals("Expected withCount to be " + "0" + " was "
+                    + withCount, 0, withCount);
+            assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was "
+                    + allCount, MESSAGE_COUNT, allCount);
+            LOG.info("withCount = " + withCount + "\n allCount = " +
+                    allCount + "\n  = " + "\n");
+        } finally {
+            purgeAllMessages();
+        }
+    }
+
+    public void testPurgeCommandComplexSQLSelector_AND() throws Exception {
+        try {
+
+            String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100";
+            String two = "\\*:100";
+            try {
+            if (one.matches(two))
+                LOG.info("String matches.");
+            else
+                LOG.info("string does not match.");
+            } catch (Exception ex) {
+                LOG.error(ex.getMessage());
+            }
+
+            PurgeCommand purgeCommand = new PurgeCommand();
+            CommandContext context = new CommandContext();
+
+            context.setFormatter(new CommandShellOutputFormatter(System.out));
+
+            purgeCommand.setCommandContext(context);
+            purgeCommand.setJmxUseLocal(true);
+
+            List<String> tokens = new ArrayList<String>();
+            tokens.add("--msgsel");
+            tokens.add(MSG_SEL_COMPLEX_SQL_AND);
+
+            addMessages();
+            validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
+
+            purgeCommand.execute(tokens);
+
+            QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
+                    theQueue, MSG_SEL_COMPLEX_SQL_AND);
+            QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
+
+            int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
+            int allCount = getMessageCount(allBrowser, "allMessages ");
+
+            withPropertyBrowser.close();
+            allBrowser.close();
+
+            assertEquals("Expected withCount to be " + "0" + " was "
+                    + withCount, 0, withCount);
+            assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was "
+                    + allCount, MESSAGE_COUNT, allCount);
+            LOG.info("withCount = " + withCount + "\n allCount = " +
+                    allCount + "\n  = " + "\n");
+        } finally {
+            purgeAllMessages();
+        }
+    }
+
+    public void testPurgeCommandComplexSQLSelector_OR() throws Exception {
+        try {
+            PurgeCommand purgeCommand = new PurgeCommand();
+            CommandContext context = new CommandContext();
+
+            context.setFormatter(new CommandShellOutputFormatter(System.out));
+
+            purgeCommand.setCommandContext(context);
+            purgeCommand.setJmxUseLocal(true);
+
+            List<String> tokens = new ArrayList<String>();
+            tokens.add("--msgsel");
+            tokens.add(MSG_SEL_COMPLEX_SQL_OR);
+
+            addMessages();
+            validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
+
+            purgeCommand.execute(tokens);
+
+            QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
+                    theQueue, MSG_SEL_COMPLEX_SQL_OR);
+            QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
+
+            int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
+            int allCount = getMessageCount(allBrowser, "allMessages ");
+
+            withPropertyBrowser.close();
+            allBrowser.close();
+
+            assertEquals("Expected withCount to be 0 but was "
+                    + withCount, 0, withCount);
+            assertEquals("Expected allCount to be 0 but was "
+                    + allCount, 0, allCount);
+            LOG.info("withCount = " + withCount + "\n allCount = " +
+                    allCount + "\n  = " + "\n");
+        } finally {
+            purgeAllMessages();
+        }
+    }
+
+    public void testDummy() throws Exception {
+        try {
+
+            String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100";
+            String two = "ID*:100";
+            try {
+            if (one.matches(two))
+                LOG.info("String matches.");
+            else
+                LOG.info("string does not match.");
+            } catch (Exception ex) {
+                LOG.error(ex.getMessage());
+            }
+
+            PurgeCommand purgeCommand = new PurgeCommand();
+            CommandContext context = new CommandContext();
+
+            context.setFormatter(new CommandShellOutputFormatter(System.out));
+
+            purgeCommand.setCommandContext(context);
+            purgeCommand.setJmxUseLocal(true);
+
+            List<String> tokens = new ArrayList<String>();
+            tokens.add("--msgsel");
+            tokens.add("(XTestProperty LIKE '1:*') AND (JMSPriority>3)");
+
+            addMessages();
+
+            purgeCommand.execute(tokens);
+
+            /*
+            QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(
+                    theQueue, MSG_SEL_COMPLEX_SQL_AND);
+            QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
+
+            int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
+            int allCount = getMessageCount(allBrowser, "allMessages ");
+
+            withPropertyBrowser.close();
+            allBrowser.close();
+
+            assertEquals("Expected withCount to be " + "0" + " was "
+                    + withCount, 0, withCount);
+            assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was "
+                    + allCount, MESSAGE_COUNT, allCount);
+            LOG.info("withCount = " + withCount + "\n allCount = " +
+                    allCount + "\n  = " + "\n");
+            */
+        } finally {
+            purgeAllMessages();
+        }
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/console/command/activemq.xml
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/console/command/activemq.xml b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/console/command/activemq.xml
new file mode 100644
index 0000000..b2aaf16
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/console/command/activemq.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<!-- START SNIPPET: xbean -->
+<beans
+  xmlns="http://www.springframework.org/schema/beans"
+  xmlns:amq="http://activemq.apache.org/schema/core"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
+
+  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+  <!-- Default configuration -->
+  <broker id="default" useJmx="false" xmlns="http://activemq.apache.org/schema/core">
+
+	<persistenceFactory>
+	  <journalPersistenceAdapterFactory journalLogFiles="2" dataDirectory="target/foo"/>
+	</persistenceFactory>
+
+	<transportConnectors>
+      <transportConnector uri="tcp://localhost:61616" />
+    </transportConnectors>
+
+  </broker>
+
+ <bean id="localbroker" class="org.apache.activemq.broker.BrokerService"
+    init-method="start">
+    <property name="brokerName" value = "localbroker"/>
+    <property name="persistent" value = "false"/>
+    <property name="transportConnectorURIs">
+      <list>
+        <value>tcp://localhost:61234</value>
+      </list>
+      </property>
+  </bean>
+
+  <!-- JMS ConnectionFactory to use local broker -->
+  <bean id="localFactory"
+    class="org.apache.activemq.ActiveMQConnectionFactory">
+    <property name="brokerURL" value="tcp://localhost:61234" />
+  </bean>
+
+  <!-- Example of broker configuration that uses new logging options and dynamic management of logging
+  <broker useJmx="true" xmlns="http://activemq.apache.org/schema/core" persistent="false" deleteAllMessagesOnStartup="true">
+
+    <transportConnectors>
+      <transportConnector uri="tcp://localhost:61616?trace=true&amp;logWriterName=custom&amp;dynamicManagement=true&amp;startLogging=true"/>
+    </transportConnectors>
+
+    <persistenceAdapter>
+      <memoryPersistenceAdapter/>
+    </persistenceAdapter>
+
+  </broker>
+  End of example-->
+
+<!-- Note: the jmxPort=portnumber option on transportConnectors should only be used on clients.
+On brokers, there is a default port (usually 1099) -->
+
+
+</beans>
+<!-- END SNIPPET: xbean -->

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/conversions/AmqpAndMqttTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/conversions/AmqpAndMqttTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/conversions/AmqpAndMqttTest.java
new file mode 100644
index 0000000..3c0f474
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/conversions/AmqpAndMqttTest.java
@@ -0,0 +1,120 @@
+/**
+ * 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.conversions;
+
+import org.apache.activemq.CombinationTestSupport;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.TransportConnector;
+import org.apache.qpid.amqp_1_0.jms.impl.ConnectionFactoryImpl;
+import org.apache.qpid.amqp_1_0.jms.impl.QueueImpl;
+import org.apache.qpid.amqp_1_0.jms.impl.TopicImpl;
+import org.fusesource.mqtt.client.BlockingConnection;
+import org.fusesource.mqtt.client.MQTT;
+import org.fusesource.mqtt.client.QoS;
+
+import javax.jms.*;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+
+/**
+ */
+public class AmqpAndMqttTest extends CombinationTestSupport {
+
+    protected BrokerService broker;
+    private TransportConnector amqpConnector;
+    private TransportConnector mqttConnector;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        broker = createBroker();
+        broker.start();
+        broker.waitUntilStarted();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if( broker!=null ) {
+            broker.stop();
+            broker.waitUntilStopped();
+            broker = null;
+        }
+        super.tearDown();
+    }
+
+    protected BrokerService createBroker() throws Exception {
+        BrokerService broker = new BrokerService();
+        broker.setPersistent(false);
+        amqpConnector = broker.addConnector("amqp://0.0.0.0:0");
+        mqttConnector = broker.addConnector("mqtt://0.0.0.0:0");
+        return broker;
+    }
+
+
+    public void testFromMqttToAmqp() throws Exception {
+        Connection amqp = createAmqpConnection();
+        Session session = amqp.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageConsumer consumer = session.createConsumer(session.createTopic("topic://FOO"));
+
+        final BlockingConnection mqtt = createMQTTConnection().blockingConnection();
+        mqtt.connect();
+        byte[] payload = bytes("Hello World");
+        mqtt.publish("FOO", payload, QoS.AT_LEAST_ONCE, false);
+        mqtt.disconnect();
+
+        Message msg = consumer.receive(1000 * 5);
+        assertNotNull(msg);
+        assertTrue(msg instanceof BytesMessage);
+
+        BytesMessage bmsg = (BytesMessage) msg;
+        byte[] actual = new byte[(int) bmsg.getBodyLength()];
+        bmsg.readBytes(actual);
+        assertTrue(Arrays.equals(actual, payload));
+        amqp.close();
+    }
+
+    private byte[] bytes(String value) {
+        try {
+            return value.getBytes("UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+
+    protected MQTT createMQTTConnection() throws Exception {
+        MQTT mqtt = new MQTT();
+        mqtt.setConnectAttemptsMax(1);
+        mqtt.setReconnectAttemptsMax(0);
+        mqtt.setHost("localhost", mqttConnector.getConnectUri().getPort());
+        return mqtt;
+    }
+
+    public Connection createAmqpConnection() throws Exception {
+        final ConnectionFactoryImpl factory = new ConnectionFactoryImpl("localhost", amqpConnector.getConnectUri().getPort(), "admin", "password");
+        final Connection connection = factory.createConnection();
+        connection.setExceptionListener(new ExceptionListener() {
+            @Override
+            public void onException(JMSException exception) {
+                exception.printStackTrace();
+            }
+        });
+        connection.start();
+        return connection;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/DefaultQueueSender.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/DefaultQueueSender.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/DefaultQueueSender.java
new file mode 100644
index 0000000..98ca666
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/DefaultQueueSender.java
@@ -0,0 +1,111 @@
+/**
+ * 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.
+ */
+
+/**
+ * The SimpleQueueSender class consists only of a main method,
+ * which sends several messages to a queue.
+ *
+ * Run this program in conjunction with SimpleQueueReceiver.
+ * Specify a queue name on the command line when you run the
+ * program.  By default, the program sends one message.  Specify
+ * a number after the queue name to send that number of messages.
+ */
+package org.apache.activemq.demo;
+
+// START SNIPPET: demo
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A simple queue sender which does not use JNDI
+ * 
+ * 
+ */
+public final class DefaultQueueSender {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DefaultQueueSender.class);
+
+    private DefaultQueueSender() {    
+    }
+
+    public static void main(String[] args) {
+
+        String uri = "tcp://localhost:61616";
+        String text = "Hello World!";
+
+        Connection connection = null;
+
+        if (args.length < 1) {
+            printUsage();
+            System.exit(1);
+        }
+
+        int idx = 0;
+        String arg = args[0];
+        if (arg.equals("-uri")) {
+            if (args.length == 1) {
+                printUsage();
+                System.exit(1);
+            }
+            uri = args[1];
+            idx += 2;
+        }
+        String queueName = args[idx];
+        LOG.info("Connecting to: " + uri);
+        LOG.info("Queue name is " + queueName);
+
+        if (++idx < args.length) {
+            text = args[idx];
+        }
+
+        try {
+            ConnectionFactory factory = new ActiveMQConnectionFactory(uri);
+            connection = factory.createConnection();
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Destination destination = session.createQueue(queueName);
+            MessageProducer producer = session.createProducer(destination);
+
+            Message message = session.createTextMessage(text);
+            producer.send(message);
+        } catch (JMSException e) {
+            LOG.info("Exception occurred: " + e.toString());
+        } finally {
+            if (connection != null) {
+                try {
+                    connection.close();
+                } catch (JMSException e) {
+                }
+            }
+        }
+    }
+
+    protected static void printUsage() {
+        System.out.println("Usage: java DefaultQueueSender [-uri <connection-uri>] " + "<queue-name> [<message-body>]");
+    }
+}
+
+// END SNIPPET: demo

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleConsumer.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleConsumer.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleConsumer.java
new file mode 100644
index 0000000..9b515ac
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleConsumer.java
@@ -0,0 +1,130 @@
+/**
+ * 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.
+ */
+
+/**
+ * The SimpleQueueReceiver class consists only of a main method,
+ * which fetches one or more messages from a queue using
+ * synchronous message delivery.  Run this program in conjunction
+ * with SimpleQueueSender.  Specify a queue name on the command
+ * line when you run the program.
+ */
+package org.apache.activemq.demo;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * A simple polymorphic JMS consumer which can work with Queues or Topics which
+ * uses JNDI to lookup the JMS connection factory and destination
+ * 
+ * 
+ */
+public final class SimpleConsumer {
+
+    private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
+        .getLog(SimpleConsumer.class);
+
+    private SimpleConsumer() {
+    }
+
+    /**
+     * @param args the queue used by the example
+     */
+    public static void main(String[] args) {
+        String destinationName = null;
+        Context jndiContext = null;
+        ConnectionFactory connectionFactory = null;
+        Connection connection = null;
+        Session session = null;
+        Destination destination = null;
+        MessageConsumer consumer = null;
+
+        /*
+         * Read destination name from command line and display it.
+         */
+        if (args.length != 1) {
+            LOG.info("Usage: java SimpleConsumer <destination-name>");
+            System.exit(1);
+        }
+        destinationName = args[0];
+        LOG.info("Destination name is " + destinationName);
+
+        /*
+         * Create a JNDI API InitialContext object
+         */
+        try {
+            jndiContext = new InitialContext();
+        } catch (NamingException e) {
+            LOG.info("Could not create JNDI API " + "context: " + e.toString());
+            System.exit(1);
+        }
+
+        /*
+         * Look up connection factory and destination.
+         */
+        try {
+            connectionFactory = (ConnectionFactory)jndiContext.lookup("ConnectionFactory");
+            destination = (Destination)jndiContext.lookup(destinationName);
+        } catch (NamingException e) {
+            LOG.info("JNDI API lookup failed: " + e.toString());
+            System.exit(1);
+        }
+
+        /*
+         * Create connection. Create session from connection; false means
+         * session is not transacted. Create receiver, then start message
+         * delivery. Receive all text messages from destination until a non-text
+         * message is received indicating end of message stream. Close
+         * connection.
+         */
+        try {
+            connection = connectionFactory.createConnection();
+            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            consumer = session.createConsumer(destination);
+            connection.start();
+            while (true) {
+                Message m = consumer.receive(1);
+                if (m != null) {
+                    if (m instanceof TextMessage) {
+                        TextMessage message = (TextMessage)m;
+                        LOG.info("Reading message: " + message.getText());
+                    } else {
+                        break;
+                    }
+                }
+            }
+        } catch (JMSException e) {
+            LOG.info("Exception occurred: " + e);
+        } finally {
+            if (connection != null) {
+                try {
+                    connection.close();
+                } catch (JMSException e) {
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleProducer.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleProducer.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleProducer.java
new file mode 100644
index 0000000..85061c8
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleProducer.java
@@ -0,0 +1,139 @@
+/**
+ * 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.
+ */
+
+/**
+ * The SimpleQueueSender class consists only of a main method,
+ * which sends several messages to a queue.
+ *
+ * Run this program in conjunction with SimpleQueueReceiver.
+ * Specify a queue name on the command line when you run the
+ * program.  By default, the program sends one message.  Specify
+ * a number after the queue name to send that number of messages.
+ */
+package org.apache.activemq.demo;
+
+// START SNIPPET: demo
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A simple polymorphic JMS producer which can work with Queues or Topics which
+ * uses JNDI to lookup the JMS connection factory and destination
+ * 
+ * 
+ */
+public final class SimpleProducer {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleProducer.class);
+
+    private SimpleProducer() {
+    }
+
+    /**
+     * @param args the destination name to send to and optionally, the number of
+     *                messages to send
+     */
+    public static void main(String[] args) {
+        Context jndiContext = null;
+        ConnectionFactory connectionFactory = null;
+        Connection connection = null;
+        Session session = null;
+        Destination destination = null;
+        MessageProducer producer = null;
+        String destinationName = null;
+        final int numMsgs;
+
+        if ((args.length < 1) || (args.length > 2)) {
+            LOG.info("Usage: java SimpleProducer <destination-name> [<number-of-messages>]");
+            System.exit(1);
+        }
+        destinationName = args[0];
+        LOG.info("Destination name is " + destinationName);
+        if (args.length == 2) {
+            numMsgs = (new Integer(args[1])).intValue();
+        } else {
+            numMsgs = 1;
+        }
+
+        /*
+         * Create a JNDI API InitialContext object
+         */
+        try {
+            jndiContext = new InitialContext();
+        } catch (NamingException e) {
+            LOG.info("Could not create JNDI API context: " + e.toString());
+            System.exit(1);
+        }
+
+        /*
+         * Look up connection factory and destination.
+         */
+        try {
+            connectionFactory = (ConnectionFactory)jndiContext.lookup("ConnectionFactory");
+            destination = (Destination)jndiContext.lookup(destinationName);
+        } catch (NamingException e) {
+            LOG.info("JNDI API lookup failed: " + e);
+            System.exit(1);
+        }
+
+        /*
+         * Create connection. Create session from connection; false means
+         * session is not transacted. Create sender and text message. Send
+         * messages, varying text slightly. Send end-of-messages message.
+         * Finally, close connection.
+         */
+        try {
+            connection = connectionFactory.createConnection();
+            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            producer = session.createProducer(destination);
+            TextMessage message = session.createTextMessage();
+            for (int i = 0; i < numMsgs; i++) {
+                message.setText("This is message " + (i + 1));
+                LOG.info("Sending message: " + message.getText());
+                producer.send(message);
+            }
+
+            /*
+             * Send a non-text control message indicating end of messages.
+             */
+            producer.send(session.createMessage());
+        } catch (JMSException e) {
+            LOG.info("Exception occurred: " + e);
+        } finally {
+            if (connection != null) {
+                try {
+                    connection.close();
+                } catch (JMSException e) {
+                }
+            }
+        }
+    }
+}
+
+// END SNIPPET: demo

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleQueueReceiver.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleQueueReceiver.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleQueueReceiver.java
new file mode 100644
index 0000000..791efa1
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleQueueReceiver.java
@@ -0,0 +1,130 @@
+/**
+ * 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.
+ */
+
+/**
+ * The SimpleQueueReceiver class consists only of a main method,
+ * which fetches one or more messages from a queue using
+ * synchronous message delivery.  Run this program in conjunction
+ * with SimpleQueueSender.  Specify a queue name on the command
+ * line when you run the program.
+ */
+package org.apache.activemq.demo;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class SimpleQueueReceiver {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleQueueReceiver.class);
+
+    private SimpleQueueReceiver() {
+    }
+
+    /**
+     * Main method.
+     * 
+     * @param args the queue used by the example
+     */
+    public static void main(String[] args) {
+        String queueName = null;
+        Context jndiContext = null;
+        QueueConnectionFactory queueConnectionFactory = null;
+        QueueConnection queueConnection = null;
+        QueueSession queueSession = null;
+        Queue queue = null;
+        QueueReceiver queueReceiver = null;
+        TextMessage message = null;
+
+        /*
+         * Read queue name from command line and display it.
+         */
+        if (args.length != 1) {
+            LOG.info("Usage: java " + "SimpleQueueReceiver <queue-name>");
+            System.exit(1);
+        }
+        queueName = args[0];
+        LOG.info("Queue name is " + queueName);
+
+        /*
+         * Create a JNDI API InitialContext object if none exists yet.
+         */
+        try {
+            jndiContext = new InitialContext();
+        } catch (NamingException e) {
+            LOG.info("Could not create JNDI API " + "context: " + e.toString());
+            System.exit(1);
+        }
+
+        /*
+         * Look up connection factory and queue. If either does not exist, exit.
+         */
+        try {
+            queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("QueueConnectionFactory");
+            queue = (Queue)jndiContext.lookup(queueName);
+        } catch (NamingException e) {
+            LOG.info("JNDI API lookup failed: " + e.toString());
+            System.exit(1);
+        }
+
+        /*
+         * Create connection. Create session from connection; false means
+         * session is not transacted. Create receiver, then start message
+         * delivery. Receive all text messages from queue until a non-text
+         * message is received indicating end of message stream. Close
+         * connection.
+         */
+        try {
+            queueConnection = queueConnectionFactory.createQueueConnection();
+            queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+            queueReceiver = queueSession.createReceiver(queue);
+            queueConnection.start();
+            while (true) {
+                Message m = queueReceiver.receive(1);
+                if (m != null) {
+                    if (m instanceof TextMessage) {
+                        message = (TextMessage)m;
+                        LOG.info("Reading message: " + message.getText());
+                    } else {
+                        break;
+                    }
+                }
+            }
+        } catch (JMSException e) {
+            LOG.info("Exception occurred: " + e.toString());
+        } finally {
+            if (queueConnection != null) {
+                try {
+                    queueConnection.close();
+                } catch (JMSException e) {
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleQueueSender.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleQueueSender.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleQueueSender.java
new file mode 100644
index 0000000..22ee403
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/demo/SimpleQueueSender.java
@@ -0,0 +1,137 @@
+/**
+ * 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.
+ */
+
+/**
+ * The SimpleQueueSender class consists only of a main method,
+ * which sends several messages to a queue.
+ *
+ * Run this program in conjunction with SimpleQueueReceiver.
+ * Specify a queue name on the command line when you run the
+ * program.  By default, the program sends one message.  Specify
+ * a number after the queue name to send that number of messages.
+ */
+package org.apache.activemq.demo;
+
+// START SNIPPET: demo
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class SimpleQueueSender {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SimpleQueueSender.class);
+
+    private SimpleQueueSender() {
+    }
+
+    /**
+     * Main method.
+     * 
+     * @param args the queue used by the example and, optionally, the number of
+     *                messages to send
+     */
+    public static void main(String[] args) {
+        String queueName = null;
+        Context jndiContext = null;
+        QueueConnectionFactory queueConnectionFactory = null;
+        QueueConnection queueConnection = null;
+        QueueSession queueSession = null;
+        Queue queue = null;
+        QueueSender queueSender = null;
+        TextMessage message = null;
+        final int numMsgs;
+
+        if ((args.length < 1) || (args.length > 2)) {
+            LOG.info("Usage: java SimpleQueueSender " + "<queue-name> [<number-of-messages>]");
+            System.exit(1);
+        }
+        queueName = args[0];
+        LOG.info("Queue name is " + queueName);
+        if (args.length == 2) {
+            numMsgs = (new Integer(args[1])).intValue();
+        } else {
+            numMsgs = 1;
+        }
+
+        /*
+         * Create a JNDI API InitialContext object if none exists yet.
+         */
+        try {
+            jndiContext = new InitialContext();
+        } catch (NamingException e) {
+            LOG.info("Could not create JNDI API context: " + e.toString());
+            System.exit(1);
+        }
+
+        /*
+         * Look up connection factory and queue. If either does not exist, exit.
+         */
+        try {
+            queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("QueueConnectionFactory");
+            queue = (Queue)jndiContext.lookup(queueName);
+        } catch (NamingException e) {
+            LOG.info("JNDI API lookup failed: " + e);
+            System.exit(1);
+        }
+
+        /*
+         * Create connection. Create session from connection; false means
+         * session is not transacted. Create sender and text message. Send
+         * messages, varying text slightly. Send end-of-messages message.
+         * Finally, close connection.
+         */
+        try {
+            queueConnection = queueConnectionFactory.createQueueConnection();
+            queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+            queueSender = queueSession.createSender(queue);
+            message = queueSession.createTextMessage();
+            for (int i = 0; i < numMsgs; i++) {
+                message.setText("This is message " + (i + 1));
+                LOG.info("Sending message: " + message.getText());
+                queueSender.send(message);
+            }
+
+            /*
+             * Send a non-text control message indicating end of messages.
+             */
+            queueSender.send(queueSession.createMessage());
+        } catch (JMSException e) {
+            LOG.info("Exception occurred: " + e.toString());
+        } finally {
+            if (queueConnection != null) {
+                try {
+                    queueConnection.close();
+                } catch (JMSException e) {
+                }
+            }
+        }
+    }
+}
+
+// END SNIPPET: demo

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
new file mode 100644
index 0000000..95af394
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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.filter;
+
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+
+import junit.framework.TestCase;
+
+public class DestinationFilterTest extends TestCase {
+
+	public void testPrefixFilter() throws Exception {
+		DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue(">"));
+		assertTrue("Filter not parsed well: " + filter.getClass(), filter instanceof PrefixDestinationFilter);
+		System.out.println(filter);
+		assertFalse("Filter matched wrong destination type", filter.matches(new ActiveMQTopic(">")));
+	}
+
+	public void testWildcardFilter() throws Exception {
+		DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.*"));
+		assertTrue("Filter not parsed well: " + filter.getClass(), filter instanceof WildcardDestinationFilter);
+		assertFalse("Filter matched wrong destination type", filter.matches(new ActiveMQTopic("A.B")));
+	}
+
+	public void testCompositeFilter() throws Exception {
+		DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.B,B.C"));
+		assertTrue("Filter not parsed well: " + filter.getClass(), filter instanceof CompositeDestinationFilter);
+		assertFalse("Filter matched wrong destination type", filter.matches(new ActiveMQTopic("A.B")));
+	}
+
+    public void testMatchesChild() throws Exception{
+        DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.*.C"));
+        assertFalse("Filter matched wrong destination type", filter.matches(new ActiveMQTopic("A.B")));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.B.C")));
+
+        filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.*"));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.B")));
+        assertFalse("Filter did match", filter.matches(new ActiveMQQueue("A")));
+    }
+
+    public void testMatchesAny() throws Exception{
+        DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.>.>"));
+
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.C")));
+
+        assertFalse("Filter did match", filter.matches(new ActiveMQQueue("B")));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.B")));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A.B.C.D.E.F")));
+        assertTrue("Filter did not match", filter.matches(new ActiveMQQueue("A")));
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapMemoryTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapMemoryTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapMemoryTest.java
new file mode 100644
index 0000000..42edaf4
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapMemoryTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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.filter;
+
+import junit.framework.TestCase;
+import org.apache.activemq.command.ActiveMQDestination;
+import org.apache.activemq.command.ActiveMQTopic;
+
+public class DestinationMapMemoryTest extends TestCase {
+
+    public void testLongDestinationPath() throws Exception {
+        ActiveMQTopic d1 = new ActiveMQTopic("1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18");
+        DestinationMap map = new DestinationMap();
+        map.put(d1, d1);
+    }
+
+    public void testVeryLongestinationPaths() throws Exception {
+
+        for (int i = 1; i < 100; i++) {
+            String name = "1";
+            for (int j = 2; j <= i; j++) {
+                name += "." + j;
+            }
+            // System.out.println("Checking: " + name);
+            try {
+                ActiveMQDestination d1 = createDestination(name);
+                DestinationMap map = new DestinationMap();
+                map.put(d1, d1);
+            } catch (Throwable e) {
+                fail("Destination name too long: " + name + " : " + e);
+            }
+        }
+    }
+
+    protected ActiveMQDestination createDestination(String name) {
+        return new ActiveMQTopic(name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTempDestinationTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTempDestinationTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTempDestinationTest.java
new file mode 100644
index 0000000..21dd60d
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTempDestinationTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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.filter;
+
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.command.ActiveMQTempQueue;
+import org.apache.activemq.command.ConnectionId;
+import org.apache.activemq.util.IdGenerator;
+
+public class DestinationMapTempDestinationTest extends TestCase {
+
+    public void testtestTempDestinations() throws Exception {
+        ConnectionId id = new ConnectionId(new IdGenerator().generateId());
+        DestinationMap map = new DestinationMap();
+        Object value = new Object();
+        int count = 1000;
+        for (int i = 0; i < count; i++) {
+            ActiveMQTempQueue queue = new ActiveMQTempQueue(id, i);
+            map.put(queue, value);
+        }
+        for (int i = 0; i < count; i++) {
+            ActiveMQTempQueue queue = new ActiveMQTempQueue(id, i);
+            map.remove(queue, value);
+            Set<?> set = map.get(queue);
+            assertTrue(set.isEmpty());
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTest.java
new file mode 100644
index 0000000..2f0f92c
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationMapTest.java
@@ -0,0 +1,414 @@
+/**
+ * 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.filter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.activemq.command.ActiveMQDestination;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+import junit.framework.TestCase;
+
+public class DestinationMapTest extends TestCase {
+    protected DestinationMap map = new DestinationMap();
+
+    protected ActiveMQDestination d1 = createDestination("TEST.D1");
+    protected ActiveMQDestination d2 = createDestination("TEST.BAR.D2");
+    protected ActiveMQDestination d3 = createDestination("TEST.BAR.D3");
+    protected ActiveMQDestination compositeDestination1 = createDestination("TEST.D1,TEST.BAR.D2");
+    protected ActiveMQDestination compositeDestination2 = createDestination("TEST.D1,TEST.BAR.D3");
+
+    protected Object v1 = "value1";
+    protected Object v2 = "value2";
+    protected Object v3 = "value3";
+    protected Object v4 = "value4";
+    protected Object v5 = "value5";
+    protected Object v6 = "value6";
+
+    public void testCompositeDestinations() throws Exception {
+        ActiveMQDestination d1 = createDestination("TEST.BAR.D2");
+        ActiveMQDestination d2 = createDestination("TEST.BAR.D3");
+        map.put(d1, d1);
+        map.put(d2, d2);
+        map.get(createDestination("TEST.BAR.D2,TEST.BAR.D3"));
+    }
+
+    public void testSimpleDestinations() throws Exception {
+        map.put(d1, v1);
+        map.put(d2, v2);
+        map.put(d3, v3);
+
+        assertMapValue(d1, v1);
+        assertMapValue(d2, v2);
+        assertMapValue(d3, v3);
+    }
+
+    public void testQueueAndTopicWithSameName() throws Exception {
+        ActiveMQQueue q1 = new ActiveMQQueue("foo");
+        ActiveMQTopic t1 = new ActiveMQTopic("foo");
+
+        map.put(q1, v1);
+        map.put(t1, v2);
+
+        assertMapValue(q1, v1);
+        assertMapValue(t1, v2);
+    }
+
+    public void testSimpleDestinationsWithMultipleValues() throws Exception {
+        map.put(d1, v1);
+        map.put(d2, v2);
+        map.put(d2, v3);
+
+        assertMapValue(d1, v1);
+        assertMapValue("TEST.BAR.D2", v2, v3);
+        assertMapValue(d3, null);
+    }
+
+    public void testSimpleAndCompositeDestinations() throws Exception {
+        map.put(d1, v1);
+        map.put(compositeDestination1, v2);
+        map.put(compositeDestination2, v3);
+
+        assertMapValue("TEST.D1", v1, v2, v3);
+        assertMapValue(d2, v2);
+        assertMapValue(d3, v3);
+        assertMapValue(compositeDestination1.toString(), v1, v2, v3);
+        assertMapValue(compositeDestination2.toString(), v1, v2, v3);
+
+        map.remove(compositeDestination1, v2);
+        map.remove(compositeDestination2, v3);
+
+        assertMapValue("TEST.D1", v1);
+    }
+
+    public void testLookupOneStepWildcardDestinations() throws Exception {
+        map.put(d1, v1);
+        map.put(d2, v2);
+        map.put(d3, v3);
+
+        assertMapValue("TEST.D1", v1);
+        assertMapValue("TEST.*", v1);
+        assertMapValue("*.D1", v1);
+        assertMapValue("*.*", v1);
+
+        assertMapValue("TEST.BAR.D2", v2);
+        assertMapValue("TEST.*.D2", v2);
+        assertMapValue("*.BAR.D2", v2);
+        assertMapValue("*.*.D2", v2);
+
+        assertMapValue("TEST.BAR.D3", v3);
+        assertMapValue("TEST.*.D3", v3);
+        assertMapValue("*.BAR.D3", v3);
+        assertMapValue("*.*.D3", v3);
+
+        assertMapValue("TEST.BAR.D4", null);
+
+        assertMapValue("TEST.BAR.*", v2, v3);
+    }
+
+    public void testLookupMultiStepWildcardDestinations() throws Exception {
+        map.put(d1, v1);
+        map.put(d2, v2);
+        map.put(d3, v3);
+
+        List<Object> allValues = Arrays.asList(new Object[] {v1, v2, v3});
+
+        assertMapValue(">", allValues);
+        assertMapValue("TEST.>", allValues);
+        assertMapValue("*.>", allValues);
+        assertMapValue("TEST.*.>", allValues);
+        assertMapValue("TEST.*.*.>", v2,v3);
+
+        assertMapValue("FOO.>", null);
+    }
+
+    public void testStoreWildcardWithOneStepPath() throws Exception {
+        put("TEST.*", v1);
+        put("TEST.D1", v2);
+        put("TEST.BAR.*", v2);
+        put("TEST.BAR.D3", v3);
+
+        assertMapValue("FOO", null);
+        assertMapValue("TEST.FOO", v1);
+        assertMapValue("TEST.D1", v1, v2);
+
+        assertMapValue("TEST.FOO.FOO", null);
+        assertMapValue("TEST.BAR.FOO", v2);
+        assertMapValue("TEST.BAR.D3", v2, v3);
+
+        assertMapValue("TEST.*", v1, v2);
+        assertMapValue("*.D1", v1, v2);
+        assertMapValue("*.*", v1, v2);
+        assertMapValue("TEST.*.*", v2, v3);
+        assertMapValue("TEST.BAR.*", v2, v3);
+        assertMapValue("*.*.*", v2, v3);
+        assertMapValue("*.BAR.*", v2, v3);
+        assertMapValue("*.BAR.D3", v2, v3);
+        assertMapValue("*.*.D3", v2, v3);
+    }
+
+    public void testStoreWildcardInMiddleOfPath() throws Exception {
+        put("TEST.*", v1);
+        put("TEST.D1", v2);
+        put("TEST.BAR.*", v2);
+        put("TEST.XYZ.D3", v3);
+        put("TEST.XYZ.D4", v4);
+        put("TEST.BAR.D3", v5);
+        put("TEST.*.D2", v6);
+
+        assertMapValue("TEST.*.D3", v2, v3, v5);
+        assertMapValue("TEST.*.D4", v2, v4);
+
+        assertMapValue("TEST.*", v1, v2);
+        assertMapValue("TEST.*.*", v2, v3, v4, v5, v6);
+        assertMapValue("TEST.*.>", v1, v2, v3, v4, v5, v6);
+        assertMapValue("TEST.>", v1, v2, v3, v4, v5, v6);
+        assertMapValue("TEST.>.>", v1, v2, v3, v4, v5, v6);
+        assertMapValue("*.*.D3", v2, v3, v5);
+        assertMapValue("TEST.BAR.*", v2, v5, v6);
+
+        assertMapValue("TEST.BAR.D2", v2, v6);
+        assertMapValue("TEST.*.D2", v2, v6);
+        assertMapValue("TEST.BAR.*", v2, v5, v6);
+    }
+
+    public void testDoubleWildcardDoesNotMatchLongerPattern() throws Exception {
+        put("TEST.*", v1);
+        put("TEST.BAR.D3", v2);
+
+        assertMapValue("*.*.D3", v2);
+    }
+
+    public void testWildcardAtEndOfPathAndAtBeginningOfSearch() throws Exception {
+        put("TEST.*", v1);
+
+        assertMapValue("*.D1", v1);
+    }
+
+    public void testAnyPathWildcardInMap() throws Exception {
+        put("TEST.FOO.>", v1);
+
+        assertMapValue("TEST.FOO.BAR.WHANOT.A.B.C", v1);
+        assertMapValue("TEST.FOO.BAR.WHANOT", v1);
+        assertMapValue("TEST.FOO.BAR", v1);
+
+        assertMapValue("TEST.*.*", v1);
+        assertMapValue("TEST.BAR", null);
+
+        assertMapValue("TEST.FOO", v1);
+    }
+
+    public void testSimpleAddRemove() throws Exception {
+        put("TEST.D1", v2);
+
+        assertEquals("Root child count", 1, map.getTopicRootChildCount());
+
+        assertMapValue("TEST.D1", v2);
+
+        remove("TEST.D1", v2);
+
+        assertEquals("Root child count", 0, map.getTopicRootChildCount());
+        assertMapValue("TEST.D1", null);
+    }
+
+    public void testMQTTMappedWildcards() throws Exception {
+        put("TopicA", v1);
+        put(".TopicA", v2);
+        put("TopicA.", v3);
+        put(".", v4);
+        put("..TopicA", v5);
+        put("..", v6);
+
+        // test wildcard patterns "#", "+", "+/#", "/+", "+/", "+/+", "+/+/", "+/+/+"
+        assertMapValue(">", v1, v2, v3, v4, v5, v6);
+        assertMapValue("*", v1);
+        assertMapValue("*.>", v1, v2, v3, v4, v5, v6);
+        assertMapValue(".*", v2, v4);
+        assertMapValue("*.", v3, v4);
+        assertMapValue("*.*", v2, v3, v4);
+        assertMapValue("*.*.", v6);
+        assertMapValue("*.*.*", v5, v6);
+    }
+
+    public void testStoreAndLookupAllWildcards() throws Exception {
+        loadSample2();
+
+        assertSample2();
+
+        // lets remove everything and add it back
+        remove("TEST.FOO", v1);
+
+        assertMapValue("TEST.FOO", v2, v3, v4);
+        assertMapValue("TEST.*", v2, v3, v4, v6);
+        assertMapValue("*.*", v2, v3, v4, v6);
+
+        remove("TEST.XYZ", v6);
+
+        assertMapValue("TEST.*", v2, v3, v4);
+        assertMapValue("*.*", v2, v3, v4);
+
+        remove("TEST.*", v2);
+
+        assertMapValue("TEST.*", v3, v4);
+        assertMapValue("*.*", v3, v4);
+
+        remove(">", v4);
+
+        assertMapValue("TEST.*", v3);
+        assertMapValue("*.*", v3);
+
+        remove("TEST.>", v3);
+        remove("TEST.FOO.BAR", v5);
+
+        assertMapValue("FOO", null);
+        assertMapValue("TEST.FOO", null);
+        assertMapValue("TEST.D1", null);
+
+        assertMapValue("TEST.FOO.FOO", null);
+        assertMapValue("TEST.BAR.FOO", null);
+        assertMapValue("TEST.FOO.BAR", null);
+        assertMapValue("TEST.BAR.D3", null);
+
+        assertMapValue("TEST.*", null);
+        assertMapValue("*.*", null);
+        assertMapValue("*.D1", null);
+        assertMapValue("TEST.*.*", null);
+        assertMapValue("TEST.BAR.*", null);
+
+        loadSample2();
+
+        assertSample2();
+
+        remove(">", v4);
+        remove("TEST.*", v2);
+
+        assertMapValue("FOO", null);
+        assertMapValue("TEST.FOO", v1, v3);
+        assertMapValue("TEST.D1", v3);
+
+        assertMapValue("TEST.FOO.FOO", v3);
+        assertMapValue("TEST.BAR.FOO", v3);
+        assertMapValue("TEST.FOO.BAR", v3, v5);
+        assertMapValue("TEST.BAR.D3", v3);
+
+        assertMapValue("TEST.*", v1, v3, v6);
+        assertMapValue("*.*", v1, v3, v6);
+        assertMapValue("*.D1", v3);
+        assertMapValue("TEST.*.*", v3, v5);
+        assertMapValue("TEST.BAR.*", v3);
+    }
+
+    public void testAddAndRemove() throws Exception {
+
+        put("FOO.A", v1);
+        assertMapValue("FOO.>", v1);
+
+        put("FOO.B", v2);
+        assertMapValue("FOO.>", v1, v2);
+
+        map.removeAll(createDestination("FOO.A"));
+
+        assertMapValue("FOO.>", v2);
+    }
+
+    protected void loadSample2() {
+        put("TEST.FOO", v1);
+        put("TEST.*", v2);
+        put("TEST.>", v3);
+        put(">", v4);
+        put("TEST.FOO.BAR", v5);
+        put("TEST.XYZ", v6);
+    }
+
+    protected void assertSample2() {
+        assertMapValue("FOO", v4);
+        assertMapValue("TEST.FOO", v1, v2, v3, v4);
+        assertMapValue("TEST.D1", v2, v3, v4);
+
+        assertMapValue("TEST.FOO.FOO", v3, v4);
+        assertMapValue("TEST.BAR.FOO", v3, v4);
+        assertMapValue("TEST.FOO.BAR", v3, v4, v5);
+        assertMapValue("TEST.BAR.D3", v3, v4);
+
+        assertMapValue("TEST.*", v1, v2, v3, v4, v6);
+        assertMapValue("*.*", v1, v2, v3, v4, v6);
+        assertMapValue("*.D1", v2, v3, v4);
+        assertMapValue("TEST.*.*", v3, v4, v5);
+        assertMapValue("TEST.BAR.*", v3, v4);
+    }
+
+    protected void put(String name, Object value) {
+        map.put(createDestination(name), value);
+    }
+
+    protected void remove(String name, Object value) {
+        ActiveMQDestination destination = createDestination(name);
+        map.remove(destination, value);
+    }
+
+    protected void assertMapValue(String destinationName, Object expected) {
+        ActiveMQDestination destination = createDestination(destinationName);
+        assertMapValue(destination, expected);
+    }
+
+    protected void assertMapValue(String destinationName, Object expected1, Object expected2) {
+        assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2}));
+    }
+
+    protected void assertMapValue(String destinationName, Object expected1, Object expected2, Object expected3) {
+        assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2, expected3}));
+    }
+
+    protected void assertMapValue(String destinationName, Object expected1, Object expected2, Object expected3, Object expected4) {
+        assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2, expected3, expected4}));
+    }
+
+    protected void assertMapValue(String destinationName, Object expected1, Object expected2, Object expected3, Object expected4, Object expected5) {
+        assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2, expected3, expected4, expected5}));
+    }
+
+    protected void assertMapValue(String destinationName, Object expected1, Object expected2, Object expected3, Object expected4, Object expected5, Object expected6) {
+        assertMapValue(destinationName, Arrays.asList(new Object[] {expected1, expected2, expected3, expected4, expected5, expected6}));
+    }
+
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    protected void assertMapValue(ActiveMQDestination destination, Object expected) {
+        List expectedList = null;
+        if (expected == null) {
+            expectedList = Collections.EMPTY_LIST;
+        } else if (expected instanceof List) {
+            expectedList = (List)expected;
+        } else {
+            expectedList = new ArrayList();
+            expectedList.add(expected);
+        }
+        Collections.sort(expectedList);
+        Set actualSet = map.get(destination);
+        List actual = new ArrayList(actualSet);
+        Collections.sort(actual);
+        assertEquals("map value for destinationName:  " + destination, expectedList, actual);
+    }
+
+    protected ActiveMQDestination createDestination(String name) {
+        return new ActiveMQTopic(name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationPathTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationPathTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationPathTest.java
new file mode 100644
index 0000000..397ccca
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DestinationPathTest.java
@@ -0,0 +1,36 @@
+/**
+ * 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.filter;
+
+import org.apache.activemq.test.TestSupport;
+
+public class DestinationPathTest extends TestSupport {
+
+    public void testPathParse() {
+        assertParse("FOO", new String[]{"FOO"});
+        assertParse("FOO.BAR", new String[]{"FOO", "BAR"});
+        assertParse("FOO.*", new String[]{"FOO", "*"});
+        assertParse("FOO.>", new String[]{"FOO", ">"});
+        assertParse("FOO.BAR.XYZ", new String[]{"FOO", "BAR", "XYZ"});
+        assertParse("FOO.BAR.", new String[]{"FOO", "BAR", ""});
+    }
+
+    protected void assertParse(String subject, String[] expected) {
+        String[] path = DestinationPath.getDestinationPaths(subject);
+        assertArrayEqual(subject, expected, path);
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicy.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicy.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicy.java
new file mode 100644
index 0000000..3dde44f
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicy.java
@@ -0,0 +1,40 @@
+/**
+ * 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.filter;
+
+import java.util.List;
+
+/**
+ * Represents a destination based policy
+ *
+ *
+ */
+public class DummyPolicy extends DestinationMap {
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Override
+    protected Class getEntryClass() {
+        return DummyPolicyEntry.class;
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Override
+    public void setEntries(List entries) {
+        super.setEntries(entries);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyEntry.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyEntry.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyEntry.java
new file mode 100644
index 0000000..d271580
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyEntry.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      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.filter;
+
+
+/**
+ * 
+ * 
+ */
+public class DummyPolicyEntry extends DestinationMapEntry<String> {
+
+    private String description;
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public Comparable<String> getValue() {
+        return description;
+    }
+
+    protected String getValuePropertyName() {
+        return "description";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyTest.java
new file mode 100644
index 0000000..5d71c54
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/DummyPolicyTest.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      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.filter;
+
+import java.util.Set;
+
+import org.apache.activemq.SpringTestSupport;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ *
+ */
+public class DummyPolicyTest extends SpringTestSupport {
+
+    public void testPolicy() throws Exception {
+        DummyPolicy policy = (DummyPolicy)getBean("policy");
+
+        Set<?> set = policy.get(new ActiveMQTopic("FOO.BAR"));
+
+        assertSetEquals("FOO.BAR set", new Object[] {"Edam", "Cheddar"}, set);
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/activemq/filter/dummyPolicy.xml");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/dummyPolicy.xml
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/dummyPolicy.xml b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/dummyPolicy.xml
new file mode 100644
index 0000000..6585986
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/filter/dummyPolicy.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+   
+    http://www.apache.org/licenses/LICENSE-2.0
+   
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<beans>
+  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+  <bean id="policy" class="org.apache.activemq.filter.DummyPolicy">
+    <property name="entries">
+      <list>
+        <bean class="org.apache.activemq.filter.DummyPolicyEntry">
+          <property name="topic" value="FOO.>" />
+          <property name="description" value="Edam" />
+        </bean>
+        <bean class="org.apache.activemq.filter.DummyPolicyEntry">
+          <property name="topic" value="FOO.BAR" />
+          <property name="description" value="Cheddar" />
+        </bean>
+      </list>
+    </property>
+  </bean>
+
+</beans>


Mime
View raw message