1 4 package org.oddjob.monitor.view; 5 6 import java.awt.Component ; 7 import java.io.File ; 8 9 import javax.swing.JMenu ; 10 import javax.swing.JMenuItem ; 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 24 public class ActionModelTest extends TestCase { 25 26 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 menu = new JMenu (); 44 detailModel.addObserver(test); 45 test.populateMenu(menu); 46 47 detailModel.select(econ, oj); 48 49 Component c = menu.getMenuComponent(7); 50 assertEquals(JMenuItem .class, c.getClass()); 51 52 JMenuItem item = (JMenuItem ) c; 53 DesignerAction designerAction = (DesignerAction) item.getAction(); 54 55 assertFalse("oj has no config", designerAction.isEnabled()); 56 } 57 58 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 ("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 menu = new JMenu (); 75 detailModel.addObserver(test); 76 test.populateMenu(menu); 77 78 detailModel.select(econ, oj); 79 80 JMenuItem item = (JMenuItem ) menu.getMenuComponent(7); 81 DesignerAction designerAction = (DesignerAction) item.getAction(); 82 83 assertTrue("designer enabled", designerAction.isEnabled()); 84 } 85 86 } 87 | Popular Tags |