KickJava   Java API By Example, From Geeks To Geeks.

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

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