| 1 | package tmcsim.cadsimulator; |
|---|
| 2 | |
|---|
| 3 | import java.io.File; |
|---|
| 4 | import java.io.FileWriter; |
|---|
| 5 | import java.io.PrintWriter; |
|---|
| 6 | import java.rmi.RemoteException; |
|---|
| 7 | import static junit.framework.Assert.assertEquals; |
|---|
| 8 | import static junit.framework.Assert.assertTrue; |
|---|
| 9 | import static junit.framework.Assert.fail; |
|---|
| 10 | import org.uispec4j.*; |
|---|
| 11 | import org.uispec4j.interception.WindowInterceptor; |
|---|
| 12 | import tmcsim.common.ScriptException; |
|---|
| 13 | import tmcsim.common.SimulationException; |
|---|
| 14 | import tmcsim.paramicscommunicator.ParamicsCommunicator; |
|---|
| 15 | import tmcsim.paramicscommunicator.gui.ParamicsCommunicatorGUI; |
|---|
| 16 | import tmcsim.simulationmanager.SimulationManager; |
|---|
| 17 | import 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 | */ |
|---|
| 25 | public 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 Server 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 | |
|---|
| 75 | // Note: Can't set visible ANY windows during UISpec test |
|---|
| 76 | |
|---|
| 77 | Window simMgrWindow = null; |
|---|
| 78 | simMgrWindow = WindowInterceptor.run(new Trigger() |
|---|
| 79 | { |
|---|
| 80 | public void run() |
|---|
| 81 | { |
|---|
| 82 | try |
|---|
| 83 | { |
|---|
| 84 | simMgrApp = new SimulationManager("config/sim_manager_systest_config.properties"); |
|---|
| 85 | } catch (Exception ex) |
|---|
| 86 | { |
|---|
| 87 | fail("Couldn't launch Simulation Manager"); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | }); |
|---|
| 91 | |
|---|
| 92 | // TODO: Check that the Sim Mgr GUI appears without a script loaded yet |
|---|
| 93 | |
|---|
| 94 | Panel contentPanel = simMgrWindow.getPanel("contentPane"); |
|---|
| 95 | TextBox txtSimStatus = contentPanel.getTextBox("simulationStatusText"); |
|---|
| 96 | assertEquals("No Script", txtSimStatus.getText()); |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | // Load a script file |
|---|
| 100 | String autoloadScriptname = kScenarioFolder+"/system_test_script.xml"; |
|---|
| 101 | simMgrApp.loadScript(new File(autoloadScriptname)); |
|---|
| 102 | try |
|---|
| 103 | { |
|---|
| 104 | Thread.sleep(500); |
|---|
| 105 | } catch (Exception ex) |
|---|
| 106 | { |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | // The status should now say Ready |
|---|
| 110 | assertEquals("Ready", txtSimStatus.getText()); |
|---|
| 111 | |
|---|
| 112 | // Click "Start" |
|---|
| 113 | simMgrWindow.getButton("Start").click(); |
|---|
| 114 | try |
|---|
| 115 | { |
|---|
| 116 | Thread.sleep(200); |
|---|
| 117 | } catch (Exception ex) |
|---|
| 118 | { |
|---|
| 119 | ex.printStackTrace(); |
|---|
| 120 | } |
|---|
| 121 | assertEquals("Running", txtSimStatus.getText()); |
|---|
| 122 | System.out.println("Running Passed"); |
|---|
| 123 | try |
|---|
| 124 | { |
|---|
| 125 | Thread.sleep(9000); |
|---|
| 126 | } catch (InterruptedException ex) |
|---|
| 127 | { |
|---|
| 128 | } |
|---|
| 129 | simMgrWindow.getButton("Pause").click(); |
|---|
| 130 | try |
|---|
| 131 | { |
|---|
| 132 | Thread.sleep(3000); |
|---|
| 133 | } catch (InterruptedException ex) |
|---|
| 134 | { |
|---|
| 135 | } |
|---|
| 136 | simMgrWindow.getButton("Resume").click(); |
|---|
| 137 | try |
|---|
| 138 | { |
|---|
| 139 | Thread.sleep(3000); |
|---|
| 140 | } catch (InterruptedException ex) |
|---|
| 141 | { |
|---|
| 142 | } |
|---|
| 143 | simMgrWindow.getButton("Pause").click(); |
|---|
| 144 | simMgrWindow.getMenuBar().getMenu("File").getSubMenu("Exit").click(); |
|---|
| 145 | System.out.println("Exiting."); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | // Write the test data to a file |
|---|
| 149 | public static void writedata(String filename, String data) |
|---|
| 150 | { |
|---|
| 151 | PrintWriter writer = null; |
|---|
| 152 | try |
|---|
| 153 | { |
|---|
| 154 | writer = new PrintWriter(new FileWriter(filename)); |
|---|
| 155 | writer.println(data); |
|---|
| 156 | writer.close(); |
|---|
| 157 | } catch (Exception ex) |
|---|
| 158 | { |
|---|
| 159 | ex.printStackTrace(); |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | } |
|---|