Warning: Can't use blame annotator:
svn blame failed on trunk/test/tmcsim/cadsimulator/CADSimulatorGUITest.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/test/tmcsim/cadsimulator/CADSimulatorGUITest.java @ 34

Revision 34, 6.6 KB checked in by bokumura, 10 years ago (diff)

Change unit tests to work with the new config directory restructure.

RevLine 
1package tmcsim.cadsimulator;
2
3import java.io.File;
4import java.rmi.RemoteException;
5import java.util.logging.Level;
6import java.util.logging.Logger;
7
8import static junit.framework.Assert.assertEquals;
9import static junit.framework.Assert.fail;
10import static org.mockito.Mockito.*;
11import org.uispec4j.*;
12import org.uispec4j.interception.WindowInterceptor;
13import tmcsim.cadsimulator.managers.ParamicsSimulationManager;
14import tmcsim.common.CADEnums;
15import tmcsim.common.ScriptException;
16import tmcsim.common.SimulationException;
17import tmcsim.interfaces.CADClientInterface;
18import tmcsim.interfaces.SimulationManagerInterface;
19
20/**
21 * Test of CADSimulator GUI
22 *
23 * @author jdalbey
24 */
25public class CADSimulatorGUITest extends UISpecTestCase
26{
27
28    static final String configData =
29            "CADClientPort          = 4444 \n"
30            + "CoordinatorRMIPort     = 4445 \n"
31            + "CADRmiPort             = 4446 \n"
32            + "UserInterface          = tmcsim.cadsimulator.viewer.CADSimulatorViewer\n"
33            + "ParamicsProperties     = pconfig.txt\n"
34            + "ATMSProperties         = empty.txt\n"
35            + "MediaProperties        = empty.txt\n";
36
37    public CADSimulatorGUITest(String testName)
38    {
39        super(testName);
40    }
41
42    @Override
43    public void tearDown() throws java.io.IOException
44    {
45        File removeMe = new File("config.txt");
46        removeMe.delete();
47        removeMe = new File("pconfig.txt");
48        removeMe.delete();
49        removeMe = new File("empty.txt");
50        removeMe.delete();
51    }
52
53    /**
54     * Test of getCADTime method, of class CADSimulator.
55     */
56    public void testGetCADTime()
57    {
58        System.out.println("getCADTime");
59        String result = CADSimulator.getCADTime();
60        // Just test length for now
61        assertEquals(4, result.length());
62    }
63
64    /**
65     * Test of getCADDate method, of class CADSimulator.
66     */
67    public void testGetCADDate()
68    {
69        System.out.println("getCADDate");
70        String result = CADSimulator.getCADDate();
71        // Just test length for now
72        assertEquals(6, result.length());
73    }
74    /**
75     * Test of main method, of class CADSimulator.
76     */
77    CADSimulator app;
78
79    public void testConstructor() throws SimulationException, RemoteException, ScriptException
80    {
81        CADSimulatorFixture.writeConfigData();
82        CADSimulatorFixture.writedata("config.txt", configData);
83        System.out.println("CADSimulator constructor");
84        System.setProperty("CONFIG_DIR", "config/testConfig");
85        Window cadwindow = null;
86        if (System.getProperty("CONFIG_DIR") != null)
87        {
88            cadwindow = WindowInterceptor.run(new Trigger()
89            {
90                public void run()
91                {
92                    try
93                    {
94                        app = new CADSimulator(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + "cad_simulator_config.properties");
95
96                    } catch (Exception e)
97                    {
98                        fail("Couldn't launch CADSimulator" + e.getMessage());
99                    }
100                }
101            });
102        } else
103        {
104            fail("CONFIG_DIR system property not defined.");
105        }
106        assertEquals("CAD Simulator", cadwindow.getTitle());
107        Panel mainPanel = cadwindow.getPanel("contentPane");
108        TextBox txtStatus = mainPanel.getTextBox("simulationStatus");
109        assertEquals("No Script", txtStatus.getText());
110        TextBox terminals = mainPanel.getTextBox("termConnectedTF");
111        assertEquals("0", terminals.getText().trim());
112        assertEquals("No", mainPanel.getTextBox("managerConnectedTF").getText().trim());
113        assertEquals("0:00:00", mainPanel.getTextBox("simulationClockLabel").getText());
114
115        CADClientInterface ci = new FakeClient();
116        app.theCoordinator.registerForCallback(ci);
117        assertEquals("1", terminals.getText().trim());
118        app.theCoordinator.registerForCallback(ci);
119        assertEquals("2", terminals.getText().trim());
120
121        SimulationManagerInterface si = mock(SimulationManagerInterface.class);
122        app.theCoordinator.registerForCallback(si);
123        assertEquals("Yes", mainPanel.getTextBox("managerConnectedTF").getText().trim());
124
125        Logger cadSimLogger = Logger.getLogger("tmcsim.cadsimulator");
126        cadSimLogger.logp(Level.INFO, "", "", "Sample Info Message.");
127
128        Panel infoPane = mainPanel.getPanel("infoMessagesPane");
129        TextBox infoText = infoPane.getTextBox("infoMessagesTA");
130        assertEquals(". = Sample Info Message.", infoText.getText().trim());
131
132        cadSimLogger.logp(Level.SEVERE, "", "", "Sample Error Message.");
133
134        Panel errPane = mainPanel.getPanel("errorMessagesPane");
135        TextBox errText = errPane.getTextBox("errorMessagesTA");
136        assertEquals(". = Sample Error Message.", errText.getText().trim());
137
138        app.theCoordinator.setParamicsStatus(CADEnums.PARAMICS_STATUS.CONNECTED);
139        CADSimulatorFixture.pause(500);
140        assertEquals("Yes", mainPanel.getTextBox("paramicsConnectedTF").getText().trim());
141        assertEquals("None", mainPanel.getTextBox("networkLoadedTF").getText().trim());
142
143//        app.theCoordinator.setScriptStatus(CADEnums.SCRIPT_STATUS.SCRIPT_RUNNING);
144//        assertEquals("Running", mainPanel.getTextBox("simulationStatus").getText().trim());
145
146        // Load a script file
147        String autoloadScriptname = "scripts/one-incident.xml";
148        app.theCoordinator.loadScriptFile(new File(autoloadScriptname));
149        // The status should now say Ready
150        assertEquals("Ready", mainPanel.getTextBox("simulationStatus").getText().trim());
151
152        app.theCoordinator.startSimulation();
153        CADSimulatorFixture.pause(500);
154        assertEquals("Running", mainPanel.getTextBox("simulationStatus").getText().trim());
155        assertEquals("0:00:01", mainPanel.getTextBox("simulationClockLabel").getText());
156
157        ParamicsSimulationManager psm = mock(ParamicsSimulationManager.class);
158        when(psm.isConnected()).thenReturn(Boolean.TRUE);
159        app.theParamicsSimMgr = psm;
160        app.theCoordinator.loadParamicsNetwork(1);
161
162//        app.theViewer.dispose();
163//        Window confirmPopup = null;
164//        confirmPopup = WindowInterceptor.run(new Trigger()
165//        {
166//            public void run()
167//            {
168//                app.theViewer.closeViewer();
169//            }
170//        });
171//        confirmPopup.getButton("OK").click();
172    }
173
174    class FakeClient implements CADClientInterface
175    {
176
177        @Override
178        public void refresh() throws RemoteException
179        {
180        }
181    }
182}
Note: See TracBrowser for help on using the repository browser.