[jboss-cvs] JBoss Messaging SVN: r4511 - in trunk: tests/src/org/jboss/messaging/tests/unit/core/remoting and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 18 05:07:24 EDT 2008


Author: ataylor
Date: 2008-06-18 05:07:23 -0400 (Wed, 18 Jun 2008)
New Revision: 4511

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/ConnectorRegistryFactoryTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/DummyConnectorRegistryLocator.java
Modified:
   trunk/src/main/org/jboss/messaging/core/remoting/ConnectorRegistryFactory.java
Log:
new tests

Modified: trunk/src/main/org/jboss/messaging/core/remoting/ConnectorRegistryFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/ConnectorRegistryFactory.java	2008-06-18 08:19:36 UTC (rev 4510)
+++ trunk/src/main/org/jboss/messaging/core/remoting/ConnectorRegistryFactory.java	2008-06-18 09:07:23 UTC (rev 4511)
@@ -22,6 +22,7 @@
 
 package org.jboss.messaging.core.remoting;
 
+import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.impl.ConnectorRegistryImpl;
 
 /**
@@ -32,6 +33,10 @@
 public class ConnectorRegistryFactory implements ConnectorRegistryLocator
 {
    // Constants -----------------------------------------------------
+   private static Logger log = Logger.getLogger(ConnectorRegistryImpl.class);
+
+
+   public static final String CONNECTOR_LOCATOR_PROPERTY = "messaging.connectorlocator.name";
    // Attributes ----------------------------------------------------
 
    // Static --------------------------------------------------------
@@ -54,8 +59,23 @@
    {
       if (REGISTRY_LOCATOR == null)
       {
-         //todo create the locator from another source using sys props, for now just use the default
-         REGISTRY_LOCATOR = new ConnectorRegistryFactory();
+         String locaterClass = System.getProperty(CONNECTOR_LOCATOR_PROPERTY);
+         if(locaterClass != null)
+         {
+            try
+            {
+               REGISTRY_LOCATOR = (ConnectorRegistryLocator) Class.forName(locaterClass).newInstance();
+            }
+            catch (Exception e)
+            {
+               log.warn("unable to create class for Registry Locator, using default", e);
+               REGISTRY_LOCATOR = new ConnectorRegistryFactory();
+            }
+         }
+         else
+         {
+            REGISTRY_LOCATOR = new ConnectorRegistryFactory();
+         }
       }
       return REGISTRY_LOCATOR.locate();
    }

Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/ConnectorRegistryFactoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/ConnectorRegistryFactoryTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/ConnectorRegistryFactoryTest.java	2008-06-18 09:07:23 UTC (rev 4511)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.unit.core.remoting;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.remoting.ConnectorRegistry;
+import org.jboss.messaging.core.remoting.ConnectorRegistryFactory;
+import org.jboss.messaging.core.remoting.ConnectorRegistryLocator;
+import org.jboss.messaging.core.remoting.impl.ConnectorRegistryImpl;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class ConnectorRegistryFactoryTest extends UnitTestCase
+{
+
+   public void testDefaultRegistry()
+   {
+      assertEquals(ConnectorRegistryFactory.getRegistry().getClass(), ConnectorRegistryImpl.class);
+   }
+
+   public void testSetLocator()
+   {
+      try
+      {
+         final ConnectorRegistry connectorRegistry = EasyMock.createNiceMock(ConnectorRegistry.class);
+         ConnectorRegistryFactory.setRegisteryLocator(new ConnectorRegistryLocator()
+         {
+            public ConnectorRegistry locate()
+            {
+               return connectorRegistry;
+            }
+         });
+         assertEquals(ConnectorRegistryFactory.getRegistry(), connectorRegistry);
+      }
+      finally
+      {
+         ConnectorRegistryFactory.setRegisteryLocator(null);
+      }
+   }
+
+   public void testOverrideSystemProperty()
+   {
+      try
+      {
+         System.setProperty(ConnectorRegistryFactory.CONNECTOR_LOCATOR_PROPERTY, DummyConnectorRegistryLocator.class.getName());
+         ConnectorRegistry connectorRegistry = EasyMock.createNiceMock(ConnectorRegistry.class);
+         DummyConnectorRegistryLocator.setConnectorRegistry(connectorRegistry);
+         assertEquals(ConnectorRegistryFactory.getRegistry(), connectorRegistry);
+         assertEquals(ConnectorRegistryFactory.getRegistry().getClass(), DummyConnectorRegistryLocator.getConnectorRegistry().getClass());
+      }
+      finally
+      {
+         System.clearProperty(ConnectorRegistryFactory.CONNECTOR_LOCATOR_PROPERTY);
+         ConnectorRegistryFactory.setRegisteryLocator(null);
+      }
+   }
+
+   public void testOverrideBadSystemProperty()
+   {
+      try
+      {
+         System.setProperty(ConnectorRegistryFactory.CONNECTOR_LOCATOR_PROPERTY, "thisdoesntexist.class");
+         ConnectorRegistry connectorRegistry = EasyMock.createNiceMock(ConnectorRegistry.class);
+         DummyConnectorRegistryLocator.setConnectorRegistry(connectorRegistry);
+         assertEquals(ConnectorRegistryFactory.getRegistry().getClass(), ConnectorRegistryImpl.class);
+      }
+      finally
+      {
+         System.clearProperty(ConnectorRegistryFactory.CONNECTOR_LOCATOR_PROPERTY);
+         ConnectorRegistryFactory.setRegisteryLocator(null);
+      }
+   }
+}

Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/DummyConnectorRegistryLocator.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/DummyConnectorRegistryLocator.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/DummyConnectorRegistryLocator.java	2008-06-18 09:07:23 UTC (rev 4511)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.unit.core.remoting;
+
+import org.jboss.messaging.core.remoting.ConnectorRegistry;
+import org.jboss.messaging.core.remoting.ConnectorRegistryLocator;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class DummyConnectorRegistryLocator implements ConnectorRegistryLocator
+{
+   private static ConnectorRegistry connectorRegistry;
+   public ConnectorRegistry locate()
+   {
+      return connectorRegistry;
+   }
+
+   public static ConnectorRegistry getConnectorRegistry()
+   {
+      return connectorRegistry;
+   }
+
+   public static void setConnectorRegistry(ConnectorRegistry connectorRegistry)
+   {
+      DummyConnectorRegistryLocator.connectorRegistry = connectorRegistry;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list