KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > jmx > TogetherTest


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.jmx;
5
6 import junit.framework.TestCase;
7
8 import org.apache.commons.beanutils.PropertyUtils;
9 import org.apache.log4j.Logger;
10 import org.oddjob.Oddjob;
11 import org.oddjob.arooa.reflect.IntrospectionHelper;
12 import org.oddjob.values.VariablesJob;
13
14 /**
15  * Test for both client and server together.
16  *
17  */

18 public class TogetherTest extends TestCase {
19     private static final Logger logger = Logger.getLogger(TogetherTest.class);
20
21     protected void setUp() {
22         logger.debug("================= " + getName() + "==================");
23     }
24     
25     public void test1() {
26
27         Oddjob oj = new Oddjob();
28         oj.setInput(this.getClass().getResourceAsStream("together1.xml"));
29         oj.run();
30         
31         VariablesJob result = (VariablesJob) oj.lookup("result");
32         assertNotNull(result);
33         String JavaDoc fruit = (String JavaDoc) IntrospectionHelper.valueFor(result.get("fruit"));
34         assertNotNull(fruit);
35         assertEquals("apples", fruit);
36     }
37
38 // doesn't work in ant and I don't know why!!
39
public void test2() throws Exception JavaDoc {
40         Oddjob oj = new Oddjob();
41         oj.setInput(this.getClass().getResourceAsStream("together2.xml"));
42         oj.run();
43         
44         VariablesJob result = (VariablesJob) oj.lookup("result");
45         assertNotNull(result);
46         Object JavaDoc o = IntrospectionHelper.valueFor(result.get("echo"));
47         assertEquals("apples", PropertyUtils.getProperty(o, "text"));
48     }
49
50     // test a serving a nested oddjob.
51
public void test3() throws Exception JavaDoc {
52         Oddjob oj = new Oddjob();
53         oj.setInput(this.getClass().getResourceAsStream("together3.xml"));
54         oj.setArgs(0, this.getClass().getResourceAsStream("together3a.xml"));
55         oj.run();
56
57         VariablesJob result = (VariablesJob) oj.lookup("oj/result");
58         assertNotNull(result);
59         Object JavaDoc o = IntrospectionHelper.valueFor(result.get("echo"));
60         assertEquals("apples", PropertyUtils.getProperty(o, "text"));
61     }
62     
63     // test a client and server pair that share each other.
64
public void test4() throws Exception JavaDoc {
65         Oddjob oj = new Oddjob();
66         oj.setInput(this.getClass().getResourceAsStream("together4.xml"));
67         
68 // OddjobExplorer e = new OddjobExplorer();
69
// e.setRoot(oj);
70
// Thread t = new Thread(e);
71
// t.start();
72

73         oj.run();
74
75 // t.join();
76

77         Object JavaDoc test1 = oj.lookup("test1");
78         assertEquals("oranges", PropertyUtils.getProperty(test1, "text"));
79         
80         Object JavaDoc test2 = oj.lookup("test2");
81         assertEquals("apples", PropertyUtils.getProperty(test2, "text"));
82     }
83 }
84
Popular Tags