commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r345666 - in /jakarta/commons/sandbox/proxy/trunk/src: java/org/apache/commons/proxy/provider/RmiProvider.java test/org/apache/commons/proxy/provider/TestRmiProvider.java
Date Sat, 19 Nov 2005 18:39:49 GMT
Author: jcarman
Date: Sat Nov 19 10:39:45 2005
New Revision: 345666

URL: http://svn.apache.org/viewcvs?rev=345666&view=rev
Log:
Improving test coverage.

Modified:
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/RmiProvider.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestRmiProvider.java

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/RmiProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/RmiProvider.java?rev=345666&r1=345665&r2=345666&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/RmiProvider.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/RmiProvider.java
Sat Nov 19 10:39:45 2005
@@ -41,7 +41,7 @@
     private String host = "localhost";
     private int port = Registry.REGISTRY_PORT;
     private RMIClientSocketFactory clientSocketFactory;
-    private final String name;
+    private String name;
 
 //----------------------------------------------------------------------------------------------------------------------
 // Constructors
@@ -49,28 +49,28 @@
 
     public RmiProvider( String name )
     {
-        this.name = name;
+        setName( name );
     }
 
     public RmiProvider( String host, String name )
     {
-        this.host = host;
-        this.name = name;
+        setHost( host );
+        setName( name );
     }
 
     public RmiProvider( String host, int port, String name )
     {
-        this.host = host;
-        this.name = name;
-        this.port = port;
+        setHost( host );
+        setName( name );
+        setPort( port );
     }
 
     public RmiProvider( String host, int port, RMIClientSocketFactory clientSocketFactory,
String name )
     {
-        this.host = host;
-        this.port = port;
-        this.clientSocketFactory = clientSocketFactory;
-        this.name = name;
+        setHost( host );
+        setPort( port );
+        setClientSocketFactory( clientSocketFactory );
+        setName( name );
     }
 
 //----------------------------------------------------------------------------------------------------------------------
@@ -104,6 +104,11 @@
 //----------------------------------------------------------------------------------------------------------------------
 // Getter/Setter Methods
 //----------------------------------------------------------------------------------------------------------------------
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
 
     public void setClientSocketFactory( RMIClientSocketFactory clientSocketFactory )
     {

Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestRmiProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestRmiProvider.java?rev=345666&r1=345665&r2=345666&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestRmiProvider.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestRmiProvider.java
Sat Nov 19 10:39:45 2005
@@ -18,20 +18,71 @@
 import junit.framework.TestCase;
 import org.apache.commons.proxy.util.rmi.RmiEcho;
 import org.apache.commons.proxy.util.rmi.RmiEchoImpl;
+import org.apache.commons.proxy.exception.ObjectProviderException;
 
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
+import java.rmi.server.RMISocketFactory;
+import java.rmi.server.UnicastRemoteObject;
 
 public class TestRmiProvider extends TestCase
 {
-    RmiProvider rmiProvider;
+    private RmiEchoImpl implObject;
+    private Registry registry;
+
+    public void setUp() throws Exception
+    {
+        implObject = new RmiEchoImpl();
+        registry = LocateRegistry.createRegistry( Registry.REGISTRY_PORT );
+        registry.bind( "echo", implObject );
+    }
+
+    public void tearDown() throws Exception
+    {
+        registry.unbind( "echo" );
+        UnicastRemoteObject.unexportObject( implObject, true );
+        UnicastRemoteObject.unexportObject( registry, true );
+    }
 
     public void testGetObject() throws Exception
     {
-        final Registry registry = LocateRegistry.createRegistry( Registry.REGISTRY_PORT );
-        registry.bind( "echo", new RmiEchoImpl() );
         final RmiProvider provider = new RmiProvider( "echo" );
-        final RmiEcho echo = ( RmiEcho )provider.getObject();
+        final RmiEcho echo = ( RmiEcho ) provider.getObject();
+        assertEquals( "Hello, World!", echo.echoBack( "Hello, World!" ) );
+    }
+
+    public void testGetObjectWithInvalidName()
+    {
+        final RmiProvider provider = new RmiProvider( "bogus" );
+        try
+        {
+            final RmiEcho echo = ( RmiEcho ) provider.getObject();
+            fail();
+        }
+        catch( ObjectProviderException e )
+        {
+        }
+    }
+
+    public void testGetObjectWithHost() throws Exception
+    {
+        final RmiProvider provider = new RmiProvider( "localhost", "echo" );
+        final RmiEcho echo = ( RmiEcho ) provider.getObject();
+        assertEquals( "Hello, World!", echo.echoBack( "Hello, World!" ) );
+    }
+
+    public void testGetObjectWithPortAndHost() throws Exception
+    {
+        final RmiProvider provider = new RmiProvider( "localhost", Registry.REGISTRY_PORT,
"echo" );
+        final RmiEcho echo = ( RmiEcho ) provider.getObject();
+        assertEquals( "Hello, World!", echo.echoBack( "Hello, World!" ) );
+    }
+
+    public void testGetObjectWithPortAndHostAndFactory() throws Exception
+    {
+        final RmiProvider provider = new RmiProvider( "localhost", Registry.REGISTRY_PORT,
+                                                      RMISocketFactory.getDefaultSocketFactory(),
"echo" );
+        final RmiEcho echo = ( RmiEcho ) provider.getObject();
         assertEquals( "Hello, World!", echo.echoBack( "Hello, World!" ) );
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message