KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > model > DetailModelTest


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

4 package org.oddjob.monitor.model;
5
6 import java.util.Observable JavaDoc;
7 import java.util.Observer JavaDoc;
8
9 import junit.framework.TestCase;
10
11 import org.apache.log4j.Logger;
12 import org.oddjob.Oddjob;
13 import org.oddjob.Stateful;
14 import org.oddjob.logging.LocalConsoleArchiver;
15 import org.oddjob.logging.LogArchiver;
16 import org.oddjob.logging.LogHelper;
17 import org.oddjob.logging.LogLevel;
18 import org.oddjob.logging.LogListener;
19 import org.oddjob.state.JobStateListener;
20
21 /**
22  *
23  */

24 public class DetailModelTest extends TestCase {
25     private static final Logger logger = Logger.getLogger(DetailModelTest.class);
26     
27     class MyLA implements LogArchiver {
28         boolean removed;
29         public void addLogListener(LogListener l, Object JavaDoc component,
30                 LogLevel level, long last, int max) {
31             logger.debug("logListener added " + LogHelper.getLogger(component));
32             assertEquals(LogLevel.DEBUG, level);
33             assertEquals(-1, last);
34             assertEquals(1000, max);
35         }
36         
37         public void removeLogListener(LogListener l, Object JavaDoc component) {
38             removed = true;
39             logger.debug("logListener removed");
40         }
41     }
42             
43     
44     class MyJob implements Stateful {
45         public String JavaDoc getLogger() {
46             return "foo";
47         }
48         boolean added;
49         boolean removed;
50         public void addJobStateListener(JobStateListener listener) {
51             logger.debug("JobStateListener added");
52             added = true;
53         }
54         public void removeJobStateListener(JobStateListener listener) {
55             logger.debug("JobStateListener removed");
56             removed = true;
57         }
58     }
59
60     Observable JavaDoc ob;
61     Object JavaDoc ar;
62     class MyO implements Observer JavaDoc {
63         /* (non-Javadoc)
64          * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
65          */

66         public void update(Observable JavaDoc o, Object JavaDoc arg) {
67             ob = o;
68             ar = arg;
69         }
70     }
71     
72     /**
73      * Test the effect of selecting a node on the model.
74      *
75      */

76     public void testSelect() {
77         MyLA la = new MyLA();
78         MyJob mj = new MyJob();
79
80         ExplorerModel em = new ExplorerModel();
81         em.setRoot(mj);
82         
83         DetailModel m = new DetailModel();
84         ExplorerContext context = new ExplorerContext(em);
85         context.setLogArchiver(la);
86         context.setConsoleArchiver(new LocalConsoleArchiver(mj));
87         
88         // console
89
Oddjob.class.getName();
90         System.out.println("Hello");
91         m.setTabSelected(DetailModel.CONSOLE_TAB);
92         logger.debug("Console selected");
93         Observable JavaDoc consoleModel = m.getConsoleModel();
94         consoleModel.addObserver(new MyO());
95         m.select(context, mj);
96         assertNotNull(ob);
97         
98         // log
99
m.setTabSelected(DetailModel.LOG_TAB);
100         logger.debug("Log selected");
101         m.select(context, mj);
102         logger.debug("Log de-selected");
103         m.deSelect(context, mj);
104         assertTrue(la.removed);
105         la.removed = false;
106         
107         m.setTabSelected(DetailModel.STATE_TAB);
108         
109         logger.debug("Tab 0 selected");
110         m.select(context, mj);
111         assertTrue(mj.added);
112         
113         logger.debug("Tab 0 de-selected");
114         m.deSelect(context, mj);
115         assertTrue(la.removed);
116         assertTrue(mj.removed);
117         
118     }
119     
120 }
121
Popular Tags