/*********************************************************************
* AssistedRemotingTest.java
* created on 23.07.2006 by netseeker
* $Source: /cvsroot/ejoe/EJOE/test/de/netseeker/ejoe/test/remoting/DefaultRemotingTest.java,v $
* $Date: 2007/03/22 21:01:32 $
* $Revision: 1.9 $
*********************************************************************/
package de.netseeker.ejoe.test.remoting;
import java.io.IOException;
import de.netseeker.ejoe.EJClient;
import de.netseeker.ejoe.handler.DefaultRemotingHandler;
import de.netseeker.ejoe.request.RemotingRequest;
import de.netseeker.ejoe.test.BaseClientTest;
import de.netseeker.ejoe.util.ContentStringBuilder;
/**
* @author netseeker
*/
public class DefaultRemotingTest extends BaseClientTest
{
EJClient client;
public DefaultRemotingTest()
{
nonBlockingIO = true;
handler = new DefaultRemotingHandler();
persistent = true;
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.test.BaseTest#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
if ( client == null ) client = getNewClient();
}
public void testAllAccessors()
{
// run three times to get a basic comparism to AssistedRemoting
//for ( int i = 0; i < 100; i++ )
//{
// static method invocation
try
{
Object[] args = new Object[] { "This", " is", " a", " remoting", " test" };
RemotingRequest request = new RemotingRequest( RemoteTestMethods.class.getName(), "buildStaticString",
new Object[] { args } );
Object result = client.execute( request );
assertNotNull( result );
assertEquals( ContentStringBuilder.toString( args ), result );
}
catch ( IOException e )
{
e.printStackTrace();
fail( e.getMessage() );
}
// instance method invocations
try
{
Object[] args = new Object[] { "This", " is", " a", " remoting", " test" };
RemotingRequest request = new RemotingRequest( RemoteTestMethods.class.getName(), "buildString",
new Object[] { args } );
Object result = client.execute( request );
assertNotNull( result );
assertEquals( ContentStringBuilder.toString( args ), result );
Integer sum = Integer.valueOf( 3 );
request = new RemotingRequest( RemoteTestMethods.class.getName(), "add", new Object[] {
Integer.valueOf( 1 ), Integer.valueOf( 2 ) } );
result = client.execute( request );
assertNotNull( result );
assertEquals( sum, result );
request = new RemotingRequest( RemoteTestMethods.class.getName(), "add", new Object[] {
Integer.valueOf( 1 ), Integer.valueOf( 2 ) } );
result = client.execute( request );
assertNotNull( result );
assertEquals( sum, result );
request = new RemotingRequest( RemoteTestMethods.class.getName(), "subtract", new Object[] {
Integer.valueOf( 3 ), Integer.valueOf( 1 ) } );
result = client.execute( request );
assertNotNull( result );
assertEquals( Integer.valueOf( 2 ), result );
}
catch ( IOException e )
{
e.printStackTrace();
fail( e.getMessage() );
}
// default constructor invocation
try
{
RemotingRequest request = new RemotingRequest( RemoteTestMethods.class.getName(), "RemoteTestMethods",
new Object[] {} );
Object result = client.execute( request );
assertNotNull( result );
assertTrue( result instanceof RemoteTestMethods );
}
catch ( IOException e )
{
e.printStackTrace();
fail( e.getMessage() );
}
// parameterized constructor invocation
try
{
RemotingRequest request = new RemotingRequest( RemoteTestMethods.class.getName(), "RemoteTestMethods",
new Object[] { Boolean.TRUE } );
Object result = client.execute( request );
assertNotNull( result );
assertTrue( result instanceof RemoteTestMethods );
request = new RemotingRequest( RemoteTestMethods.class.getName(), "RemoteTestMethods",
new Object[] { Boolean.FALSE } );
result = client.execute( request );
assertNotNull( result );
assertTrue( result instanceof RemoteTestMethods );
request = new RemotingRequest( RemoteTestMethods.class.getName(), "RemoteTestMethods", new Object[] {
Boolean.TRUE, Boolean.FALSE } );
result = client.execute( request );
assertNotNull( result );
assertTrue( result instanceof RemoteTestMethods );
}
catch ( IOException e )
{
e.printStackTrace();
fail( e.getMessage() );
}
}
//}
}