KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > remoting > RmiTestBase


1 package hudson.remoting;
2
3 import junit.framework.TestCase;
4 import junit.framework.Test;
5 import junit.framework.TestSuite;
6
7 import java.io.IOException JavaDoc;
8 import java.io.PipedInputStream JavaDoc;
9 import java.io.PipedOutputStream JavaDoc;
10 import java.util.concurrent.ExecutorService JavaDoc;
11 import java.util.concurrent.Executors JavaDoc;
12
13 import hudson.remoting.ChannelRunner.InProcess;
14
15 /**
16  * Base class for remoting tests.
17  *
18  * @author Kohsuke Kawaguchi
19  */

20 public abstract class RmiTestBase extends TestCase {
21
22     protected Channel channel;
23     private ChannelRunner channelRunner = new InProcess();
24
25     protected void setUp() throws Exception JavaDoc {
26         channel = channelRunner.start();
27     }
28
29     protected void tearDown() throws Exception JavaDoc {
30         channelRunner.stop(channel);
31     }
32
33     /*package*/ void setChannelRunner(Class JavaDoc<? extends ChannelRunner> runner) {
34         try {
35             this.channelRunner = runner.newInstance();
36         } catch (InstantiationException JavaDoc e) {
37             throw new Error JavaDoc(e);
38         } catch (IllegalAccessException JavaDoc e) {
39             throw new Error JavaDoc(e);
40         }
41     }
42
43     public String JavaDoc getName() {
44         return super.getName()+"-"+channelRunner.getName();
45     }
46
47     /**
48      * Can be used in the suite method of the derived class to build a
49      * {@link TestSuite} to run the test with all the available
50      * {@link ChannelRunner} configuration.
51      */

52     protected static Test buildSuite(Class JavaDoc<? extends RmiTestBase> testClass) {
53         TestSuite suite = new TestSuite();
54         for( Class JavaDoc<? extends ChannelRunner> r : ChannelRunner.LIST ) {
55             suite.addTest(new ChannelTestSuite(testClass,r));
56         }
57         return suite;
58     }
59 }
60
Popular Tags