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

Revision 228, 4.9 KB checked in by jdalbey, 8 years ago (diff)

System Tests updated to work with new integrated Traffic Mgr. All system tests now passing.

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