source: tmcsimulator/trunk/test/tmcsim/cadsimulator/CADSimulatorConsoleDriver.java @ 558

Revision 558, 7.7 KB checked in by jdalbey, 6 years ago (diff)

Change hardcoded "scripts" as name of folder to a constant in SimulationManager?. See #228.

Line 
1package tmcsim.cadsimulator;
2
3import java.io.File;
4import java.io.IOException;
5import java.util.logging.Level;
6import java.util.logging.Logger;
7import junit.framework.TestCase;
8import static org.mockito.Mockito.mock;
9import static tmcsim.cadsimulator.CADSimulatorFixture.writedata;
10import tmcsim.common.CADEnums;
11import tmcsim.common.ScriptException;
12import tmcsim.common.SimulationException;
13import tmcsim.interfaces.CADClientInterface;
14import tmcsim.interfaces.SimulationManagerInterface;
15import static tmcsim.simulationmanager.SimulationManager.kScenarioFolder;
16
17/**
18 * Driver for CADSimulator Console - output to stdout.
19 *
20 * @author jdalbey
21 */
22public class CADSimulatorConsoleDriver extends TestCase
23{
24
25    static CADServer app;
26    static final String configData =
27            "CADClientPort          = 4444 \n"
28            + "CoordinatorRMIPort     = 4445 \n"
29            + "CADRmiPort             = 4446 \n"
30            + "UserInterface          = tmcsim.cadsimulator.viewer.CADConsoleViewer\n"
31            + "ParamicsProperties     = pconfig.txt\n"
32            + "ATMSProperties         = empty.txt\n"
33            + "MediaProperties        = empty.txt\n";
34    static final String paramicsData = "ParamicsCommHost       = 192.168.251.45\n"
35            + "ParamicsCommPort       = 4450\n"
36            + "IncidentUpdateInterval = 30\n"
37            + "IncidentUpdateFile     = exchange.xml\n"
38            + "ParamicsStatusInterval = 15\n"
39            + "ParamicsStatusFile     = paramics_status.xml\n"
40            + "CameraStatusInterval   = 30\n"
41            + "CameraStatusFile       = camera_status.xml\n";
42    /*
43     * Creating instance of app must be done only once or you get registry
44     * bind problems, and code Written in Constructor is Executed
45     * before each Test Method
46     */
47
48    public static void main(String[] args) throws IOException, SimulationException, ScriptException
49    {
50        writedata("config.txt", configData);
51        writedata("pconfig.txt", paramicsData);
52        writedata("empty.txt", "");
53        CADSimulatorFixture.writeScriptfiles();
54        CADSimulatorFixture.startCADSim();
55        (new CADSimulatorConsoleDriver()).testAll();
56        System.exit(0);
57    }
58    // Write the test data to a file
59
60    private void testAll() throws java.io.IOException, SimulationException, ScriptException
61    {
62
63        CADClientInterface ci = mock(CADClientInterface.class); //new tmcsim.cadsimulator.CADSimulatorDriver.FakeClient();
64        app.theCoordinator.registerForCallback(ci);
65        // Convert the output stream into a string we can test.
66
67        app.theCoordinator.registerForCallback(ci);
68
69        SimulationManagerInterface si = mock(SimulationManagerInterface.class);
70
71        app.theCoordinator.registerForCallback(si);
72
73        Logger cadSimLogger = Logger.getLogger("tmcsim.cadsimulator");
74        cadSimLogger.logp(Level.INFO, "", "", "Sample Info Message.");
75
76        app.theCoordinator.setParamicsStatus(CADEnums.PARAMICS_STATUS.CONNECTED);
77        CADSimulatorFixture.pause(500);
78
79        // Show loaded, and ALSO update the current network id
80        app.theCoordinator.setParamicsStatus(CADEnums.PARAMICS_STATUS.LOADED);
81        CADSimulatorFixture.pause(500);
82
83        app.theCoordinator.setScriptStatus(CADEnums.SCRIPT_STATUS.SCRIPT_RUNNING);
84        CADSimulatorFixture.pause(500);
85
86        cadSimLogger.logp(Level.SEVERE, "Someclass", "Somemethod", "Sample error message.");
87
88        // Load a script file
89        String autoloadScriptname = kScenarioFolder+"/one-incident.xml";
90        app.theCoordinator.loadScriptFile(new File(autoloadScriptname));
91        // The status should now say Ready
92
93
94//        ParamicsSimulationManager psm = mock(ParamicsSimulationManager.class);
95//        when(psm.isConnected()).thenReturn(Boolean.TRUE, Boolean.FALSE);
96//        app.theParamicsSimMgr = psm;
97//        app.theCoordinator.connectToParamics();
98//        app.theCoordinator.loadParamicsNetwork(1);
99//        CADSimulatorFixture.pause(500);
100//        app.theCoordinator.disconnectFromParamics();
101//        CADSimulatorFixture.pause(500);
102
103        app.theCoordinator.startSimulation();
104        CADSimulatorFixture.pause(1500);
105        app.theCoordinator.pauseSimulation();
106        app = null;
107        cleanup();
108    }
109
110    private void cleanup()
111    {
112        File removeMe = new File("config.txt");
113        removeMe.delete();
114        removeMe = new File("pconfig.txt");
115        removeMe.delete();
116        removeMe = new File("empty.txt");
117        removeMe.delete();
118    }
119    String expected1 =
120            "--- CAD Simulator ---\n"
121            + "Elapsed Simulation Time     : 0:00:00\n"
122            + "Status                      : No Script\n"
123            + "Connected CAD Terminals     : 0\n"
124            + "Simulation Manager Connected: No\n"
125            + "Connected to Paramics       : No\n"
126            + "Network Loaded              : \n"
127            + "-- Info Messages --\n\n"
128            + "-- Error Messages --\n\n";
129    String expected2 =
130            "--- CAD Simulator ---\n"
131            + "Elapsed Simulation Time     : 0:00:00\n"
132            + "Status                      : No Script\n"
133            + "Connected CAD Terminals     : 1\n"
134            + "Simulation Manager Connected: No\n"
135            + "Connected to Paramics       : No\n"
136            + "Network Loaded              : \n"
137            + "-- Info Messages --\n\n"
138            + "-- Error Messages --\n\n";
139    String expected3 =
140            "--- CAD Simulator ---\n"
141            + "Elapsed Simulation Time     : 0:00:00\n"
142            + "Status                      : No Script\n"
143            + "Connected CAD Terminals     : 2\n"
144            + "Simulation Manager Connected: No\n"
145            + "Connected to Paramics       : No\n"
146            + "Network Loaded              : \n"
147            + "-- Info Messages --\n\n"
148            + "-- Error Messages --\n\n";
149    String expected4 =
150            "--- CAD Simulator ---\n"
151            + "Elapsed Simulation Time     : 0:00:00\n"
152            + "Status                      : No Script\n"
153            + "Connected CAD Terminals     : 2\n"
154            + "Simulation Manager Connected: Yes\n"
155            + "Connected to Paramics       : No\n"
156            + "Network Loaded              : \n"
157            + "-- Info Messages --\n\n"
158            + "-- Error Messages --\n\n";
159    String expected5 =
160            "--- CAD Simulator ---\n"
161            + "Elapsed Simulation Time     : 0:00:00\n"
162            + "Status                      : No Script\n"
163            + "Connected CAD Terminals     : 2\n"
164            + "Simulation Manager Connected: Yes\n"
165            + "Connected to Paramics       : No\n"
166            + "Network Loaded              : \n"
167            + "-- Info Messages --\n"
168            + ". = Sample Info Message.\n"
169            + "-- Error Messages --\n\n";
170    String expected6 =
171            "--- CAD Simulator ---\n"
172            + "Elapsed Simulation Time     : 0:00:00\n"
173            + "Status                      : No Script\n"
174            + "Connected CAD Terminals     : 2\n"
175            + "Simulation Manager Connected: Yes\n"
176            + "Connected to Paramics       : Yes\n"
177            + "Network Loaded              : \n"
178            + "-- Info Messages --\n"
179            + ". = Sample Info Message.\n"
180            + "-- Error Messages --\n\n";
181    String expected7 =
182            "--- CAD Simulator ---\n"
183            + "Elapsed Simulation Time     : 0:00:00\n"
184            + "Status                      : No Script\n"
185            + "Connected CAD Terminals     : 2\n"
186            + "Simulation Manager Connected: Yes\n"
187            + "Connected to Paramics       : Yes\n"
188            + "Network Loaded              : 3\n"
189            + "-- Info Messages --\n"
190            + ". = Sample Info Message.\n"
191            + "-- Error Messages --\n\n";
192}
Note: See TracBrowser for help on using the repository browser.