KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > jobs > WaitJobTest


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

4 package org.oddjob.jobs;
5
6 import junit.framework.TestCase;
7
8 import org.apache.commons.beanutils.PropertyUtils;
9 import org.oddjob.Oddjob;
10 import org.oddjob.jobs.structural.SequentialJob;
11 import org.oddjob.state.JobState;
12
13 public class WaitJobTest extends TestCase {
14
15     public void testInOddjob() throws Exception JavaDoc {
16     
17         Oddjob oj = new Oddjob();
18         oj.setInput(WaitJobTest.class.getResourceAsStream("wait.xml"));
19
20         oj.run();
21         
22         Object JavaDoc result = oj.lookup("test");
23         assertEquals("hello", PropertyUtils.getProperty(result, "text"));
24     }
25
26     public void testStateWait() {
27         DummyStateJob sample = new DummyStateJob();
28         sample.setDesired("complete");
29         
30         WaitJob wait = new WaitJob();
31         wait.setPause(2000);
32         
33         SequentialJob sequential = new SequentialJob();
34         sequential.addComponent(wait);
35         sequential.addComponent(sample);
36         
37         Thread JavaDoc t = new Thread JavaDoc(sequential);
38         
39         WaitJob test = new WaitJob();
40         test.setFor(sample);
41         test.setState("complete");
42
43         t.start();
44         test.run();
45         
46         assertEquals(JobState.COMPLETE, sample.lastJobStateEvent().getJobState());
47     }
48     
49     public void testStateWaitInOJ() throws Exception JavaDoc {
50         
51         Oddjob oj = new Oddjob();
52         oj.setInput(WaitJobTest.class.getResourceAsStream("wait2.xml"));
53
54         oj.run();
55         
56         Object JavaDoc result = oj.lookup("test");
57         assertEquals("hello", PropertyUtils.getProperty(result, "text"));
58     }
59     
60     public void testNotStateWait() {
61         DummyStateJob sample = new DummyStateJob();
62         sample.setDesired("complete");
63                 
64         WaitJob test = new WaitJob();
65         test.setFor(sample);
66         test.setState("!complete");
67
68         assertEquals(JobState.READY, sample.lastJobStateEvent().getJobState());
69         
70         // smample will still be ready
71
test.run();
72         
73     }
74 }
75
Popular Tags