source: tmcsimulator/trunk/test/tmcsim/cadsimulator/VisibleSystemDemoDriver.java @ 558

Revision 558, 6.2 KB checked in by jdalbey, 6 years ago (diff)

Change hardcoded "scripts" as name of folder to a constant in SimulationManager?. See #228.

Line 
1package tmcsim.cadsimulator;
2
3import java.io.File;
4import java.io.FileWriter;
5import java.io.PrintWriter;
6import java.rmi.RemoteException;
7import static junit.framework.Assert.assertEquals;
8import static junit.framework.Assert.fail;
9import org.uispec4j.*;
10import org.uispec4j.interception.WindowInterceptor;
11import tmcsim.common.ScriptException;
12import tmcsim.common.SimulationException;
13import tmcsim.paramicscommunicator.ParamicsCommunicator;
14import tmcsim.paramicscommunicator.gui.ParamicsCommunicatorGUI;
15import tmcsim.simulationmanager.SimulationManager;
16import static tmcsim.simulationmanager.SimulationManager.kScenarioFolder;
17
18/**
19 * Requires manual starting CADSimulator before running this test. System test
20 * with emulated Paramics Modeler NO ATMS server.
21 *
22 * @author jdalbey
23 */
24public class VisibleSystemDemoDriver extends UISpecTestCase
25{
26
27    SimulationManager simMgrApp;
28
29    public VisibleSystemDemoDriver(String testName)
30    {
31        super(testName);
32    }
33
34    @Override
35    protected void setUp() throws Exception
36    {
37        super.setUp();
38    }
39
40    /**
41     * Test of run method, of class ParamicsCommunicator.
42     */
43    public void testRun() throws ScriptException, SimulationException, RemoteException
44    {
45        System.out.println("Visible System Test starting.");
46        // NOTE: CADSimulator must be started prior to running this test,
47        // because it displays a GUI, and if we try to do it inside this test,
48        // UISpec will complain about an uncaught window appearing.
49
50        ParamicsCommunicator pc = null;
51        pc = new ParamicsCommunicator("config/paramics_communicator_config.properties");
52        ParamicsCommunicatorGUI theGUI = new ParamicsCommunicatorGUI();
53        pc.setGUI(theGUI);
54        // Note: Don't set visible ANY windows during UISpec test
55
56        // expect pcomm to say "sleeping"
57
58        Window simMgrWindow = null;
59        simMgrWindow = WindowInterceptor.run(new Trigger()
60        {
61            public void run()
62            {
63                try
64                {
65                    simMgrApp = new SimulationManager("config/sim_manager_systest_config.properties");
66                } catch (Exception ex)
67                {
68                    fail("Couldn't launch Simulation Manager, perhaps CADSimulator isn't running.");
69                }
70            }
71        });
72
73        // Check that the Sim Mgr GUI appears without a script loaded yet
74        Panel contentPanel = simMgrWindow.getPanel("contentPane");
75        TextBox txtSimStatus = contentPanel.getTextBox("simulationStatusText");
76        assertEquals("No Script", txtSimStatus.getText());
77        TextBox txtParamStatus = contentPanel.getTextBox("paramicsStatusInfoLabel");
78        assertEquals("Unknown", txtParamStatus.getText());
79        Button loadNetworkBtn = simMgrWindow.getButton("Load Network");
80        assertFalse(loadNetworkBtn.isEnabled());
81        // Begin actions
82        Button paramicsBtn = simMgrWindow.getButton("Connect to Paramics");
83        paramicsBtn.click();
84        try
85        {
86            Thread.sleep(200);
87        } catch (Exception ex)
88        {
89        }
90        assertEquals("Disconnect from Paramics", paramicsBtn.getLabel());
91
92        assertEquals("Connected", txtParamStatus.getText());
93        pc.startReading();
94
95        loadNetworkBtn.click();
96        try
97        {
98            Thread.sleep(200);
99        } catch (Exception ex)
100        {
101        }
102        assertEquals("Sending Network ID", txtParamStatus.getText());
103        System.out.println("Sending Network ID");
104        assertFalse(loadNetworkBtn.isEnabled());
105        String warmingXML = "<Paramics>\n"
106                + "<Network_Status>WARMING</Network_Status>\n"
107                + "<Network_ID>1</Network_ID>\n"
108                + "</Paramics>";
109        writedata("paramics_status.xml", warmingXML);
110        try
111        {
112            Thread.sleep(2100);
113        } catch (Exception ex)
114        {
115        }
116        assertEquals("Warming Up", txtParamStatus.getText());
117        System.out.println("Warming Up Passed");
118
119        try
120        {
121            Thread.sleep(2100);
122        } catch (Exception ex)
123        {
124        }
125        String loadedXML = "<Paramics>\n"
126                + "<Network_Status>LOADED</Network_Status>"
127                + "<Network_ID>1</Network_ID>"
128                + "</Paramics>";
129        writedata("paramics_status.xml", loadedXML);
130        try
131        {
132            Thread.sleep(2100);
133        } catch (Exception ex)
134        {
135        }
136        assertEquals("Network 1 Loaded", txtParamStatus.getText());
137        System.out.println("Network Loaded Passed");
138
139        // Load a script file
140        String autoloadScriptname = kScenarioFolder+"/audio_systest.xml";
141        simMgrApp.loadScript(new File(autoloadScriptname));
142        try
143        {
144            Thread.sleep(500);
145        } catch (Exception ex)
146        {
147        }
148
149        // The status should now say Ready
150        assertEquals("Ready", txtSimStatus.getText());
151
152        // Click "Start"
153        simMgrWindow.getButton("Start").click();
154        try
155        {
156            Thread.sleep(200);
157        } catch (Exception ex)
158        {
159            ex.printStackTrace();
160        }
161        assertEquals("Running", txtSimStatus.getText());
162        System.out.println("Running Passed");
163        try
164        {
165            Thread.sleep(9000);
166        } catch (InterruptedException ex)
167        {
168        }
169        simMgrWindow.getButton("Pause").click();
170        try
171        {
172            Thread.sleep(3000);
173        } catch (InterruptedException ex)
174        {
175        }
176        simMgrWindow.getButton("Start").click();
177        try
178        {
179            Thread.sleep(3000);
180        } catch (InterruptedException ex)
181        {
182        }
183        simMgrWindow.getButton("Pause").click();
184        simMgrWindow.getMenuBar().getMenu("File").getSubMenu("Exit").click();
185        System.out.println("Exiting.");
186    }
187
188    // Write the test data to a file
189    public static void writedata(String filename, String data)
190    {
191//        System.out.println("writedata called for " + filename);
192        PrintWriter writer = null;
193        try
194        {
195            writer = new PrintWriter(new FileWriter(filename));
196            writer.println(data);
197            writer.close();
198        } catch (Exception ex)
199        {
200            ex.printStackTrace();
201        }
202    }
203}
Note: See TracBrowser for help on using the repository browser.