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

source: tmcsimulator/trunk/test/tmcsim/cadsimulator/VisibleSystemDemoDriver.java @ 52

Revision 52, 6.2 KB checked in by jdalbey, 10 years ago (diff)

ParamicsCommunicator?.java revised to simplify system testing

RevLine 
1package tmcsim.cadsimulator;
2
3import java.io.File;
4import java.io.FileWriter;
5import java.io.PrintWriter;
6import java.rmi.RemoteException;
7import static junit.framework.Assert.assertEquals;
8import static junit.framework.Assert.fail;
9import org.uispec4j.*;
10import org.uispec4j.interception.WindowInterceptor;
11import tmcsim.common.ScriptException;
12import tmcsim.common.SimulationException;
13import tmcsim.paramicscommunicator.ParamicsCommunicator;
14import tmcsim.paramicscommunicator.gui.ParamicsCommunicatorGUI;
15import tmcsim.simulationmanager.SimulationManager;
16
17/**
18 * Requires manual starting CADSimulator before running this test. System test
19 * with emulated Paramics Modeler NO ATMS server.
20 *
21 * @author jdalbey
22 */
23public class VisibleSystemDemoDriver extends UISpecTestCase
24{
25
26    SimulationManager simMgrApp;
27
28    public VisibleSystemDemoDriver(String testName)
29    {
30        super(testName);
31    }
32
33    @Override
34    protected void setUp() throws Exception
35    {
36        super.setUp();
37    }
38
39    /**
40     * Test of run method, of class ParamicsCommunicator.
41     */
42    public void testRun() throws ScriptException, SimulationException, RemoteException
43    {
44        System.out.println("Visible System Test starting.");
45        // NOTE: CADSimulator must be started prior to running this test,
46        // because it displays a GUI, and if we try to do it inside this test,
47        // UISpec will complain about an uncaught window appearing.
48
49        ParamicsCommunicator pc = null;
50        pc = new ParamicsCommunicator("config/testConfig/paramics_communicator_config.properties");
51        ParamicsCommunicatorGUI theGUI = new ParamicsCommunicatorGUI();
52        pc.setGUI(theGUI);
53        // Note: Don't set visible ANY windows during UISpec test
54
55        // expect pcomm to say "sleeping"
56
57        Window simMgrWindow = null;
58        simMgrWindow = WindowInterceptor.run(new Trigger()
59        {
60            public void run()
61            {
62                try
63                {
64                    simMgrApp = new SimulationManager("config/sim_manager_systest_config.properties");
65                } catch (Exception ex)
66                {
67                    fail("Couldn't launch Simulation Manager, perhaps CADSimulator isn't running.");
68                }
69            }
70        });
71
72        // Check that the Sim Mgr GUI appears without a script loaded yet
73        Panel contentPanel = simMgrWindow.getPanel("contentPane");
74        TextBox txtSimStatus = contentPanel.getTextBox("simulationStatusText");
75        assertEquals("No Script", txtSimStatus.getText());
76        TextBox txtParamStatus = contentPanel.getTextBox("paramicsStatusInfoLabel");
77        assertEquals("Unknown", txtParamStatus.getText());
78        Button loadNetworkBtn = simMgrWindow.getButton("Load Network");
79        assertFalse(loadNetworkBtn.isEnabled());
80        // Begin actions
81        Button paramicsBtn = simMgrWindow.getButton("Connect to Paramics");
82        paramicsBtn.click();
83        try
84        {
85            Thread.sleep(200);
86        } catch (Exception ex)
87        {
88        }
89        assertEquals("Disconnect from Paramics", paramicsBtn.getLabel());
90
91        assertEquals("Connected", txtParamStatus.getText());
92        pc.startReading();
93
94        loadNetworkBtn.click();
95        try
96        {
97            Thread.sleep(200);
98        } catch (Exception ex)
99        {
100        }
101        assertEquals("Sending Network ID", txtParamStatus.getText());
102        System.out.println("Sending Network ID");
103        assertFalse(loadNetworkBtn.isEnabled());
104        String warmingXML = "<Paramics>\n"
105                + "<Network_Status>WARMING</Network_Status>\n"
106                + "<Network_ID>1</Network_ID>\n"
107                + "</Paramics>";
108        writedata("paramics_status.xml", warmingXML);
109        try
110        {
111            Thread.sleep(2100);
112        } catch (Exception ex)
113        {
114        }
115        assertEquals("Warming Up", txtParamStatus.getText());
116        System.out.println("Warming Up Passed");
117
118        try
119        {
120            Thread.sleep(2100);
121        } catch (Exception ex)
122        {
123        }
124        String loadedXML = "<Paramics>\n"
125                + "<Network_Status>LOADED</Network_Status>"
126                + "<Network_ID>1</Network_ID>"
127                + "</Paramics>";
128        writedata("paramics_status.xml", loadedXML);
129        try
130        {
131            Thread.sleep(2100);
132        } catch (Exception ex)
133        {
134        }
135        assertEquals("Network 1 Loaded", txtParamStatus.getText());
136        System.out.println("Network Loaded Passed");
137
138        // Load a script file
139        String autoloadScriptname = "scripts/audio_systest.xml";
140        simMgrApp.loadScript(new File(autoloadScriptname));
141        try
142        {
143            Thread.sleep(500);
144        } catch (Exception ex)
145        {
146        }
147
148        // The status should now say Ready
149        assertEquals("Ready", txtSimStatus.getText());
150
151        // Click "Start"
152        simMgrWindow.getButton("Start").click();
153        try
154        {
155            Thread.sleep(200);
156        } catch (Exception ex)
157        {
158            ex.printStackTrace();
159        }
160        assertEquals("Running", txtSimStatus.getText());
161        System.out.println("Running Passed");
162        try
163        {
164            Thread.sleep(9000);
165        } catch (InterruptedException ex)
166        {
167        }
168        simMgrWindow.getButton("Pause").click();
169        try
170        {
171            Thread.sleep(3000);
172        } catch (InterruptedException ex)
173        {
174        }
175        simMgrWindow.getButton("Start").click();
176        try
177        {
178            Thread.sleep(3000);
179        } catch (InterruptedException ex)
180        {
181        }
182        simMgrWindow.getButton("Pause").click();
183        simMgrWindow.getMenuBar().getMenu("File").getSubMenu("Exit").click();
184        System.out.println("Exiting.");
185    }
186
187    // Write the test data to a file
188    public static void writedata(String filename, String data)
189    {
190//        System.out.println("writedata called for " + filename);
191        PrintWriter writer = null;
192        try
193        {
194            writer = new PrintWriter(new FileWriter(filename));
195            writer.println(data);
196            writer.close();
197        } catch (Exception ex)
198        {
199            ex.printStackTrace();
200        }
201    }
202}
Note: See TracBrowser for help on using the repository browser.