KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > callback > CallbackTestCase


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.callback;
8
9 import junit.framework.Test;
10 import junit.framework.TestSuite;
11 import junit.textui.TestRunner;
12 import org.jboss.dtf.DistributedTestCase;
13 import org.jgroups.Address;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18
19 /**
20  * This should be used as the main test case for the invoker client/server.
21  * It will start one instance of the client and one of the server and will
22  * gather the test results and report them in standard JUnit format. When
23  * wanting to run JUnit test for invoker, this is the class to use.
24  *
25  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
26  */

27 public class CallbackTestCase extends DistributedTestCase
28 {
29    private List JavaDoc results = new ArrayList JavaDoc();
30
31    public CallbackTestCase(String JavaDoc name)
32    {
33       super(name);
34    }
35
36    protected void setUp() throws Exception JavaDoc
37    {
38       String JavaDoc clientcmd = "java -cp " + System.getProperty("java.class.path") +
39 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.local.dir") +
40
" " + CallbackTestClient.class.getName() + " 3";
41       System.out.println("clientcmd: " + clientcmd);
42       String JavaDoc svrcmd = "java -cp " + System.getProperty("java.class.path") +
43 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.remote.dir") +
44
" " + CallbackTestServer.class.getName() + " 3";
45       System.out.println("svrcmd: " + svrcmd);
46
47       final Process JavaDoc local = Runtime.getRuntime().exec(clientcmd);
48       final Process JavaDoc remote = Runtime.getRuntime().exec(svrcmd);
49
50    }
51
52    protected void tearDown() throws Exception JavaDoc
53    {
54       //NO OP since manually controlling shutdown
55
}
56
57    public void testInvokers()
58    {
59       try
60       {
61          startup(3);
62          System.out.println("startup() called");
63          shutdown();
64          System.out.println("shutdown() called");
65       }
66       catch(Exception JavaDoc e)
67       {
68          e.printStackTrace();
69          assertTrue("Problem starting or stopping client/server processes.", false);
70       }
71       finally
72       {
73          // assert results
74
try
75          {
76             Thread.currentThread().sleep(5000);
77          }
78          catch(InterruptedException JavaDoc e)
79          {
80             e.printStackTrace();
81          }
82          System.out.println("results.size() = " + results.size());
83          if(results.size() > 0)
84          {
85             Iterator JavaDoc itr = results.iterator();
86             while(itr.hasNext())
87             {
88                String JavaDoc message = (String JavaDoc) itr.next();
89                assertTrue(message, false);
90             }
91          }
92          else
93          {
94             assertTrue("No test failures or errors.", true);
95          }
96
97       }
98    }
99
100    /**
101     * **********************************
102     * Driver callback for JUnit asserts *
103     * ***********************************
104     */

105    public void receiveAssert(Address source, String JavaDoc message)
106    {
107       super.receiveAssert(source, message);
108       results.add("Assert source: " + source + "\tmessage: " + message);
109    }
110
111    public static Test suite()
112    {
113       return new TestSuite(CallbackTestCase.class);
114    }
115
116    public static void main(String JavaDoc[] args)
117    {
118       TestRunner.run(suite());
119       System.exit(0);
120    }
121
122
123 }
Popular Tags