| 1 | package tmcsim.simulationmanager; |
|---|
| 2 | |
|---|
| 3 | import java.awt.Component; |
|---|
| 4 | import java.io.File; |
|---|
| 5 | import javax.swing.JButton; |
|---|
| 6 | import static junit.framework.Assert.assertEquals; |
|---|
| 7 | import static junit.framework.Assert.assertFalse; |
|---|
| 8 | import static junit.framework.Assert.assertTrue; |
|---|
| 9 | import static junit.framework.Assert.fail; |
|---|
| 10 | import org.uispec4j.Panel; |
|---|
| 11 | import org.uispec4j.TextBox; |
|---|
| 12 | import org.uispec4j.Trigger; |
|---|
| 13 | import org.uispec4j.UISpecTestCase; |
|---|
| 14 | import org.uispec4j.Window; |
|---|
| 15 | import org.uispec4j.interception.WindowInterceptor; |
|---|
| 16 | import tmcsim.cadsimulator.CADSimulator; |
|---|
| 17 | import tmcsim.common.ScriptException; |
|---|
| 18 | import tmcsim.common.SimulationException; |
|---|
| 19 | |
|---|
| 20 | /** |
|---|
| 21 | * Smoke Test of system. Start the CAD server, Start the Sim Mgr, see if the Sim |
|---|
| 22 | * Mgr view shows "No Script". |
|---|
| 23 | * |
|---|
| 24 | * @author jdalbey |
|---|
| 25 | */ |
|---|
| 26 | public class SimulationManagerSmokeTest extends UISpecTestCase |
|---|
| 27 | { |
|---|
| 28 | |
|---|
| 29 | SimulationManager simMgrApp; |
|---|
| 30 | CADSimulator engine; |
|---|
| 31 | |
|---|
| 32 | public SimulationManagerSmokeTest(String testName) |
|---|
| 33 | { |
|---|
| 34 | super(testName); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | /** |
|---|
| 38 | * Call constructors for both classes |
|---|
| 39 | */ |
|---|
| 40 | public void testBothGUIs() throws ScriptException, SimulationException |
|---|
| 41 | { |
|---|
| 42 | System.out.println("Smoke Test Sim Mgr & CADSimulator"); |
|---|
| 43 | |
|---|
| 44 | Window cadwindow = null; |
|---|
| 45 | System.setProperty("CAD_SIM_PROPERTIES", "config/cad_simulator_smoketest_config.properties"); |
|---|
| 46 | if (System.getProperty("CAD_SIM_PROPERTIES") != null) |
|---|
| 47 | { |
|---|
| 48 | cadwindow = WindowInterceptor.run(new Trigger() |
|---|
| 49 | { |
|---|
| 50 | public void run() |
|---|
| 51 | { |
|---|
| 52 | try |
|---|
| 53 | { |
|---|
| 54 | engine = new CADSimulator(System.getProperty("CAD_SIM_PROPERTIES")); |
|---|
| 55 | } catch (Exception e) |
|---|
| 56 | { |
|---|
| 57 | fail("Couldn't launch CADSimulator"); |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | }); |
|---|
| 61 | } |
|---|
| 62 | else |
|---|
| 63 | { |
|---|
| 64 | fail("CAD_SIM_PROPERTIES system property not defined."); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | // Check CAD Simulator appears with no script and nothing connected |
|---|
| 68 | assertTrue("Window title incorrect", cadwindow.getTitle().startsWith("CAD Simulator")); |
|---|
| 69 | Panel mainPanel = cadwindow.getPanel("contentPane"); |
|---|
| 70 | TextBox txtStatus = mainPanel.getTextBox("simulationStatus"); |
|---|
| 71 | assertEquals("No Script", txtStatus.getText()); |
|---|
| 72 | TextBox terms = mainPanel.getTextBox("termConnectedTF"); |
|---|
| 73 | assertEquals("0", terms.getText().trim()); |
|---|
| 74 | assertEquals("No", mainPanel.getTextBox("managerConnectedTF").getText().trim()); |
|---|
| 75 | |
|---|
| 76 | Window simMgrWindow = null; |
|---|
| 77 | System.setProperty("SIM_MGR_PROPERTIES", "config/sim_manager_smoketest_config.properties"); |
|---|
| 78 | if (System.getProperty("SIM_MGR_PROPERTIES") != null) |
|---|
| 79 | { |
|---|
| 80 | simMgrWindow = WindowInterceptor.run(new Trigger() |
|---|
| 81 | { |
|---|
| 82 | public void run() |
|---|
| 83 | { |
|---|
| 84 | try |
|---|
| 85 | { |
|---|
| 86 | simMgrApp = new SimulationManager(System.getProperty("SIM_MGR_PROPERTIES")); |
|---|
| 87 | } catch (Exception ex) |
|---|
| 88 | { |
|---|
| 89 | fail("Couldn't launch Simulation Manager"); |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | }); |
|---|
| 93 | } |
|---|
| 94 | else |
|---|
| 95 | { |
|---|
| 96 | fail("SIM_MGR_PROPERTIES system property not defined."); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | // Check that the Sim Mgr GUI appears without a script loaded yet |
|---|
| 100 | SimulationManagerView view = simMgrApp.theSimManagerView; |
|---|
| 101 | assertFalse(view.isSimulationStarted()); |
|---|
| 102 | Window win = new Window(view); |
|---|
| 103 | Panel contentPanel = win.getPanel("contentPane"); |
|---|
| 104 | TextBox txtSimStatus = contentPanel.getTextBox("simulationStatusText"); |
|---|
| 105 | assertEquals("No Script", txtSimStatus.getText()); |
|---|
| 106 | |
|---|
| 107 | assertEquals("Yes", mainPanel.getTextBox("managerConnectedTF").getText().trim()); |
|---|
| 108 | |
|---|
| 109 | // Load a script file |
|---|
| 110 | String autoloadScriptname = "scripts/practice_script_2016.xml"; |
|---|
| 111 | SimulationManagerModel simMgrModel = simMgrApp.theSimManagerModel; |
|---|
| 112 | simMgrModel.loadScript(new File(autoloadScriptname)); |
|---|
| 113 | // The status should now say Ready |
|---|
| 114 | assertEquals("Ready", txtSimStatus.getText()); |
|---|
| 115 | |
|---|
| 116 | // Click "Start" |
|---|
| 117 | win.getButton("Start").click(); |
|---|
| 118 | try |
|---|
| 119 | { |
|---|
| 120 | Thread.sleep(200); |
|---|
| 121 | } catch (Exception ex) |
|---|
| 122 | { |
|---|
| 123 | ex.printStackTrace(); |
|---|
| 124 | } |
|---|
| 125 | assertEquals("Running", txtSimStatus.getText()); |
|---|
| 126 | |
|---|
| 127 | //List all available buttons |
|---|
| 128 | Component[] buttons = win.getSwingComponents(JButton.class); |
|---|
| 129 | for (Component comp : buttons) |
|---|
| 130 | { |
|---|
| 131 | System.out.println(comp); |
|---|
| 132 | } |
|---|
| 133 | win.getButton("Load Script"); |
|---|
| 134 | win.getButton("Pause"); |
|---|
| 135 | win.getButton("Disconnect from Paramics"); |
|---|
| 136 | win.getButton("Reset"); |
|---|
| 137 | win.getButton("Load Network"); |
|---|
| 138 | // Quit |
|---|
| 139 | engine = null; |
|---|
| 140 | win.getMenuBar().getMenu("File").getSubMenu("Exit").click(); |
|---|
| 141 | //simMgrApp = null; |
|---|
| 142 | } |
|---|
| 143 | } |
|---|