KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > action > SoftResetActionTest


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

4 package org.oddjob.monitor.action;
5
6 import junit.framework.TestCase;
7
8 import org.apache.log4j.Logger;
9 import org.oddjob.Resetable;
10 import org.oddjob.monitor.model.ExplorerContext;
11 import org.oddjob.monitor.model.ExplorerModel;
12 import org.oddjob.monitor.model.JobAction;
13 import org.oddjob.util.ThreadManager;
14
15 public class SoftResetActionTest extends TestCase {
16     private static final Logger logger = Logger.getLogger(SoftResetActionTest.class);
17
18     /**
19      * Test that performing the action works.
20      *
21      */

22     public void testPerform() throws Exception JavaDoc {
23         class MyR implements Resetable {
24             boolean reset = false;
25             public void softReset() {
26                 reset = true;
27             }
28             public void hardReset() {
29             }
30         }
31         MyR sample = new MyR();
32                 
33         ExplorerModel em = new ExplorerModel();
34         em.setRoot(sample);
35         ThreadManager tm = new ThreadManager();
36         em.setThreadManager(tm);
37         ExplorerContext ec = new ExplorerContext(em);
38         
39         JobAction test = new SoftResetAction();
40         test.optionSelect(sample, ec);
41         
42         test.action();
43         
44         while (tm.activeDescriptions().length > 0) {
45             logger.debug("Waiting for ThreadManager.");
46             Thread.yield();
47         }
48         assertTrue(sample.reset);
49     }
50
51     /**
52      * Test action is disabled for an object.
53      *
54      */

55     public void testWithObject() {
56         JobAction test = new SoftResetAction();
57         test.optionSelect(new Object JavaDoc(), null);
58         assertFalse(test.enabled());
59     }
60
61 }
62
Popular Tags