Warning: Can't use blame annotator:
svn blame failed on trunk/test/tmcsim/cadsimulator/SystemConsoleTest.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/test/tmcsim/cadsimulator/SystemConsoleTest.java @ 664

Revision 664, 6.6 KB checked in by jdalbey, 4 years ago (diff)

Multifile commit - revise source to match revisions to config filenames. Fix broken system tests. Fix defect #160.

RevLine 
1package tmcsim.cadsimulator;
2
3import java.io.File;
4import java.io.FileWriter;
5import java.io.PrintWriter;
6import java.rmi.RemoteException;
7import java.util.logging.Level;
8import java.util.logging.Logger;
9import static junit.framework.Assert.assertEquals;
10import static junit.framework.Assert.fail;
11import static org.mockito.Mockito.mock;
12import static org.mockito.Mockito.when;
13import org.uispec4j.*;
14import org.uispec4j.interception.WindowInterceptor;
15import tmcsim.cadsimulator.managers.ATMSManager;
16import tmcsim.common.ScriptException;
17import tmcsim.common.SimulationException;
18import tmcsim.paramicscommunicator.ParamicsCommunicator;
19import tmcsim.paramicscommunicator.gui.ParamicsCommunicatorGUI;
20import tmcsim.simulationmanager.SimulationManager;
21import static tmcsim.simulationmanager.SimulationManager.SCENARIOS_DIR;
22
23/**
24 * Note, this is just like VisibleSystemTest except it starts it's own
25 * CADSimulator running on the console.
26 *
27 * @author jdalbey
28 */
29public class SystemConsoleTest extends UISpecTestCase
30{
31
32    SimulationManager simMgrApp;
33    CADServer engine;
34
35    public SystemConsoleTest(String testName)
36    {
37        super(testName);
38    }
39
40    @Override
41    protected void setUp() throws Exception
42    {
43        super.setUp();
44    }
45
46    /**
47     * Test of run method, of class ParamicsCommunicator.
48     */
49    public void testRun() throws ScriptException, SimulationException, RemoteException
50    {
51        System.out.println("System Console Test");
52
53        try
54        {
55            engine = new CADServer("config/cad_server_console.properties");
56        } catch (Exception e)
57        {
58            fail("Couldn't launch CADSimulator");
59        }
60
61        ParamicsCommunicator pc = null;
62        pc = new ParamicsCommunicator("config/paramics_communicator_config.properties");
63        ParamicsCommunicatorGUI theGUI = new ParamicsCommunicatorGUI();
64        pc.setGUI(theGUI);
65        // Note: Can't set visible ANY windows during UISpec test
66
67        // expect pcomm to say "sleeping"
68
69        Window simMgrWindow = null;
70        simMgrWindow = WindowInterceptor.run(new Trigger()
71        {
72            public void run()
73            {
74                try
75                {
76                    simMgrApp = new SimulationManager("config/sim_manager.properties");
77                } catch (Exception ex)
78                {
79                    fail("Couldn't launch Simulation Manager");
80                }
81            }
82        });
83
84        // TODO: Check that the Sim Mgr GUI appears without a script loaded yet
85
86        Panel contentPanel = simMgrWindow.getPanel("contentPane");
87        TextBox txtSimStatus = contentPanel.getTextBox("simulationStatusText");
88        assertEquals("No Script", txtSimStatus.getText());
89        TextBox txtParamStatus = contentPanel.getTextBox("paramicsStatusInfoLabel");
90        assertEquals("Unknown", txtParamStatus.getText());
91        Button loadNetworkBtn = simMgrWindow.getButton("Load Network");
92        assertFalse(loadNetworkBtn.isEnabled());
93
94        Button paramicsBtn = simMgrWindow.getButton("Connect to Paramics");
95        paramicsBtn.click();
96        try
97        {
98            Thread.sleep(200);
99        } catch (Exception ex)
100        {
101        }
102        assertEquals("Disconnect from Paramics", paramicsBtn.getLabel());
103
104        assertEquals("Connected", txtParamStatus.getText());
105        pc.startReading();
106
107        loadNetworkBtn.click();
108        try
109        {
110            Thread.sleep(200);
111        } catch (Exception ex)
112        {
113        }
114        assertEquals("Sending Network ID", txtParamStatus.getText());
115        System.out.println("Sending Network ID");
116        assertFalse(loadNetworkBtn.isEnabled());
117        String warmingXML = "<Paramics>\n"
118                + "<Network_Status>WARMING</Network_Status>\n"
119                + "<Network_ID>1</Network_ID>\n"
120                + "</Paramics>";
121        writedata("paramics_status.xml", warmingXML);
122        try
123        {
124            Thread.sleep(2100);
125        } catch (Exception ex)
126        {
127        }
128        assertEquals("Warming Up", txtParamStatus.getText());
129        System.out.println("Warming Up Passed");
130
131        try
132        {
133            Thread.sleep(2100);
134        } catch (Exception ex)
135        {
136        }
137        String loadedXML = "<Paramics>\n"
138                + "<Network_Status>LOADED</Network_Status>"
139                + "<Network_ID>1</Network_ID>"
140                + "</Paramics>";
141        writedata("paramics_status.xml", loadedXML);
142        try
143        {
144            Thread.sleep(2100);
145        } catch (Exception ex)
146        {
147        }
148        //assertEquals("Network 1 Loaded", txtParamStatus.getText());
149        //System.out.println("Network Loaded Passed");
150
151        // Load a script file
152        String autoloadScriptname = SCENARIOS_DIR+"/audio_systest.xml";
153        simMgrApp.loadScript(new File(autoloadScriptname));
154        try
155        {
156            Thread.sleep(500);
157        } catch (Exception ex)
158        {
159        }
160
161        // The status should now say Ready
162        assertEquals("Ready", txtSimStatus.getText());
163
164        // Mock out the ATMS manager in CADSimulator
165        ATMSManager atm = mock(ATMSManager.class);
166        try
167        {
168            when(atm.getCurrentTime()).thenReturn(29000L);
169        } catch (Exception ex)
170        {
171            Logger.getLogger(SystemConsoleTest.class.getName()).log(Level.SEVERE, null, ex);
172        }
173        engine.theATMSMgr = atm;
174
175        // Click "Start"
176        simMgrWindow.getButton("Start").click();
177        try
178        {
179            Thread.sleep(200);
180        } catch (Exception ex)
181        {
182            ex.printStackTrace();
183        }
184        assertEquals("Running", txtSimStatus.getText());
185        System.out.println("Running Passed");
186        try
187        {
188            Thread.sleep(9000);
189        } catch (InterruptedException ex)
190        {
191        }
192        simMgrWindow.getButton("Pause").click();
193        try
194        {
195            Thread.sleep(3000);
196        } catch (InterruptedException ex)
197        {
198        }
199        simMgrWindow.getButton("Resume").click();
200        try
201        {
202            Thread.sleep(3000);
203        } catch (InterruptedException ex)
204        {
205        }
206        simMgrWindow.getButton("Pause").click();
207        simMgrWindow.getMenuBar().getMenu("File").getSubMenu("Exit").click();
208        System.out.println("Exiting.");
209
210
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.