[jboss-cvs] JBossAS SVN: r100991 - 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
Mon Feb 15 15:48:21 EST 2010


Author: clebert.suconic at jboss.com
Date: 2010-02-15 15:48:21 -0500 (Mon, 15 Feb 2010)
New Revision: 100991

Modified:
   projects/test/trunk/src/main/java/org/jboss/test/JBossJMSTestCase.java
   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:
Integration with HornetQ changes

Modified: projects/test/trunk/src/main/java/org/jboss/test/JBossJMSTestCase.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/JBossJMSTestCase.java	2010-02-15 20:28:41 UTC (rev 100990)
+++ projects/test/trunk/src/main/java/org/jboss/test/JBossJMSTestCase.java	2010-02-15 20:48:21 UTC (rev 100991)
@@ -45,14 +45,14 @@
    }
    
    
-   protected static Object deployTopic(String name, TestRole[] securityConfig) throws Exception
+   protected static void deployTopic(String name, TestRole ... securityConfig) throws Exception
    {
-      return JMSTestAdmin.getAdmin().createTopic(name, securityConfig);
+      JMSTestAdmin.getAdmin().createTopic(name, securityConfig);
    }
 
-   protected static Object deployQueue(String name, TestRole[] securityConfig) throws Exception
+   protected static void deployQueue(String name, TestRole ... securityConfig) throws Exception
    {
-      return JMSTestAdmin.getAdmin().createQueue(name, securityConfig);
+      JMSTestAdmin.getAdmin().createQueue(name, securityConfig);
    }
 
    /**
@@ -76,13 +76,13 @@
    }
 
 
-   protected static void undeployQueue(Object queue) throws Exception
+   protected static void undeployQueue(String queue) throws Exception
    {
       JMSTestAdmin.getAdmin().deleteQueue(queue);
    }
 
 
-   protected static void undeployTopic(Object topic) throws Exception
+   protected static void undeployTopic(String topic) throws Exception
    {
       JMSTestAdmin.getAdmin().deleteTopic(topic);
    }
@@ -94,16 +94,27 @@
     */
    protected static void setupBasicDestinations() throws Exception
    {
-      deployTopic("securedTopic", null);
-      deployTopic("testDurableTopic", null);
-      deployTopic("testTopic", null);
+      deployTopic("securedTopic", new TestRole[]{
+            new TestRole("publisher", true, true, false)});
+      deployTopic("testTopic", new TestRole[]{
+            new TestRole("guest", true, true, true),
+            new TestRole("publisher", true, true, true),
+            new TestRole("durpublisher", true, true, true)});
+      deployTopic("testDurableTopic", new TestRole[]{
+            new TestRole("guest", true, true, true),
+            new TestRole("publisher", true, true, true),
+            new TestRole("durpublisher", true, true, true)});
 
-      deployQueue("testQueue", null);
-      deployQueue("A", null);
-      deployQueue("B", null);
-      deployQueue("C", null);
-      deployQueue("D", null);
-      deployQueue("ex", null);
+      deployQueue("testQueue", new TestRole[]{
+            new TestRole("guest", true, true, true),
+            new TestRole("publisher", true, true, true),
+            new TestRole("durpublisher", true, true, true)});
+      
+      deployQueue("A", new TestRole("guest", true, true, true));
+      deployQueue("B", new TestRole("guest", true, true, true));
+      deployQueue("C", new TestRole("guest", true, true, true));
+      deployQueue("D", new TestRole("guest", true, true, true));
+      deployQueue("ex", new TestRole("guest", true, true, true));
    }
 
 
@@ -117,9 +128,9 @@
     * @param name
     *           The name of the Queue to be created.
     */
-   public Object createQueue(String name) throws Exception
+   public void createQueue(String name) throws Exception
    {
-      return deployQueue(name, null);
+      deployQueue(name, new TestRole("guest", true, true, true));
    }
 
    /**
@@ -131,7 +142,7 @@
     * @param name
     *           The name of the Queue to be deleted.
     */
