[jboss-cvs] JBossAS SVN: r100287 - in projects/test/trunk/src/main/java/org/jboss/test: jms and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 2 14:30:04 EST 2010
Author: clebert.suconic at jboss.com
Date: 2010-02-02 14:30:03 -0500 (Tue, 02 Feb 2010)
New Revision: 100287
Added:
projects/test/trunk/src/main/java/org/jboss/test/JBossJMSTestCase.java
projects/test/trunk/src/main/java/org/jboss/test/jms/
projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java
projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java
projects/test/trunk/src/main/java/org/jboss/test/jms/TestRole.java
Log:
Adding JMS abstract queue creation into jboss-test
Added: projects/test/trunk/src/main/java/org/jboss/test/JBossJMSTestCase.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/JBossJMSTestCase.java (rev 0)
+++ projects/test/trunk/src/main/java/org/jboss/test/JBossJMSTestCase.java 2010-02-02 19:30:03 UTC (rev 100287)
@@ -0,0 +1,174 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test;
+
+import org.jboss.test.jms.JMSTestAdmin;
+import org.jboss.test.jms.TestRole;
+import org.jboss.util.NestedRuntimeException;
+
+/**
+ * A Base class with abstraction on creating and deleting JMS destinations.
+ */
+public class JBossJMSTestCase extends JBossTestCase
+{
+ /** JBM provider properties resource name */
+
+
+ /**
+ * Constructor for JMSTestCase object
+ *
+ * @param name
+ * test case name
+ */
+ public JBossJMSTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ protected static Object deployTopic(String name, TestRole[] securityConfig) throws Exception
+ {
+ return JMSTestAdmin.getAdmin().createTopic(name, securityConfig);
+ }
+
+ protected static Object deployQueue(String name, TestRole[] securityConfig) throws Exception
+ {
+ return JMSTestAdmin.getAdmin().createQueue(name, securityConfig);
+ }
+
+ /**
+ * Create the Admin object to perform all JMS adminsitrative functions in a
+ * JMS provider-independent manner
+ */
+ protected void setUp() throws Exception
+ {
+ // perform any setUp required in the superclass
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ protected static void undeployDestinations() throws Exception
+ {
+ JMSTestAdmin.getAdmin().undeployCreatedDestinations();
+ }
+
+
+ protected static void undeployQueue(Object queue) throws Exception
+ {
+ JMSTestAdmin.getAdmin().deleteQueue(queue);
+ }
+
+
+ protected static void undeployTopic(Object topic) throws Exception
+ {
+ JMSTestAdmin.getAdmin().deleteTopic(topic);
+ }
+
+ /**
+ * Historically at jboss, lots of tests will use these destinations since JBoss 3.
+ * This method is a tool to create the basic setting that most tests will use.
+ * @throws Exception
+ */
+ protected static void setupBasicDestinations() throws Exception
+ {
+ deployTopic("securedTopic", null);
+ deployTopic("testDurableTopic", null);
+ deployTopic("testTopic", null);
+
+ deployQueue("testQueue", null);
+ deployQueue("A", null);
+ deployQueue("B", null);
+ deployQueue("C", null);
+ deployQueue("D", null);
+ deployQueue("ex", null);
+ }
+
+
+
+ /**
+ * Create a JMS Queue.
+ *
+ * The Queue is created dynamically, in a JMS provider-specific manner,
+ * according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the Queue to be created.
+ */
+ public Object createQueue(String name) throws Exception
+ {
+ return deployQueue(name, null);
+ }
+
+ /**
+ * Delete a JMS Queue.
+ *
+ * The Queue is deleted dynamically, in a JMS provider-specific manner,
+ * according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the Queue to be deleted.
+ */
+ public void deleteQueue(Object name)
+ {
+ try
+ {
+ undeployQueue(name);
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException("deleteQueue() operation failed", e);
+ }
+ }
+
+ /**
+ * Create a JMS Topic.
+ *
+ * The Topic is created dynamically, in a JMS provider-specific manner,
+ * according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the Topic to be created.
+ */
+ public Object createTopic(String name) throws Exception
+ {
+ return deployTopic(name, null);
+ }
+
+ /**
+ * Delete a JMS Topic.
+ *
+ * The Topic is deleted dynamically, in a JMS provider-specific manner,
+ * according to the instance of the Admin interface currently in use.
+ *
+ * @param name
+ * The name of the Topic to be deleted.
+ */
+ public void deleteTopic(Object name) throws Exception
+ {
+ undeployTopic(name);
+ }
+
+}
Added: projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java (rev 0)
+++ projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java 2010-02-02 19:30:03 UTC (rev 100287)
@@ -0,0 +1,160 @@
+package org.jboss.test.jms;
+
+import java.io.IOException;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.NestedRuntimeException;
+
+public class HornetQTestAdmin extends JMSTestAdmin
+{
+ private final MBeanServerConnection jmx;
+
+ /** The static log */
+ private static final Logger staticLog = Logger.getLogger(HornetQTestAdmin.class);
+
+
+ protected static final ObjectName hornetQJMSServerName;
+
+ static
+ {
+ try
+ {
+ hornetQJMSServerName = new ObjectName("org.hornetq:module=JMS,type=Server");
+ }
+ catch (Exception e)
+ {
+ throw new NestedRuntimeException(e);
+ }
+ }
+
+ public HornetQTestAdmin() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ String adaptorName = System.getProperty("jbosstest.server.name", "jmx/invoker/RMIAdaptor");
+ jmx = (MBeanServerConnection) ctx.lookup(adaptorName);
+ ctx.close();
+ }
+
+ public Object createQueue(String name, TestRole[] securityConfig) throws Exception
+ {
+ return createQueue(name, "/queue/" + name, securityConfig);
+ }
+
+ public Object createQueue(String name, String jndi, TestRole[] securityConfig) throws Exception
+ {
+ jmx.invoke(hornetQJMSServerName, "createQueue", new Object[] { name, jndi }, new String[] { "java.lang.String", "java.lang.String" });
+ deployedQueues.add(name);
+ return name;
+ }
+
+ public Object createTopic(String name, TestRole[] securityConfig) throws Exception
+ {
+ return createTopic(name, "/topic/" + name, securityConfig);
+ }
+
+ public Object createTopic(String name, String jndi, TestRole[] securityConfig) throws Exception
+ {
+ jmx.invoke(hornetQJMSServerName, "createTopic", new Object[] { name, jndi }, new String[] { "java.lang.String", "java.lang.String" });
+ deployedTopics.add(name);
+ return name;
+ }
+
+ public void deleteQueue(Object name) throws Exception
+ {
+ new Exception("Deleting Queue " + name).printStackTrace();
+ try
+ {
+ invokeDeleteQueue(name);
+ deployedQueues.remove(name);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ throw e;
+ }
+ }
+
+ public void deleteTopic(Object name) throws Exception
+ {
+
+ System.out.println("Deleting Topic " + name);
+ try
+ {
+ invokeDeleteTopic(name);
+ deployedTopics.remove(name);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ throw e;
+ }
+ }
+
+ @Override
+ public void undeployCreatedDestinations() throws Exception
+ {
+ for (Object queue : deployedQueues)
+ {
+ invokeDeleteQueue(queue);
+ }
+
+ for (Object topic : deployedTopics)
+ {
+ invokeDeleteTopic(topic);
+ }
+
+ deployedQueues.clear();
+ deployedTopics.clear();
+ }
+
+
+
+ private void invokeDeleteQueue(Object name) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException
+ {
+ jmx.invoke(hornetQJMSServerName, "destroyQueue", new Object[] { name }, new String[] { "java.lang.String" });
+ }
+
+ private void invokeDeleteTopic(Object name) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException
+ {
+ jmx.invoke(hornetQJMSServerName, "destroyTopic", new Object[] { name }, new String[] { "java.lang.String" });
+ }
+
+ @Override
+ public ObjectName createQueueJMXName(String queueName)
+ {
+ try
+ {
+ return new ObjectName("org.hornetq:module=JMS,name=\"" + queueName + "\",type=Queue");
+ }
+ catch (Exception e)
+ {
+ staticLog.warn(e.getMessage(), e);
+ e.printStackTrace(); // >> junit reports
+ return null;
+ }
+ }
+
+ @Override
+ public ObjectName createTopicJMXName(String queueName)
+ {
+ try
+ {
+ return new ObjectName("org.hornetq:module=JMS,name=\"" + queueName + "\",type=Topic");
+ }
+ catch (Exception e)
+ {
+ staticLog.warn(e.getMessage(), e);
+ e.printStackTrace(); // >> junit reports
+ return null;
+ }
+ }
+
+
+}
Added: projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java (rev 0)
+++ projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java 2010-02-02 19:30:03 UTC (rev 100287)
@@ -0,0 +1,67 @@
+package org.jboss.test.jms;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.management.ObjectName;
+
+import org.jboss.util.NestedRuntimeException;
+
+/**
+ *
+ * @author <mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ */
+public abstract class JMSTestAdmin
+{
+
+ protected Set<Object> deployedTopics = new HashSet<Object>();
+ protected Set<Object> deployedQueues = new HashSet<Object>();
+
+ public static JMSTestAdmin admin;
+
+ public static JMSTestAdmin getAdmin()
+ {
+ if (admin == null)
+ {
+ try
+ {
+ // TODO: make this configurable
+ admin = new HornetQTestAdmin();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); // >> junit report
+ throw new NestedRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ return admin;
+ }
+
+
+ /**
+ *
+ * @param name
+ * @param securityConfig
+ * @return information about the deployment required to undeploy/remove the topic
+ * @throws Exception
+ */
+ public abstract Object createTopic(String name, TestRole[] securityConfig) throws Exception;
+
+ public abstract Object createTopic(String name, String jndi, TestRole[] securityConfig) throws Exception;
+
+ public abstract void deleteTopic(Object topic) throws Exception;
+
+ public abstract Object createQueue(String name, TestRole[] securityConfig) throws Exception;
+
+ public abstract Object createQueue(String name, String jndi, TestRole[] securityConfig) throws Exception;
+
+ public abstract void deleteQueue(Object queue) throws Exception;
+
+ public abstract void undeployCreatedDestinations() throws Exception;
+
+ public abstract ObjectName createQueueJMXName(String queueName);
+
+ public abstract ObjectName createTopicJMXName(String queueName);
+}
Added: projects/test/trunk/src/main/java/org/jboss/test/jms/TestRole.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/jms/TestRole.java (rev 0)
+++ projects/test/trunk/src/main/java/org/jboss/test/jms/TestRole.java 2010-02-02 19:30:03 UTC (rev 100287)
@@ -0,0 +1,53 @@
+package org.jboss.test.jms;
+
+public class TestRole
+{
+ private String name;
+
+ private boolean read;
+
+ private boolean write;
+
+ private boolean create;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public boolean isRead()
+ {
+ return read;
+ }
+
+ public void setRead(boolean read)
+ {
+ this.read = read;
+ }
+
+ public boolean isWrite()
+ {
+ return write;
+ }
+
+ public void setWrite(boolean write)
+ {
+ this.write = write;
+ }
+
+ public boolean isCreate()
+ {
+ return create;
+ }
+
+ public void setCreate(boolean create)
+ {
+ this.create = create;
+ }
+
+}
More information about the jboss-cvs-commits
mailing list