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

Revision 558, 7.1 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.assertTrue;
9import static junit.framework.Assert.fail;
10import org.uispec4j.*;
11import org.uispec4j.interception.WindowInterceptor;
12import tmcsim.common.ScriptException;
13import tmcsim.common.SimulationException;
14import tmcsim.paramicscommunicator.ParamicsCommunicator;
15import tmcsim.paramicscommunicator.gui.ParamicsCommunicatorGUI;
16import tmcsim.simulationmanager.SimulationManager;
17import static tmcsim.simulationmanager.SimulationManager.kScenarioFolder;
18
19/**
20 * System test (include CADSimulator) with emulated Paramics Modeler NO ATMS
21 * server captures GUI display using UISpec4J.
22 *
23 * @author jdalbey
24 */
25public class SystemTest extends UISpecTestCase
26{
27
28    SimulationManager simMgrApp;
29    CADServer engine;
30//    ParamicsCommunicator paramicscomm;
31
32    public SystemTest(String testName)
33    {
34        super(testName);
35    }
36
37    @Override
38    protected void setUp() throws Exception
39    {
40        super.setUp();
41    }
42
43    /**
44     * Test of run method, of class ParamicsCommunicator.
45     */
46    public void testRun() throws ScriptException, SimulationException, RemoteException
47    {
48        System.out.println("Invisible System Test");
49        Window cadwindow = null;
50        cadwindow = WindowInterceptor.run(new Trigger()
51        {
52            public void run()
53            {
54                try
55                {
56                    engine = new CADServer("config/cad_simulator_config.properties");
57                } catch (Exception e)
58                {
59                    fail("Couldn't launch CADSimulator");
60                }
61            }
62        });
63
64        // Check CAD Simulator appears with no script and nothing connected
65        assertTrue("Title bar incorrect", cadwindow.getTitle().trim().startsWith("CAD Server"));
66        Panel mainPanel = cadwindow.getPanel("contentPane");
67        TextBox txtStatus = mainPanel.getTextBox("simulationStatus");
68        assertEquals("No Script", txtStatus.getText());
69        TextBox terms = mainPanel.getTextBox("termConnectedTF");
70        assertEquals("0", terms.getText().trim());
71        assertEquals("No", mainPanel.getTextBox("managerConnectedTF").getText().trim());
72        assertEquals("network id should be None", "None", mainPanel.getTextBox("networkLoadedTF").getText().trim());
73
74        ParamicsCommunicator pc = null;
75        pc = new ParamicsCommunicator("config/paramics_communicator_config.properties");
76        ParamicsCommunicatorGUI theGUI = new ParamicsCommunicatorGUI();
77        pc.setGUI(theGUI);
78        // Note: Can't set visible ANY windows during UISpec test
79
80        // expect pcomm to say "sleeping"
81
82        Window simMgrWindow = null;
83        simMgrWindow = WindowInterceptor.run(new Trigger()
84        {
85            public void run()
86            {
87                try
88                {
89                    simMgrApp = new SimulationManager("config/sim_manager_systest_config.properties");
90                } catch (Exception ex)
91                {
92                    fail("Couldn't launch Simulation Manager");
93                }
94            }
95        });
96
97        // TODO: Check that the Sim Mgr GUI appears without a script loaded yet
98
99        Panel contentPanel = simMgrWindow.getPanel("contentPane");
100        TextBox txtSimStatus = contentPanel.getTextBox("simulationStatusText");
101        assertEquals("No Script", txtSimStatus.getText());
102        TextBox txtParamStatus = contentPanel.getTextBox("paramicsStatusInfoLabel");
103        assertEquals("Unknown", txtParamStatus.getText());
104        Button loadNetworkBtn = simMgrWindow.getButton("Load Network");
105        assertFalse(loadNetworkBtn.isEnabled());
106
107        Button paramicsBtn = simMgrWindow.getButton("Connect to Paramics");
108        paramicsBtn.click();
109        try
110        {
111            Thread.sleep(200);
112        } catch (Exception ex)
113        {
114        }
115        assertEquals("Disconnect from Paramics", paramicsBtn.getLabel());
116
117        assertEquals("Connected", txtParamStatus.getText());
118        pc.startReading();
119
120        loadNetworkBtn.click();
121        try
122        {
123            Thread.sleep(200);
124        } catch (Exception ex)
125        {
126        }
127        assertEquals("Sending Network ID", txtParamStatus.getText());
128        System.out.println("Sending Network ID");
129        assertFalse(loadNetworkBtn.isEnabled());
130        String warmingXML = "<Paramics>\n"
131                + "<Network_Status>WARMING</Network_Status>\n"
132                + "<Network_ID>1</Network_ID>\n"
133                + "</Paramics>";
134        writedata("paramics_status.xml", warmingXML);
135        try
136        {
137            Thread.sleep(2100);
138        } catch (Exception ex)
139        {
140        }
141        assertEquals("Warming Up", txtParamStatus.getText());
142        System.out.println("Warming Up Passed");
143
144        try
145        {
146            Thread.sleep(2100);
147        } catch (Exception ex)
148        {
149        }
150        String loadedXML = "<Paramics>\n"
151                + "<Network_Status>LOADED</Network_Status>"
152                + "<Network_ID>1</Network_ID>"
153                + "</Paramics>";
154        writedata("paramics_status.xml", loadedXML);
155        try
156        {
157            Thread.sleep(2100);
158        } catch (Exception ex)
159        {
160        }
161        //assertEquals("Network 1 Loaded", txtParamStatus.getText());
162        //assertEquals("network id should be 1", "1", mainPanel.getTextBox("networkLoadedTF").getText().trim());
163
164
165        // Load a script file
166        String autoloadScriptname = kScenarioFolder+"/system_test_script.xml";
167        simMgrApp.loadScript(new File(autoloadScriptname));
168        try
169        {
170            Thread.sleep(500);
171        } catch (Exception ex)
172        {
173        }
174
175        // The status should now say Ready
176        assertEquals("Ready", txtSimStatus.getText());
177
178        // Click "Start"
179        simMgrWindow.getButton("Start").click();
180        try
181        {
182            Thread.sleep(200);
183        } catch (Exception ex)
184        {
185            ex.printStackTrace();
186        }
187        assertEquals("Running", txtSimStatus.getText());
188        System.out.println("Running Passed");
189        try
190        {
191            Thread.sleep(9000);
192        } catch (InterruptedException ex)
193        {
194        }
195        simMgrWindow.getButton("Pause").click();
196        try
197        {
198            Thread.sleep(3000);
199        } catch (InterruptedException ex)
200        {
201        }
202        simMgrWindow.getButton("Start").click();
203        try
204        {
205            Thread.sleep(3000);
206        } catch (InterruptedException ex)
207        {
208        }
209        simMgrWindow.getButton("Pause").click();
210        simMgrWindow.getMenuBar().getMenu("File").getSubMenu("Exit").click();
211        System.out.println("Exiting.");
212    }
213
214    // Write the test data to a file
215    public static void writedata(String filename, String data)
216    {
217        PrintWriter writer = null;
218        try
219        {
220            writer = new PrintWriter(new FileWriter(filename));
221            writer.println(data);
222            writer.close();
223        } catch (Exception ex)
224        {
225            ex.printStackTrace();
226        }
227    }
228}
Note: See TracBrowser for help on using the repository browser.