KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > handler > mbean > ClientTest


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.handler.mbean;
8
9 import org.jboss.dtf.MultipleTestRunner;
10 import org.jboss.remoting.AbstractInvokerTest;
11 import org.jboss.remoting.Client;
12 import org.jboss.remoting.InvokerLocator;
13
14 /**
15  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
16  */

17 public class ClientTest extends AbstractInvokerTest
18 {
19    // Default locator values
20
private static String JavaDoc transport = "socket";
21    private static String JavaDoc host = "localhost";
22    private static int port = 5400;
23
24    private String JavaDoc locatorURI = null;
25
26    public ClientTest(String JavaDoc name)
27    {
28       super(name);
29    }
30
31    public ClientTest(String JavaDoc name, String JavaDoc locatorURI)
32    {
33       super(name);
34       this.locatorURI = locatorURI;
35    }
36    public ClientTest(String JavaDoc name, int numberOfInstances)
37    {
38       super(name, numberOfInstances);
39    }
40
41    public ClientTest(String JavaDoc name, String JavaDoc transport, int port)
42    {
43       super(name, transport, port);
44    }
45
46    public ClientTest(String JavaDoc name, String JavaDoc transport, int port, int numberOfInstances)
47    {
48       super(name, transport, port, numberOfInstances);
49    }
50
51    public void testMakeInvocation() throws Throwable JavaDoc
52    {
53       if(locatorURI == null)
54       {
55          locatorURI = transport + "://" + host + ":" + port;
56       }
57       InvokerLocator locator = new InvokerLocator(locatorURI);
58       System.out.println("Calling remoting server with locator uri of: " + locatorURI);
59
60       Client remotingClient = new Client(locator);
61       Object JavaDoc response = remotingClient.invoke("Do something");
62
63       assertEquals(response,ServerTest.RESPONSE_VALUE);
64    }
65
66    /**
67     * Can pass transport and port to be used as parameters.
68     * Valid transports are 'rmi' and 'socket'.
69     *
70     * @param args
71     */

72    public static void main(String JavaDoc[] args)
73    {
74       if(args != null && args.length == 2)
75       {
76          transport = args[0];
77          port = Integer.parseInt(args[1]);
78       }
79       String JavaDoc locatorURI = transport + "://" + host + ":" + port;
80       ClientTest clientTest = new ClientTest(ClientTest.class.getName(), locatorURI);
81       try
82       {
83          MultipleTestRunner runner = new MultipleTestRunner();
84          runner.doRun(clientTest, true);
85       }
86       catch(Throwable JavaDoc e)
87       {
88          e.printStackTrace();
89          System.exit(1);
90       }
91       System.exit(0);
92    }
93 }
Popular Tags