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

Revision 658, 5.0 KB checked in by jdalbey, 4 years ago (diff)

Replace hard-code scenario folder name in Simulation Manager with config property.

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