-   public void deleteQueue(Object name)
+   public void deleteQueue(String name)
    {
       try
       {
@@ -152,9 +163,9 @@
     * @param name
     *           The name of the Topic to be created.
     */
-   public Object createTopic(String name) throws Exception
+   public void createTopic(String name) throws Exception
    {
-      return deployTopic(name, null);
+      deployTopic(name, null);
    }
 
    /**
@@ -166,7 +177,7 @@
     * @param name
     *           The name of the Topic to be deleted.
     */
-   public void deleteTopic(Object name) throws Exception
+   public void deleteTopic(String name) throws Exception
    {
       undeployTopic(name);
    }

Modified: projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java	2010-02-15 20:28:41 UTC (rev 100990)
+++ projects/test/trunk/src/main/java/org/jboss/test/jms/HornetQTestAdmin.java	2010-02-15 20:48:21 UTC (rev 100991)
@@ -1,10 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jms;
 
 import java.io.IOException;
+import java.util.Map;
 
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanException;
 import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.management.ReflectionException;
 import javax.naming.InitialContext;
@@ -12,14 +36,18 @@
 import org.jboss.logging.Logger;
 import org.jboss.util.NestedRuntimeException;
 
+/**
+ * 
+ * @author <mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * 
+ */
 public class HornetQTestAdmin extends JMSTestAdmin
 {
    private final MBeanServerConnection jmx;
-   
+
    /** The static log */
-   private static final Logger staticLog = Logger.getLogger(HornetQTestAdmin.class); 
+   private static final Logger staticLog = Logger.getLogger(HornetQTestAdmin.class);
 
-
    protected static final ObjectName hornetQJMSServerName;
 
    static
@@ -27,9 +55,9 @@
       try
       {
          hornetQJMSServerName = new ObjectName("org.hornetq:module=JMS,type=Server");
-      }
-      catch (Exception e)
+      } catch (Throwable e)
       {
+         staticLog.warn("Error initializing JMX Name", e);
          throw new NestedRuntimeException(e);
       }
    }
@@ -42,57 +70,132 @@
       ctx.close();
    }
 
-   public Object createQueue(String name, TestRole[] securityConfig) throws Exception
+   public void createQueue(String name, TestRole... securityConfig) throws Exception
    {
-      return createQueue(name, "/queue/" + name, securityConfig);
+      createQueue(name, "/queue/" + name, securityConfig);
    }
 
-   public Object createQueue(String name, String jndi, TestRole[] securityConfig) throws Exception
+   private void addRoles(boolean isTopic, String address, TestRole[] securityConf) throws Exception
    {
-      jmx.invoke(hornetQJMSServerName, "createQueue", new Object[] { name, jndi }, new String[] { "java.lang.String", "java.lang.String" });
-      deployedQueues.add(name);
-      return name;
+
+      if (securityConf == null || securityConf.length == 0)
+      {
+         securityConf = new TestRole[]
+         { new TestRole("guest", true, true, true) };
+         return;
+      }
+
+      ObjectName addressManagerON = createAddressManagerON(isTopic, address);
+      
+      deleteEveryRole(isTopic, address);
+
+      for (TestRole role : securityConf)
+      {
+
+         try
+         {
+            jmx.invoke(addressManagerON, "addRole", new Object[]
+            { role.getName(), role.isSend(), role.isConsume(), role.isCreateDurableQueue(), role.isDeleteDurableQueue(),
+                  role.isCreateNonDurableQueue(), role.isDeleteNonDurableQueue(), role.isManage() }, new String[]
+            { "java.lang.String", "boolean", "boolean", "boolean", "boolean", "boolean", "boolean", "boolean" });
+         } catch (Exception ignored)
+         {
+         }
+      }
    }
 
-   public Object createTopic(String name, TestRole[] securityConfig) throws Exception
+   private void deleteEveryRole(boolean isTopic, String address) throws Exception
    {
-      return createTopic(name, "/topic/" + name, securityConfig);
+      ObjectName addressManagerON = createAddressManagerON(isTopic, address);
+
+      Object roles[] = (Object[]) jmx.getAttribute(addressManagerON, "Roles");
+
+      for (Object role : roles)
+      {
+         Object roleArray[] = (Object[]) role;
+         jmx.invoke(addressManagerON, "removeRole", new Object[]
+         { roleArray[0].toString() }, new String[]
+         { "java.lang.String" });
+      }
    }
 
-   public Object createTopic(String name, String jndi, TestRole[] securityConfig) throws Exception
+   private void resetRoles(boolean isTopic, String address) throws Exception
    {
-      jmx.invoke(hornetQJMSServerName, "createTopic", new Object[] { name, jndi }, new String[] { "java.lang.String", "java.lang.String" });
-      deployedTopics.add(name);
-      return name;
+      ObjectName addressManagerON = createAddressManagerON(isTopic, address);
+
+      jmx.invoke(addressManagerON, "resetSecurity", new Object[]
+      {}, new String[]
+      {});
+
    }
 
