KickJava   Java API By Example, From Geeks To Geeks.

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

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