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

Revision 422, 7.0 KB checked in by jdalbey, 7 years ago (diff)

Remove ATMS functionality. Reworked and simplified the Highway model to use only VDS data from PeMS. Updated all unit tests.

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