| 1 | package tmcsim.cadsimulator; |
|---|
| 2 | |
|---|
| 3 | import java.rmi.RemoteException; |
|---|
| 4 | import static junit.framework.Assert.assertEquals; |
|---|
| 5 | import static junit.framework.Assert.fail; |
|---|
| 6 | import org.uispec4j.*; |
|---|
| 7 | import org.uispec4j.interception.WindowInterceptor; |
|---|
| 8 | import tmcsim.client.CADClient; |
|---|
| 9 | import tmcsim.client.cadclientgui.data.Incident; |
|---|
| 10 | import tmcsim.client.cadclientgui.data.IncidentEvent; |
|---|
| 11 | import tmcsim.common.CADEnums; |
|---|
| 12 | import tmcsim.common.SimulationException; |
|---|
| 13 | import tmcsim.interfaces.CADClientInterface; |
|---|
| 14 | import tmcsim.interfaces.SimulationManagerInterface; |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * Test of CADSimulator GUI |
|---|
| 18 | * |
|---|
| 19 | * @author jdalbey |
|---|
| 20 | */ |
|---|
| 21 | public class CADSimulatorTest extends UISpecTestCase |
|---|
| 22 | { |
|---|
| 23 | |
|---|
| 24 | public CADSimulatorTest(String testName) |
|---|
| 25 | { |
|---|
| 26 | super(testName); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * Test of getCADTime method, of class CADSimulator. |
|---|
| 31 | */ |
|---|
| 32 | public void testGetCADTime() |
|---|
| 33 | { |
|---|
| 34 | System.out.println("getCADTime"); |
|---|
| 35 | String result = CADSimulator.getCADTime(); |
|---|
| 36 | // Just test length for now |
|---|
| 37 | assertEquals(4, result.length()); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | * Test of getCADDate method, of class CADSimulator. |
|---|
| 42 | */ |
|---|
| 43 | public void testGetCADDate() |
|---|
| 44 | { |
|---|
| 45 | System.out.println("getCADDate"); |
|---|
| 46 | String result = CADSimulator.getCADDate(); |
|---|
| 47 | // Just test length for now |
|---|
| 48 | assertEquals(6, result.length()); |
|---|
| 49 | } |
|---|
| 50 | /** |
|---|
| 51 | * Test of main method, of class CADSimulator. |
|---|
| 52 | */ |
|---|
| 53 | CADSimulator app; |
|---|
| 54 | |
|---|
| 55 | public void testConstructor() throws SimulationException, RemoteException |
|---|
| 56 | { |
|---|
| 57 | System.out.println("CADSimulator constructor"); |
|---|
| 58 | System.setProperty("CAD_SIM_PROPERTIES", "config/cad_simulator_config.properties"); |
|---|
| 59 | Window cadwindow = null; |
|---|
| 60 | if (System.getProperty("CAD_SIM_PROPERTIES") != null) |
|---|
| 61 | { |
|---|
| 62 | cadwindow = WindowInterceptor.run(new Trigger() |
|---|
| 63 | { |
|---|
| 64 | public void run() |
|---|
| 65 | { |
|---|
| 66 | try |
|---|
| 67 | { |
|---|
| 68 | app = new CADSimulator(System.getProperty("CAD_SIM_PROPERTIES")); |
|---|
| 69 | } catch (Exception e) |
|---|
| 70 | { |
|---|
| 71 | fail("Couldn't launch CADSimulator"); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | }); |
|---|
| 75 | } else |
|---|
| 76 | { |
|---|
| 77 | fail("CAD_SIM_PROPERTIES system property not defined."); |
|---|
| 78 | } |
|---|
| 79 | assertEquals("CAD Simulator", cadwindow.getTitle()); |
|---|
| 80 | Panel mainPanel = cadwindow.getPanel("contentPane"); |
|---|
| 81 | TextBox txtStatus = mainPanel.getTextBox("simulationStatus"); |
|---|
| 82 | assertEquals("No Script", txtStatus.getText()); |
|---|
| 83 | TextBox terminals = mainPanel.getTextBox("termConnectedTF"); |
|---|
| 84 | assertEquals("0", terminals.getText().trim()); |
|---|
| 85 | assertEquals("No", mainPanel.getTextBox("managerConnectedTF").getText().trim()); |
|---|
| 86 | |
|---|
| 87 | CADClientInterface ci = new CADSimulatorTest.FakeClient(); |
|---|
| 88 | app.theCoordinator.registerForCallback(ci); |
|---|
| 89 | assertEquals("1", terminals.getText().trim()); |
|---|
| 90 | app.theCoordinator.registerForCallback(ci); |
|---|
| 91 | assertEquals("2", terminals.getText().trim()); |
|---|
| 92 | |
|---|
| 93 | SimulationManagerInterface si = new CADSimulatorTest.FakeSimMgr(); |
|---|
| 94 | app.theCoordinator.registerForCallback(si); |
|---|
| 95 | assertEquals("Yes", mainPanel.getTextBox("managerConnectedTF").getText().trim()); |
|---|
| 96 | |
|---|
| 97 | app = null; |
|---|
| 98 | // app.theViewer.dispose(); |
|---|
| 99 | // Window confirmPopup = null; |
|---|
| 100 | // confirmPopup = WindowInterceptor.run(new Trigger() |
|---|
| 101 | // { |
|---|
| 102 | // public void run() |
|---|
| 103 | // { |
|---|
| 104 | // app.theViewer.closeViewer(); |
|---|
| 105 | // } |
|---|
| 106 | // }); |
|---|
| 107 | // confirmPopup.getButton("OK").click(); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | class FakeClient implements CADClientInterface |
|---|
| 111 | { |
|---|
| 112 | @Override |
|---|
| 113 | public void refresh() throws RemoteException |
|---|
| 114 | { |
|---|
| 115 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | } |
|---|
| 119 | class FakeSimMgr implements SimulationManagerInterface |
|---|
| 120 | { |
|---|
| 121 | @Override |
|---|
| 122 | public void tick(long theTime) throws RemoteException |
|---|
| 123 | { |
|---|
| 124 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | @Override |
|---|
| 128 | public void eventOccured(Integer logNumber, IncidentEvent theEvent) throws RemoteException |
|---|
| 129 | { |
|---|
| 130 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | @Override |
|---|
| 134 | public void incidentAdded(Incident newIncident) throws RemoteException |
|---|
| 135 | { |
|---|
| 136 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | @Override |
|---|
| 140 | public void incidentStarted(Integer logNumber) throws RemoteException |
|---|
| 141 | { |
|---|
| 142 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | @Override |
|---|
| 146 | public void incidentRemoved(Integer logNumber) throws RemoteException |
|---|
| 147 | { |
|---|
| 148 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | @Override |
|---|
| 152 | public void setScriptStatus(CADEnums.SCRIPT_STATUS newStatus) throws RemoteException |
|---|
| 153 | { |
|---|
| 154 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | @Override |
|---|
| 158 | public void setParamicsStatus(CADEnums.PARAMICS_STATUS newStatus) throws RemoteException |
|---|
| 159 | { |
|---|
| 160 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | } |
|---|