-   public void deleteQueue(Object name) throws Exception
+   /**
+    * @param address
+    * @return
+    * @throws MalformedObjectNameException
+    */
+   private ObjectName createAddressManagerON(boolean isTopic, String address) throws MalformedObjectNameException
    {
-      new Exception("Deleting Queue " + name).printStackTrace();
+      if (isTopic)
+      {
+         return new ObjectName("org.hornetq:module=Core,name=\"jms.topic." + address + "\",type=Address");
+      } else
+      {
+         return new ObjectName("org.hornetq:module=Core,name=\"jms.queue." + address + "\",type=Address");
+      }
+   }
+
+   public void 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" });
+
+      addRoles(false, name, securityConfig);
+
+      deployedQueues.put(name, securityConfig);
+   }
+
+   public void createTopic(String name, TestRole... securityConfig) throws Exception
+   {
+      createTopic(name, "/topic/" + name, securityConfig);
+   }
+
+   public void 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" });
+
+      addRoles(true, name, securityConfig);
+
+      deployedTopics.put(name, securityConfig);
+   }
+
+   public void deleteQueue(String name) throws Exception
+   {
       try
       {
+         TestRole[] securityConf = deployedQueues.remove(name);
+         resetRoles(false, name);
          invokeDeleteQueue(name);
-         deployedQueues.remove(name);
-      }
-      catch (Exception e)
+      } catch (Exception e)
       {
-         e.printStackTrace(System.out);
+         staticLog.warn(e.getMessage(), e);
          throw e;
       }
    }
 
-   public void deleteTopic(Object name) throws Exception
+   public void deleteTopic(String name) throws Exception
    {
-
-      System.out.println("Deleting Topic " + name);
       try
       {
+         TestRole[] securityConf = deployedTopics.remove(name);
+         resetRoles(true, name);
          invokeDeleteTopic(name);
-         deployedTopics.remove(name);
-      }
-      catch (Exception e)
+      } catch (Exception e)
       {
-         e.printStackTrace(System.out);
+         staticLog.warn(e.getMessage(), e);
          throw e;
       }
    }
@@ -100,30 +203,46 @@
    @Override
    public void undeployCreatedDestinations() throws Exception
    {
-      for (Object queue : deployedQueues)
+      for (Map.Entry<String, TestRole[]> queue : deployedQueues.entrySet())
       {
-         invokeDeleteQueue(queue);
+         resetRoles(false, queue.getKey());
+         try
+         {
+            invokeDeleteQueue(queue.getKey());
+         } catch (Exception e)
+         {
+            staticLog.warn("Error deleting queue " + queue.getKey(), e);
+         }
       }
 
-      for (Object topic : deployedTopics)
+      for (Map.Entry<String, TestRole[]> topic : deployedTopics.entrySet())
       {
-         invokeDeleteTopic(topic);
+         resetRoles(true, topic.getKey());
+         try
+         {
+            invokeDeleteTopic(topic.getKey());
+         } catch (Exception e)
+         {
+            staticLog.warn("Error deleting topic " + topic.getKey(), e);
+         }
       }
-      
+
       deployedQueues.clear();
       deployedTopics.clear();
    }
 
-   
-
-   private void invokeDeleteQueue(Object name) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException
+   private void invokeDeleteQueue(String name) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException
    {
-      jmx.invoke(hornetQJMSServerName, "destroyQueue", new Object[] { name }, new String[] { "java.lang.String" });
+      jmx.invoke(hornetQJMSServerName, "destroyQueue", new Object[]
+      { name }, new String[]
+      { "java.lang.String" });
    }
 
-   private void invokeDeleteTopic(Object name) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException
+   private void invokeDeleteTopic(String name) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException
    {
-      jmx.invoke(hornetQJMSServerName, "destroyTopic", new Object[] { name }, new String[] { "java.lang.String" });
+      jmx.invoke(hornetQJMSServerName, "destroyTopic", new Object[]
+      { name }, new String[]
+      { "java.lang.String" });
    }
 
    @Override
@@ -132,8 +251,7 @@
       try
       {
          return new ObjectName("org.hornetq:module=JMS,name=\"" + queueName + "\",type=Queue");
-      }
-      catch (Exception e)
+      } catch (Exception e)
       {
          staticLog.warn(e.getMessage(), e);
          e.printStackTrace(); // >> junit reports
@@ -147,8 +265,7 @@
       try
       {
          return new ObjectName("org.hornetq:module=JMS,name=\"" + queueName + "\",type=Topic");
-      }
-      catch (Exception e)
+      } catch (Exception e)
       {
          staticLog.warn(e.getMessage(), e);
          e.printStackTrace(); // >> junit reports
@@ -156,5 +273,4 @@
       }
    }
 
-
 }

Modified: projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java	2010-02-15 20:28:41 UTC (rev 100990)
+++ projects/test/trunk/src/main/java/org/jboss/test/jms/JMSTestAdmin.java	2010-02-15 20:48:21 UTC (rev 100991)
@@ -1,7 +1,29 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.jms;
 
