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

Revision 52, 6.6 KB checked in by jdalbey, 10 years ago (diff)

ParamicsCommunicator?.java revised to simplify system testing

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