KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > view > ActionModelTest


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

4 package org.oddjob.monitor.view;
5
6 import java.awt.Component JavaDoc;
7 import java.io.File JavaDoc;
8
9 import javax.swing.JMenu JavaDoc;
10 import javax.swing.JMenuItem JavaDoc;
11
12 import junit.framework.TestCase;
13
14 import org.oddjob.Oddjob;
15 import org.oddjob.monitor.OddjobExplorer;
16 import org.oddjob.monitor.model.DetailModel;
17 import org.oddjob.monitor.model.ExplorerContext;
18 import org.oddjob.monitor.model.ExplorerModel;
19 import org.oddjob.util.ThreadManager;
20
21 /**
22  *
23  */

24 public class ActionModelTest extends TestCase {
25
26     // Trivial test to check designer action is created ok and
27
// is enabled.
28
public void testSelect1() {
29         OddjobExplorer oe = new OddjobExplorer();
30         ExplorerModel explorerModel = new ExplorerModel();
31         explorerModel.setRoot(oe);
32         explorerModel.setThreadManager(new ThreadManager());
33         
34         Oddjob oj = new Oddjob();
35         explorerModel.setRoot(oj);
36         ExplorerContext econ = new ExplorerContext(explorerModel);
37         
38         ExplorerJobActions test = new ExplorerJobActions(oe);
39         
40         DetailModel detailModel = new DetailModel();
41         detailModel.addObserver(test);
42         
43         JMenu JavaDoc menu = new JMenu JavaDoc();
44         detailModel.addObserver(test);
45         test.populateMenu(menu);
46         
47         detailModel.select(econ, oj);
48         
49         Component JavaDoc c = menu.getMenuComponent(7);
50         assertEquals(JMenuItem JavaDoc.class, c.getClass());
51         
52         JMenuItem JavaDoc item = (JMenuItem JavaDoc) c;
53         DesignerAction designerAction = (DesignerAction) item.getAction();
54
55         assertFalse("oj has no config", designerAction.isEnabled());
56     }
57
58     // Test Designer Action is created and enbled when selected an oddjob
59
// node with a configuration file.
60
public void testSelect2() {
61         OddjobExplorer oe = new OddjobExplorer();
62         ExplorerModel explorerModel = new ExplorerModel();
63         explorerModel.setThreadManager(new ThreadManager());
64         
65         Oddjob oj = new Oddjob();
66         oj.setConfig(new File JavaDoc("foo.xml"));
67         explorerModel.setRoot(oj);
68         ExplorerContext econ = new ExplorerContext(explorerModel);
69
70         ExplorerJobActions test = new ExplorerJobActions(oe);
71
72         DetailModel detailModel = new DetailModel();
73
74         JMenu JavaDoc menu = new JMenu JavaDoc();
75         detailModel.addObserver(test);
76         test.populateMenu(menu);
77
78         detailModel.select(econ, oj);
79         
80         JMenuItem JavaDoc item = (JMenuItem JavaDoc) menu.getMenuComponent(7);
81         DesignerAction designerAction = (DesignerAction) item.getAction();
82         
83         assertTrue("designer enabled", designerAction.isEnabled());
84     }
85     
86 }
87
Popular Tags