package tmcsim.cadsimulator; import java.rmi.RemoteException; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.fail; import org.uispec4j.*; import org.uispec4j.interception.WindowInterceptor; import tmcsim.client.CADClient; import tmcsim.client.cadclientgui.data.Incident; import tmcsim.client.cadclientgui.data.IncidentEvent; import tmcsim.common.CADEnums; import tmcsim.common.SimulationException; import tmcsim.interfaces.CADClientInterface; import tmcsim.interfaces.SimulationManagerInterface; /** * Test of CADSimulator GUI * * @author jdalbey */ public class CADSimulatorTest extends UISpecTestCase { public CADSimulatorTest(String testName) { super(testName); } /** * Test of getCADTime method, of class CADSimulator. */ public void testGetCADTime() { System.out.println("getCADTime"); String result = CADSimulator.getCADTime(); // Just test length for now assertEquals(4, result.length()); } /** * Test of getCADDate method, of class CADSimulator. */ public void testGetCADDate() { System.out.println("getCADDate"); String result = CADSimulator.getCADDate(); // Just test length for now assertEquals(6, result.length()); } /** * Test of main method, of class CADSimulator. */ CADSimulator app; public void testConstructor() throws SimulationException, RemoteException { System.out.println("CADSimulator constructor"); System.setProperty("CAD_SIM_PROPERTIES", "config/cad_simulator_config.properties"); Window cadwindow = null; if (System.getProperty("CAD_SIM_PROPERTIES") != null) { cadwindow = WindowInterceptor.run(new Trigger() { public void run() { try { app = new CADSimulator(System.getProperty("CAD_SIM_PROPERTIES")); } catch (Exception e) { fail("Couldn't launch CADSimulator"); } } }); } else { fail("CAD_SIM_PROPERTIES system property not defined."); } assertEquals("CAD Simulator", cadwindow.getTitle()); Panel mainPanel = cadwindow.getPanel("contentPane"); TextBox txtStatus = mainPanel.getTextBox("simulationStatus"); assertEquals("No Script", txtStatus.getText()); TextBox terminals = mainPanel.getTextBox("termConnectedTF"); assertEquals("0", terminals.getText().trim()); assertEquals("No", mainPanel.getTextBox("managerConnectedTF").getText().trim()); CADClientInterface ci = new CADSimulatorTest.FakeClient(); app.theCoordinator.registerForCallback(ci); assertEquals("1", terminals.getText().trim()); app.theCoordinator.registerForCallback(ci); assertEquals("2", terminals.getText().trim()); SimulationManagerInterface si = new CADSimulatorTest.FakeSimMgr(); app.theCoordinator.registerForCallback(si); assertEquals("Yes", mainPanel.getTextBox("managerConnectedTF").getText().trim()); app = null; // app.theViewer.dispose(); // Window confirmPopup = null; // confirmPopup = WindowInterceptor.run(new Trigger() // { // public void run() // { // app.theViewer.closeViewer(); // } // }); // confirmPopup.getButton("OK").click(); } class FakeClient implements CADClientInterface { @Override public void refresh() throws RemoteException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } } class FakeSimMgr implements SimulationManagerInterface { @Override public void tick(long theTime) throws RemoteException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void eventOccured(Integer logNumber, IncidentEvent theEvent) throws RemoteException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void incidentAdded(Incident newIncident) throws RemoteException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void incidentStarted(Integer logNumber) throws RemoteException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void incidentRemoved(Integer logNumber) throws RemoteException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void setScriptStatus(CADEnums.SCRIPT_STATUS newStatus) throws RemoteException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void setParamicsStatus(CADEnums.PARAMICS_STATUS newStatus) throws RemoteException { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } } }