KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > byvalue > ByValueInvocationTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.remoting.byvalue;
8
9 import junit.framework.TestCase;
10 import org.jboss.remoting.Client;
11 import org.jboss.remoting.InvokerLocator;
12 import org.jboss.remoting.ServerInvocationHandler;
13 import org.jboss.remoting.invocation.NameBasedInvocation;
14 import org.jboss.remoting.transport.Connector;
15 import org.jboss.remoting.transport.mock.MockServerInvocationHandler;
16
17 /**
18  * Just a simple example of how to setup remoting to make an invocation to local target,
19  * so are not actually going out of process, thus not really using any transport protocol.
20  *
21  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
22  */

23 public class ByValueInvocationTestCase extends TestCase
24 {
25    public ByValueInvocationTestCase(String JavaDoc name)
26    {
27       super(name);
28    }
29
30    public static void setupConfiguration(InvokerLocator locator, ServerInvocationHandler invocationHandler) throws Exception JavaDoc
31    {
32       Connector connector = new Connector();
33       connector.setInvokerLocator(locator.getLocatorURI());
34       connector.start();
35       connector.addInvocationHandler("mock", invocationHandler);
36    }
37
38    public void testInvocation() throws Throwable JavaDoc
39    {
40       InvokerLocator locator = new InvokerLocator("rmi://localhost:5400/?" +
41                                                   InvokerLocator.BYVALUE + "=" + Boolean.TRUE.toString());
42       ServerInvocationHandler invocationHandler = new MockServerInvocationHandler();
43
44       // set up
45
ByValueInvocationTestCase.setupConfiguration(locator, invocationHandler);
46
47       Thread.sleep(3000);
48
49       // This could have been new Client(locator), but want to show that subsystem param is null
50
Client remotingClient = new Client(locator, null);
51       ByValuePayload byValuePayload = new ByValuePayload();
52       Object JavaDoc response = remotingClient.invoke(new NameBasedInvocation("testByValue",
53                                                                       new Object JavaDoc[]{byValuePayload},
54                                                                       new String JavaDoc[]{byValuePayload.getClass().getName()}),
55                                               null);
56
57       System.out.println("Invocation response: " + response);
58       if(response instanceof Boolean JavaDoc)
59       {
60          assertTrue("Result of testByValue is false.", ((Boolean JavaDoc) response).booleanValue());
61       }
62       else
63       {
64          assertTrue("Result of testByValue was not even of type Boolean.", false);
65       }
66
67    }
68
69 }
Popular Tags