KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > transport > socket > ssl > custom > InvokerClientTest


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.transport.socket.ssl.custom;
8
9 import java.rmi.server.UID JavaDoc;
10 import org.jboss.logging.Logger;
11 import org.jboss.remoting.Client;
12 import org.jboss.remoting.InvokerLocator;
13 import org.jboss.remoting.invocation.NameBasedInvocation;
14 import org.jboss.test.remoting.transport.socket.ssl.SSLInvokerConstants;
15
16 import junit.framework.TestCase;
17
18
19 /**
20  * This is the actual concrete test for the invoker client. Uses socket transport by default.
21  *
22  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
23  */

24 public class InvokerClientTest extends TestCase implements SSLInvokerConstants
25 {
26    private static final Logger log = Logger.getLogger(InvokerClientTest.class);
27
28    private String JavaDoc sessionId = new UID JavaDoc().toString();
29
30    private Client client;
31
32    public void init()
33    {
34       try
35       {
36          // since doing basic (using default ssl server socket factory)
37
// need to set the system properties to the truststore
38
String JavaDoc trustStoreFilePath = this.getClass().getResource("../.truststore").getFile();
39          System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
40
41          InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port);
42          client = new Client(locator, "mock");
43          client.connect();
44       }
45       catch(Exception JavaDoc e)
46       {
47          log.error(e.getMessage(), e);
48       }
49    }
50
51    public void testRemoteCall() throws Throwable JavaDoc
52    {
53       log.debug("running testRemoteCall()");
54
55       log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
56
57       // simple invoke, should return bar
58
Object JavaDoc ret = makeInvocation("foo", "bar");
59       assertTrue("Result of testRemoteCall() invocation of foo.", "bar".equals(ret));
60       if("bar".equals(ret))
61       {
62          log.debug("PASS");
63       }
64       else
65       {
66          log.debug("FAILED");
67       }
68       assertEquals("bar", ret);
69
70    }
71
72    private Object JavaDoc makeInvocation(String JavaDoc method, String JavaDoc param) throws Throwable JavaDoc
73    {
74       Object JavaDoc ret = client.invoke(new NameBasedInvocation(method,
75                                                          new Object JavaDoc[]{param},
76                                                          new String JavaDoc[]{String JavaDoc.class.getName()}),
77                                  null);
78
79       return ret;
80    }
81
82    public void setUp() throws Exception JavaDoc
83    {
84       init();
85    }
86
87    public void tearDown() throws Exception JavaDoc
88    {
89       if(client != null)
90       {
91          client.disconnect();
92          client = null;
93       }
94    }
95
96
97 }
98
Popular Tags