[jboss-svn-commits] JBL Code SVN: r23164 - labs/jbossesb/workspace/skeagh/testutil/src/main/java/org/jboss/esb/jms.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Sep 29 02:14:16 EDT 2008


Author: beve
Date: 2008-09-29 02:14:16 -0400 (Mon, 29 Sep 2008)
New Revision: 23164

Added:
   labs/jbossesb/workspace/skeagh/testutil/src/main/java/org/jboss/esb/jms/JmsTestProvider.java
Log:
Simple jms helpder which can be used without subclassing.


Added: labs/jbossesb/workspace/skeagh/testutil/src/main/java/org/jboss/esb/jms/JmsTestProvider.java
===================================================================
--- labs/jbossesb/workspace/skeagh/testutil/src/main/java/org/jboss/esb/jms/JmsTestProvider.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/testutil/src/main/java/org/jboss/esb/jms/JmsTestProvider.java	2008-09-29 06:14:16 UTC (rev 23164)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.jms;
+
+import java.io.File;
+import java.util.Properties;
+
+import javax.naming.Context;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
+
+/**
+ * Jms Provider that can be uses in funtional/integration tests.
+ * <p/>
+ * Useage:
+ * <pre>{@code
+ *  private static JmsTestProvider jmsProvider;
+ *
+ *  @BeforeClass
+ *  public static void startProvider() throws Exception
+ *  {
+ *      jmsProvider = new JmsTestProvider();
+ *      jmsProvider.start();
+ *  }
+ *
+ *  @AfterClass
+ *  public static void stopProvider() throws Exception
+ *  {
+ *      jmsProvider.stop();
+ *  }
+ *
+ *  @Test
+ *  public void testSomething()
+ *  {
+ *      ...
+ *  }
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ */
+public class JmsTestProvider
+{
+    /**
+     * Default provider URL.
+     */
+    public static final String DEFAULT_PROVIDER_URL = "tcp://localhost:61717";
+
+    /**
+     * JNDI properties.
+     */
+    private Properties jndiProperties;
+
+    /**
+     * Default JNDI Provider URL.
+     */
+    private String providerUrl = DEFAULT_PROVIDER_URL;
+
+    /**
+     * Jms broker
+     */
+    private BrokerService broker;
+
+    /**
+     * Public constructor.
+     */
+    public JmsTestProvider()
+    {
+        jndiProperties = new Properties();
+        jndiProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getName());
+        jndiProperties.setProperty(Context.PROVIDER_URL, DEFAULT_PROVIDER_URL);
+    }
+
+    /**
+     * Public constructor.
+     *
+     * @param providerUrl Provider URL.
+     */
+    public JmsTestProvider(final String providerUrl)
+    {
+        this();
+        jndiProperties.setProperty(Context.PROVIDER_URL, providerUrl);
+        this.providerUrl = providerUrl;
+    }
+
+    /**
+     * Get the JNDI properties in use by this test runner instance.
+     *
+     * @return The JNDI properties.
+     */
+    public final Properties getJndiProperties()
+    {
+        return (Properties) jndiProperties.clone();
+    }
+
+    /**
+     * Start the JMS Broker
+     *
+     * @throws Exception Error starting the broker.
+     */
+    public final void start() throws Exception
+    {
+        broker = new BrokerService();
+
+        // configure the broker
+        broker.setDataDirectory(new File("./target/activeMQData"));
+        broker.addConnector(providerUrl);
+
+        broker.start();
+
+    }
+
+    /**
+     * Stop the JMS Broker
+     *
+     * @throws Exception Error stopping the broker.
+     */
+    public final void stop() throws Exception
+    {
+        if (broker !=null)
+        {
+            broker.stop();
+        }
+    }
+
+}




More information about the jboss-svn-commits mailing list