KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > marshall > dynamic > local > MarshallerLoadingTestCase


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.marshall.dynamic.local;
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 MarshallerLoadingTestCase extends DistributedTestCase
28 {
29    private List JavaDoc results = new ArrayList JavaDoc();
30
31    public MarshallerLoadingTestCase(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") + System.getProperty("path.separator") +
39                       convertFileSeperator(System.getProperty("loader.path")) +
40 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.local.dir") +
41
" " + MarshallerLoadingClient.class.getName() + " 3";
42       System.out.println("clientcmd: " + clientcmd);
43       String JavaDoc svrcmd = "java -cp " + System.getProperty("java.class.path") + System.getProperty("path.separator") +
44                       convertFileSeperator(System.getProperty("loader.path")) +
45 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.remote.dir") +
46
" " + MarshallerLoadingServer.class.getName() + " 3";
47       System.out.println("svrcmd: " + svrcmd);
48
49       final Process JavaDoc local = Runtime.getRuntime().exec(clientcmd);
50       final Process JavaDoc remote = Runtime.getRuntime().exec(svrcmd);
51
52    }
53
54    protected void tearDown() throws Exception JavaDoc
55    {
56       //NO OP since manually controlling shutdown
57
}
58
59    private String JavaDoc convertFileSeperator(String JavaDoc property)
60    {
61       String JavaDoc newPath = property;
62       try
63       {
64          String JavaDoc fileSeperator = System.getProperty("file.separator");
65          String JavaDoc seperatorToReplace = "\\";
66          if(seperatorToReplace.equals(fileSeperator))
67          {
68             seperatorToReplace = "/";
69          }
70          System.out.println("fileSeperator = " + fileSeperator);
71          System.out.println("seperatorToReplace = " + seperatorToReplace);
72
73          CharSequence JavaDoc charSet = seperatorToReplace.subSequence(0, 1);
74          System.out.println("charSet = " + charSet);
75          char c = charSet.charAt(0);
76          System.out.println("char = " + c);
77
78          CharSequence JavaDoc charSet2 = fileSeperator.subSequence(0, 1);
79          System.out.println("charSet = " + charSet2);
80          char c2 = charSet2.charAt(0);
81          System.out.println("char = " + c2);
82
83          newPath = property.replace(c, c2);
84
85       }
86       catch(Exception JavaDoc e)
87       {
88          e.printStackTrace();
89       }
90       System.out.println("New path = " + newPath);
91       return newPath;
92    }
93    
94
95    public void testInvokers()
96    {
97       try
98       {
99          startup(3);
100          System.out.println("startup() called");
101          shutdown();
102          System.out.println("shutdown() called");
103       }
104       catch(Exception JavaDoc e)
105       {
106          e.printStackTrace();
107          assertTrue("Problem starting or stopping client/server processes.", false);
108       }
109       finally
110       {
111          // assert results
112
try
113          {
114             Thread.currentThread().sleep(5000);
115          }
116          catch(InterruptedException JavaDoc e)
117          {
118             e.printStackTrace();
119          }
120          System.out.println("results.size() = " + results.size());
121          if(results.size() > 0)
122          {
123             Iterator JavaDoc itr = results.iterator();
124             while(itr.hasNext())
125             {
126                String JavaDoc message = (String JavaDoc) itr.next();
127                assertTrue(message, false);
128             }
129          }
130          else
131          {
132             assertTrue("No test failures or errors.", true);
133          }
134
135       }
136    }
137
138    /**
139     * **********************************
140     * Driver callback for JUnit asserts *
141     * ***********************************
142     */

143    public void receiveAssert(Address source, String JavaDoc message)
144    {
145       super.receiveAssert(source, message);
146       results.add("Assert source: " + source + "\tmessage: " + message);
147    }
148
149    public static Test suite()
150    {
151       return new TestSuite(MarshallerLoadingTestCase.class);
152    }
153
154    public static void main(String JavaDoc[] args)
155    {
156       TestRunner.run(suite());
157       System.exit(0);
158    }
159
160
161 }
Popular Tags