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

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

Revision 123, 7.6 KB checked in by jdalbey, 9 years ago (diff)

Multiple renaming of classes to improve clarity. Remove check for Paramics running before starting sim.

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