source: tmcsimulator/trunk/test/tmcsim/cadsimulator/CADSimulatorTest.java @ 5

Revision 5, 5.8 KB checked in by jdalbey, 10 years ago (diff)

CADSimulatorTest: added test of info messages text area.

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