source: tmcsimulator/trunk/test/tmcsim/simulationmanager/SimulationManagerSmokeTest.java @ 664

Revision 664, 6.1 KB checked in by jdalbey, 4 years ago (diff)

Multifile commit - revise source to match revisions to config filenames. Fix broken system tests. Fix defect #160.

Line 
1package tmcsim.simulationmanager;
2
3import java.awt.Component;
4import java.io.File;
5import java.util.Arrays;
6import javax.swing.JButton;
7import static junit.framework.Assert.assertEquals;
8import static junit.framework.Assert.assertFalse;
9import static junit.framework.Assert.assertTrue;
10import static junit.framework.Assert.fail;
11import org.uispec4j.Panel;
12import org.uispec4j.TextBox;
13import org.uispec4j.Trigger;
14import org.uispec4j.UISpecTestCase;
15import org.uispec4j.Window;
16import org.uispec4j.interception.WindowInterceptor;
17import tmcsim.cadsimulator.CADServer;
18import tmcsim.common.ScriptException;
19import tmcsim.common.SimulationException;
20import static tmcsim.simulationmanager.SimulationManager.SCENARIOS_DIR;
21
22/**
23 * Smoke Test of system. Start the CAD server, Start the Sim Mgr, see if the Sim
24 * Mgr view shows "No Script".
25 *
26 * @author jdalbey
27 */
28public class SimulationManagerSmokeTest extends UISpecTestCase
29{
30
31    SimulationManager simMgrApp;
32    CADServer engine;
33
34    public SimulationManagerSmokeTest(String testName)
35    {
36        super(testName);
37    }
38
39    /**
40     * Call constructors for both classes
41     */
42    public void testBothGUIs() throws ScriptException, SimulationException, InterruptedException
43    {
44        System.out.println("Smoke Test Sim Mgr & CADSimulator");
45
46        Window cadwindow = null;
47        System.setProperty("CAD_SIM_PROPERTIES", "config/cad_server.properties"); 
48        if (System.getProperty("CAD_SIM_PROPERTIES") != null)
49        {
50            cadwindow = WindowInterceptor.run(new Trigger()
51            {
52                public void run()
53                {
54                    try
55                    {
56                        engine = new CADServer(System.getProperty("CAD_SIM_PROPERTIES"));
57                    } catch (Exception e)
58                    {
59                        e.printStackTrace();
60                        fail("Couldn't launch CADSimulator");
61                    }
62                }
63            });
64        }
65        else
66        {
67            fail("CAD_SIM_PROPERTIES system property not defined.");
68        }
69
70        // Check CAD Simulator appears with no script and nothing connected
71        assertTrue("Window title incorrect", cadwindow.getTitle().startsWith("CAD Server"));
72        Panel mainPanel = cadwindow.getPanel("contentPane");
73        TextBox txtStatus = mainPanel.getTextBox("simulationStatus");
74        assertEquals("No Script", txtStatus.getText());
75        TextBox terms = mainPanel.getTextBox("termConnectedTF");
76        assertEquals("0", terms.getText().trim());
77        assertEquals("No", mainPanel.getTextBox("managerConnectedTF").getText().trim());
78
79        Window simMgrWindow = null;
80        System.setProperty("SIM_MGR_PROPERTIES", "config/sim_manager.properties");
81        if (System.getProperty("SIM_MGR_PROPERTIES") != null)
82        {
83            simMgrWindow = WindowInterceptor.run(new Trigger()
84            {
85                public void run()
86                {
87                    try
88                    {
89                        simMgrApp = new SimulationManager(System.getProperty("SIM_MGR_PROPERTIES"));
90                    } catch (Exception ex)
91                    {
92                        fail("Couldn't launch Simulation Manager");
93                    }
94                }
95            });
96        }
97        else
98        {
99            fail("SIM_MGR_PROPERTIES system property not defined.");
100        }
101
102        // Check that the Sim Mgr GUI appears without a script loaded yet
103        SimulationManagerView view = simMgrApp.theSimManagerView;
104        assertFalse(view.isSimulationStarted());
105        Window win = new Window(view);
106        Panel contentPanel = win.getPanel("contentPane");
107        TextBox txtSimStatus = contentPanel.getTextBox("simulationStatusText");
108        assertEquals("No Script", txtSimStatus.getText());
109
110        assertEquals("Yes", mainPanel.getTextBox("managerConnectedTF").getText().trim());
111
112        // Load a script file
113        String autoloadScriptname = SCENARIOS_DIR+"/practice_script_2016.xml";
114        SimulationManagerModel simMgrModel = simMgrApp.theSimManagerModel;
115        simMgrModel.loadScript(new File(autoloadScriptname));
116        // The status should now say Ready
117        assertEquals("Ready", txtSimStatus.getText());
118
119        // Click "Start"
120        win.getButton("Start").click();
121        Thread.sleep(200);
122        assertEquals("Running", txtSimStatus.getText());
123
124        java.util.ArrayList<String> expectedButtons = new java.util.ArrayList<String>(Arrays.asList("Load Script","Start","Pause","Reset","Connect to Paramics",
125                "Load Network","Reschedule","Trigger","Delete","Add New Incident","Divert Traffic"));
126        // Check for appearance of buttons in the GUI
127        win.getButton("Load Script");
128        win.getButton("Reset");
129        win.getButton("Add New Incident");
130        win.getButton("Reschedule");
131        win.getButton("Trigger");
132        win.getButton("Delete");
133        //Find all available buttons - obsolete, replaced by stmts above
134//        Component[] buttons = win.getSwingComponents(JButton.class);
135//        java.util.List<Component> actualButtons = Arrays.asList(buttons);
136//        for (Component actualBtn: actualButtons)
137//        {
138//            if (actualBtn instanceof JButton)
139//            {
140//                String btnName = ((JButton) actualBtn).getText();
141//                if (btnName.length()>0)
142//                {
143//                    if (expectedButtons.contains(btnName))
144//                    {
145//                        expectedButtons.remove(btnName);
146//                    }
147//                    else
148//                    {
149//                        fail("GUI has an unexpected button: "+btnName);
150//                    }
151//                }
152//            }
153//        }
154//        if (expectedButtons.size() > 0)
155//        {
156//            fail("GUI is missing a button: "+expectedButtons);
157//        }
158
159        // Pause the simulation   
160        win.getButton("Pause").click();
161        Thread.sleep(200);
162        win.getButton("Resume");    // resume should appear when paused
163        // Quit
164        engine = null;
165        win.getMenuBar().getMenu("File").getSubMenu("Exit").click();
166        //simMgrApp = null;
167    }
168}
Note: See TracBrowser for help on using the repository browser.