[jboss-cvs] JBoss Messaging SVN: r4473 - in trunk: tests/src/org/jboss/messaging/tests/unit/core/client/impl and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jun 14 04:50:39 EDT 2008


Author: timfox
Date: 2008-06-14 04:50:39 -0400 (Sat, 14 Jun 2008)
New Revision: 4473

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LocationImplTest.java
Removed:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/config/impl/LocationTest.java
Modified:
   trunk/src/main/org/jboss/messaging/core/client/impl/LocationImpl.java
Log:
Moved and improved location test


Modified: trunk/src/main/org/jboss/messaging/core/client/impl/LocationImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/LocationImpl.java	2008-06-14 08:35:52 UTC (rev 4472)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/LocationImpl.java	2008-06-14 08:50:39 UTC (rev 4473)
@@ -34,8 +34,11 @@
 	private static final long serialVersionUID = -1101852656621257742L;
 	
 	private TransportType transport;
+	
    private String host;
+   
    private int port = ConfigurationImpl.DEFAULT_REMOTING_PORT;
+   
    private int serverID;
    
    public LocationImpl(final int serverID)
@@ -46,10 +49,10 @@
 
    public LocationImpl(final TransportType transport, final String host, final int port)
    {
-      assert host != null;
-      assert port > 0;
       if (transport != TransportType.TCP && transport != TransportType.HTTP)
+      {
          throw new IllegalArgumentException("only HTTP and TCP transports are allowed for remote location");
+      }
       
       this.transport = transport;
       this.host = host;
@@ -64,9 +67,13 @@
    public String getLocation()
    {
       if (transport == TransportType.INVM)
+      {
          return "invm://" + serverID;
+      }
       else
+      {
          return transport +  "://" + host + ":" + port;
+      }
    }
 
    public TransportType getTransport()
@@ -104,13 +111,19 @@
    	Location lother = (Location)other;
    	
    	if (transport != lother.getTransport())
+   	{
    	   return false;
+   	}
    	
    	if (transport == TransportType.INVM)
+   	{
    	   return serverID == lother.getServerID();
+   	}
    	else
+   	{
    	   return this.transport.equals(lother.getTransport()) &&
-   	       this.host.equals(lother.getHost()) &&
-   	       this.port == lother.getPort();
+   	          this.host.equals(lother.getHost()) &&
+   	          this.port == lother.getPort();
+   	}
    }
 }

Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LocationImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LocationImplTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LocationImplTest.java	2008-06-14 08:50:39 UTC (rev 4473)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.messaging.tests.unit.core.client.impl;
+
+import static org.jboss.messaging.core.remoting.TransportType.HTTP;
+import static org.jboss.messaging.core.remoting.TransportType.INVM;
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.Location;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.remoting.TransportType;
+
+/**
+ * 
+ * A LocationImplTest
+ * 
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class LocationImplTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // FIXME - I don't like this weird constructor that's only used for INVM
+   public void testINVMConstructor() throws Exception
+   {
+      final int serverID = 12091;
+      
+      Location location = new LocationImpl(serverID);
+      
+      assertEquals(INVM, location.getTransport());
+      assertEquals(serverID, location.getServerID());
+      assertEquals("invm://" + serverID, location.getLocation());
+   }
+   
+   public void testTransportTypeHostPortConstructor() throws Exception
+   {
+      testTransportTypeHostPortConstructor(TransportType.TCP);
+      testTransportTypeHostPortConstructor(TransportType.HTTP);
+   }
+  
+   public void testTransportTypeHostConstructor() throws Exception
+   {
+      testTransportTypeHostConstructor(TransportType.TCP);
+      testTransportTypeHostConstructor(TransportType.HTTP);
+   }
+     
+   public void testINVMLocationEquality() throws Exception
+   {
+      assertEquals(new LocationImpl(0), new LocationImpl(0));
+      assertNotSame(new LocationImpl(0), new LocationImpl(1));
+      assertNotSame(new LocationImpl(0), new LocationImpl(TCP, "localhost", 9000));
+      assertNotSame(new LocationImpl(0), new LocationImpl(HTTP, "localhost", 9000));
+   }
+
+   public void testTCPLocationEquality() throws Exception
+   {
+      assertEquals(new LocationImpl(TCP, "localhost", 9000), new LocationImpl(TCP, "localhost", 9000));
+      assertEquals(new LocationImpl(HTTP, "localhost", 9000), new LocationImpl(HTTP, "localhost", 9000));
+      assertNotSame(new LocationImpl(TCP, "localhost", 9001), new LocationImpl(TCP, "localhost", 9000));
+      assertNotSame(new LocationImpl(TCP, "anotherhost", 9000), new LocationImpl(TCP, "localhost", 9000));
+      assertNotSame(new LocationImpl(HTTP, "localhost", 9000), new LocationImpl(TCP, "localhost", 9000));
+      assertNotSame(new LocationImpl(HTTP, "localhost", 9000), new LocationImpl(43));
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private void testTransportTypeHostPortConstructor(final TransportType transport) throws Exception
+   {
+      final String host = "uasuas";
+      final int port = 1276718;
+      Location location = new LocationImpl(transport, host, port);
+      assertEquals(transport, location.getTransport());
+      assertEquals(host, location.getHost());
+      assertEquals(port, location.getPort());
+   }
+   
+   private void testTransportTypeHostConstructor(final TransportType transport) throws Exception
+   {
+      final String host = "uasuas";
+      Location location = new LocationImpl(transport, host);
+      assertEquals(transport, location.getTransport());
+      assertEquals(host, location.getHost());
+      assertEquals(ConfigurationImpl.DEFAULT_REMOTING_PORT, location.getPort());
+   }
+   
+   // Inner classes -------------------------------------------------
+}

Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/core/config/impl/LocationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/config/impl/LocationTest.java	2008-06-14 08:35:52 UTC (rev 4472)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/config/impl/LocationTest.java	2008-06-14 08:50:39 UTC (rev 4473)
@@ -1,47 +0,0 @@
-package org.jboss.messaging.tests.unit.core.config.impl;
-
-import static org.jboss.messaging.core.remoting.TransportType.HTTP;
-import static org.jboss.messaging.core.remoting.TransportType.TCP;
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.impl.LocationImpl;
-
-public class LocationTest extends TestCase
-{
-   // Constants -----------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   public void testINVMLocationEquality() throws Exception
-   {
-      assertEquals(new LocationImpl(0), new LocationImpl(0));
-      assertNotSame(new LocationImpl(0), new LocationImpl(1));
-   }
-
-   public void testTCPLocationEquality() throws Exception
-   {
-      assertEquals(new LocationImpl(TCP, "localhost", 9000), new LocationImpl(TCP, "localhost", 9000));
-      assertNotSame(new LocationImpl(TCP, "localhost", 9001), new LocationImpl(TCP, "localhost", 9000));
-      assertNotSame(new LocationImpl(TCP, "anotherhost", 9000), new LocationImpl(TCP, "localhost", 9000));
-      assertNotSame(new LocationImpl(HTTP, "localhost", 9000), new LocationImpl(TCP, "localhost", 9000));
-   }
-
-   public void testTCPAndINVMLocationInequality() throws Exception
-   {
-      assertNotSame(new LocationImpl(0), new LocationImpl(TCP, "localhost", 9000));
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-}




More information about the jboss-cvs-commits mailing list