-import java.util.HashSet;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.management.ObjectName;
 
@@ -15,8 +37,8 @@
 public abstract class JMSTestAdmin
 {
 
-   protected Set<Object> deployedTopics = new HashSet<Object>();
-   protected Set<Object> deployedQueues = new HashSet<Object>();
+   protected Map<String, TestRole[]> deployedTopics = new HashMap<String, TestRole[]>();
+   protected Map<String, TestRole[]> deployedQueues = new HashMap<String, TestRole[]>();
 
    public static JMSTestAdmin admin;
    
@@ -47,17 +69,17 @@
 	 * @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 void createTopic(String name, TestRole ... securityConfig) throws Exception;
 
-   public abstract Object createTopic(String name, String jndi, TestRole[] securityConfig) throws Exception;
+   public abstract void createTopic(String name, String jndi, TestRole ... securityConfig) throws Exception;
 
-	public abstract void deleteTopic(Object topic) throws Exception;
+	public abstract void deleteTopic(String topic) throws Exception;
 
-	public abstract Object createQueue(String name, TestRole[] securityConfig) throws Exception;
+	public abstract void createQueue(String name, TestRole ... securityConfig) throws Exception;
 
-   public abstract Object createQueue(String name, String jndi, TestRole[] securityConfig) throws Exception;
+   public abstract void createQueue(String name, String jndi, TestRole ... securityConfig) throws Exception;
 
-   public abstract void deleteQueue(Object queue) throws Exception;
+   public abstract void deleteQueue(String queue) throws Exception;
 	
 	public abstract void undeployCreatedDestinations() throws Exception;
 	

Modified: projects/test/trunk/src/main/java/org/jboss/test/jms/TestRole.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/jms/TestRole.java	2010-02-15 20:28:41 UTC (rev 100990)
+++ projects/test/trunk/src/main/java/org/jboss/test/jms/TestRole.java	2010-02-15 20:48:21 UTC (rev 100991)
@@ -1,53 +1,115 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.jms;
 
+/**
+ * 
+ * @author <mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ */
 public class TestRole
 {
-	private String name;
+   private final String name;
 
-	private boolean read;
+   private final boolean send;
 
-	private boolean write;
+   private final boolean consume;
 
-	private boolean create;
+   private final boolean createDurableQueue;
 
-	public String getName()
-	{
-		return name;
-	}
+   private final boolean deleteDurableQueue;
 
-	public void setName(String name)
-	{
-		this.name = name;
-	}
+   private final boolean createNonDurableQueue;
 
-	public boolean isRead()
-	{
-		return read;
-	}
+   private final boolean deleteNonDurableQueue;
 
-	public void setRead(boolean read)
-	{
-		this.read = read;
-	}
+   private final boolean manage;
 
-	public boolean isWrite()
-	{
-		return write;
-	}
+   public TestRole(String name, boolean send, boolean consume, boolean createDurableQueue, boolean deleteDurableQueue,
+         boolean createNonDurableQueue, boolean deleteNonDurableQueue, boolean manage)
+   {
+      super();
+      this.name = name;
+      this.send = send;
+      this.consume = consume;
+      this.createDurableQueue = createDurableQueue;
+      this.deleteDurableQueue = deleteDurableQueue;
+      this.createNonDurableQueue = createNonDurableQueue;
+      this.deleteNonDurableQueue = deleteNonDurableQueue;
+      this.manage = manage;
+   }
 
-	public void setWrite(boolean write)
-	{
-		this.write = write;
-	}
+   public TestRole(String name, boolean send, boolean consume, boolean create)
+   {
+      super();
+      this.name = name;
+      this.send = send;
+      this.consume = consume;
+      this.createDurableQueue = create;
+      this.deleteDurableQueue = create;
+      this.createNonDurableQueue = create;
+      this.deleteNonDurableQueue = create;
+      this.manage = true;
+   }
 
-	public boolean isCreate()
-	{
-		return create;
-	}
+   public boolean isSend()
+   {
+      return send;
+   }
 
-	public void setCreate(boolean create)
-	{
-		this.create = create;
-	}
+   public boolean isConsume()
+   {
+      return consume;
+   }
 
+   public boolean isCreateDurableQueue()
+   {
+      return createDurableQueue;
+   }
+
+   public boolean isDeleteDurableQueue()
+   {
+      return deleteDurableQueue;
+   }
+
+   public boolean isCreateNonDurableQueue()
+   {
+      return createNonDurableQueue;
+   }
+
+   public boolean isDeleteNonDurableQueue()
+   {
+      return deleteNonDurableQueue;
+   }
+
+   public boolean isManage()
+   {
+      return manage;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
 }




More information about the jboss-cvs-commits mailing list