| 1 | package tmcsim.cadsimulator.viewer; |
|---|
| 2 | |
|---|
| 3 | import java.util.logging.Level; |
|---|
| 4 | import java.util.logging.Logger; |
|---|
| 5 | import org.uispec4j.*; |
|---|
| 6 | import tmcsim.cadsimulator.viewer.model.CADSimulatorModel; |
|---|
| 7 | import tmcsim.common.CADEnums; |
|---|
| 8 | |
|---|
| 9 | /** |
|---|
| 10 | * |
|---|
| 11 | * @author jdalbey |
|---|
| 12 | */ |
|---|
| 13 | public class CADSimulatorViewModelTest extends junit.framework.TestCase //extends UISpecTestCase |
|---|
| 14 | { |
|---|
| 15 | |
|---|
| 16 | CADSimulatorViewer viewer; |
|---|
| 17 | Window cadwindow; |
|---|
| 18 | CADSimulatorModel model; |
|---|
| 19 | Panel mainPanel; |
|---|
| 20 | |
|---|
| 21 | public CADSimulatorViewModelTest(String testName) |
|---|
| 22 | { |
|---|
| 23 | super(testName); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | @Override |
|---|
| 27 | protected void setUp() throws Exception |
|---|
| 28 | { |
|---|
| 29 | super.setUp(); |
|---|
| 30 | viewer = new CADSimulatorViewer(); |
|---|
| 31 | cadwindow = new Window(viewer); |
|---|
| 32 | model = new CADSimulatorModel(); |
|---|
| 33 | model.addObserver(viewer); |
|---|
| 34 | mainPanel = cadwindow.getPanel("contentPane"); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | public void testInitialView() |
|---|
| 38 | { |
|---|
| 39 | String actual; |
|---|
| 40 | assertTrue("Title bar incorrect", cadwindow.getTitle().trim().startsWith("CAD Simulator")); |
|---|
| 41 | TextBox txtStatus = mainPanel.getTextBox("simulationStatus"); |
|---|
| 42 | actual = txtStatus.getText().trim(); |
|---|
| 43 | assertEquals("simulation status should say No Script", "No Script", actual); |
|---|
| 44 | TextBox terminals = mainPanel.getTextBox("termConnectedTF"); |
|---|
| 45 | actual = terminals.getText().trim(); |
|---|
| 46 | assertEquals("should be 0 terminals", "0", actual); |
|---|
| 47 | actual = mainPanel.getTextBox("managerConnectedTF").getText().trim(); |
|---|
| 48 | assertEquals("mgr connected should be no", "No", actual); |
|---|
| 49 | actual = mainPanel.getTextBox("paramicsConnectedTF").getText().trim(); |
|---|
| 50 | assertEquals("paramics connected should be no", "No", actual); |
|---|
| 51 | actual = mainPanel.getTextBox("simulationClockLabel").getText().trim(); |
|---|
| 52 | assertEquals("initial time should be 0:00:00", "0:00:00", actual); |
|---|
| 53 | actual = mainPanel.getTextBox("networkLoadedTF").getText().trim(); |
|---|
| 54 | assertEquals("network id should be None", "None", actual); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | public void testClients() |
|---|
| 58 | { |
|---|
| 59 | String actual; |
|---|
| 60 | model.connectClient(); |
|---|
| 61 | TextBox terminals = mainPanel.getTextBox("termConnectedTF"); |
|---|
| 62 | assertEquals(1, model.getNumClients()); |
|---|
| 63 | assertEquals("should be 1 terminal", "1", terminals.getText().trim()); |
|---|
| 64 | model.connectClient(); |
|---|
| 65 | assertEquals("should be 2 terminals", "2", terminals.getText().trim()); |
|---|
| 66 | model.disconnectClient(); |
|---|
| 67 | assertEquals("should be 1 terminal after disconnect", "1", terminals.getText().trim()); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | public void testSimMgr() |
|---|
| 71 | { |
|---|
| 72 | String actual; |
|---|
| 73 | model.setSimManagerStatus(true); |
|---|
| 74 | actual = mainPanel.getTextBox("managerConnectedTF").getText().trim(); |
|---|
| 75 | assertEquals("mgr connected should be yes", "Yes", actual); |
|---|
| 76 | assertTrue(model.isSimManagerConnected()); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | public void testMessagePanes() |
|---|
| 80 | { |
|---|
| 81 | String actual; |
|---|
| 82 | System.out.println("Tests for message panes."); |
|---|
| 83 | Logger cadSimLogger = Logger.getLogger("tmcsim.cadsimulator"); |
|---|
| 84 | cadSimLogger.logp(Level.INFO, "", "", "Sample Info Message."); |
|---|
| 85 | Panel infoPane = mainPanel.getPanel("infoMessagesPane"); |
|---|
| 86 | TextBox infoText = infoPane.getTextBox("infoMessagesTA"); |
|---|
| 87 | actual = infoText.getText().trim(); |
|---|
| 88 | assertEquals("wrong info msg text", ". = Sample Info Message.", actual); |
|---|
| 89 | |
|---|
| 90 | cadSimLogger.logp(Level.SEVERE, "", "", "Sample Error Message."); |
|---|
| 91 | |
|---|
| 92 | Panel errPane = mainPanel.getPanel("errorMessagesPane"); |
|---|
| 93 | TextBox errText = errPane.getTextBox("errorMessagesTA"); |
|---|
| 94 | actual = errText.getText().trim(); |
|---|
| 95 | assertEquals("wrong error msg text", ". = Sample Error Message.", actual); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | public void testStatusChg() |
|---|
| 99 | { |
|---|
| 100 | String actual; |
|---|
| 101 | System.out.println("Tests for status changes."); |
|---|
| 102 | model.setParamicsStatus(CADEnums.PARAMICS_STATUS.CONNECTED); |
|---|
| 103 | pause(500); |
|---|
| 104 | actual = mainPanel.getTextBox("paramicsConnectedTF").getText().trim(); |
|---|
| 105 | assertEquals("paramics connected should be yes", "Yes", actual); |
|---|
| 106 | actual = mainPanel.getTextBox("networkLoadedTF").getText().trim(); |
|---|
| 107 | assertEquals("network id should be None", "None", actual); |
|---|
| 108 | |
|---|
| 109 | model.setScriptStatus(CADEnums.SCRIPT_STATUS.SCRIPT_STOPPED_NOT_STARTED); |
|---|
| 110 | |
|---|
| 111 | // The status should now say Ready |
|---|
| 112 | actual = mainPanel.getTextBox("simulationStatus").getText().trim(); |
|---|
| 113 | assertEquals("sim status should be ready", "Ready", actual); |
|---|
| 114 | |
|---|
| 115 | model.setScriptStatus(CADEnums.SCRIPT_STATUS.SCRIPT_RUNNING); |
|---|
| 116 | model.setTime(61L); |
|---|
| 117 | actual = mainPanel.getTextBox("simulationStatus").getText().trim(); |
|---|
| 118 | assertEquals("sim status should be running", "Running", actual); |
|---|
| 119 | actual = mainPanel.getTextBox("simulationClockLabel").getText().trim(); |
|---|
| 120 | assertEquals("sim time should be 0:01:01", "0:01:01", actual); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | public void testNetworkID() |
|---|
| 124 | { |
|---|
| 125 | String actual; |
|---|
| 126 | // this will tell the model it has a new network ID |
|---|
| 127 | model.setParamicsNetworkLoaded("1"); |
|---|
| 128 | model.setParamicsStatus(CADEnums.PARAMICS_STATUS.LOADED); |
|---|
| 129 | pause(500); |
|---|
| 130 | actual = mainPanel.getTextBox("networkLoadedTF").getText().trim(); |
|---|
| 131 | assertEquals("network id should be 1", "1", actual); |
|---|
| 132 | |
|---|
| 133 | // model.updateDVDStatus(new DVDStatusUpdate("1", false, new Throwable())); |
|---|
| 134 | |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | public static void pause(int millis) |
|---|
| 138 | { |
|---|
| 139 | try |
|---|
| 140 | { |
|---|
| 141 | Thread.sleep(millis); |
|---|
| 142 | } catch (InterruptedException ex) |
|---|
| 143 | { |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | } |
|---|