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

Revision 6, 4.1 KB checked in by jdalbey, 10 years ago (diff)

Multifile commit. Add version # to Paramics Communicator. Move Load button in Sim Mgr. Add several tests. Add package jars target.

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