KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > marshall > dynamic > remote > socket > SocketMarshallerLoadingTestCase


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.remote.socket;
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.jboss.remoting.marshall.dynamic.local.MarshallerLoadingServer;
14 import org.jgroups.Address;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19
20 /**
21  * This should be used as the main test case for the invoker client/server.
22  * It will start one instance of the client and one of the server and will
23  * gather the test results and report them in standard JUnit format. When
24  * wanting to run JUnit test for invoker, this is the class to use.
25  *
26  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
27  */

28 public class SocketMarshallerLoadingTestCase extends DistributedTestCase
29 {
30    private List JavaDoc results = new ArrayList JavaDoc();
31
32    public SocketMarshallerLoadingTestCase(String JavaDoc name)
33    {
34       super(name);
35    }
36
37    protected void setUp() throws Exception JavaDoc
38    {
39       System.out.println(System.getProperty("loader.path"));
40       String JavaDoc clientcmd = "java -cp " + System.getProperty("java.class.path") +
41 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.local.dir") +
42
" " + org.jboss.remoting.marshall.dynamic.local.MarshallerLoadingClient.class.getName() + " 3";
43       System.out.println("clientcmd: " + clientcmd);
44       String JavaDoc svrcmd = "java -cp " + System.getProperty("java.class.path") + System.getProperty("path.separator") +
45                       convertFileSeperator(System.getProperty("loader.path")) +
46 // " -Djboss.mx.instanceid.dir=" + System.getProperty("jboss.mx.instanceid.remote.dir") +
47
" " + MarshallerLoadingServer.class.getName() + " 3";
48       System.out.println("svrcmd: " + svrcmd);
49
50       final Process JavaDoc local = Runtime.getRuntime().exec(clientcmd);
51       final Process JavaDoc remote = Runtime.getRuntime().exec(svrcmd);
52
53    }
54
55    private String JavaDoc convertFileSeperator(String JavaDoc property)
56    {
57       String JavaDoc newPath = property;
58       try
59       {
60          String JavaDoc fileSeperator = System.getProperty("file.separator");
61          String JavaDoc seperatorToReplace = "\\";
62          if(seperatorToReplace.equals(fileSeperator))
63          {
64             seperatorToReplace = "/";
65          }
66          System.out.println("fileSeperator = " + fileSeperator);
67          System.out.println("seperatorToReplace = " + seperatorToReplace);
68
69          CharSequence JavaDoc charSet = seperatorToReplace.subSequence(0, 1);
70          System.out.println("charSet = " + charSet);
71          char c = charSet.charAt(0);
72          System.out.println("char = " + c);
73
74          CharSequence JavaDoc charSet2 = fileSeperator.subSequence(0, 1);
75          System.out.println("charSet = " + charSet2);
76          char c2 = charSet2.charAt(0);
77          System.out.println("char = " + c2);
78
79          newPath = property.replace(c, c2);
80
81       }
82       catch(Exception JavaDoc e)
83       {
84          e.printStackTrace();
85       }
86       System.out.println("New path = " + newPath);
87       return newPath;
88    }
89
90    protected void tearDown() throws Exception JavaDoc
91    {
92       //NO OP since manually controlling shutdown
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(SocketMarshallerLoadingTestCase.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