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

source: tmcsimulator/trunk/test/tmcsim/cadsimulator/SystemTest.java @ 658

Revision 658, 4.9 KB checked in by jdalbey, 4 years ago (diff)

Replace hard-code scenario folder name in Simulation Manager with config property.

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.assertTrue;
9import static junit.framework.Assert.fail;
10import org.uispec4j.*;
11import org.uispec4j.interception.WindowInterceptor;
12import tmcsim.common.ScriptException;
13import tmcsim.common.SimulationException;
14import tmcsim.paramicscommunicator.ParamicsCommunicator;
15import tmcsim.paramicscommunicator.gui.ParamicsCommunicatorGUI;
16import tmcsim.simulationmanager.SimulationManager;
17import static tmcsim.simulationmanager.SimulationManager.SCENARIOS_DIR;
18
19/**
20 * System test (include CADSimulator) with emulated Paramics Modeler NO ATMS
21 * server captures GUI display using UISpec4J.
22 *
23 * @author jdalbey
24 */
25public class SystemTest extends UISpecTestCase
26{
27
28    SimulationManager simMgrApp;
29    CADServer engine;
30//    ParamicsCommunicator paramicscomm;
31
32    public SystemTest(String testName)
33    {
34        super(testName);
35    }
36
37    @Override
38    protected void setUp() throws Exception
39    {
40        super.setUp();
41    }
42
43    /**
44     * Test of run method, of class ParamicsCommunicator.
45     */
46    public void testRun() throws ScriptException, SimulationException, RemoteException
47    {
48        System.out.println("Invisible System Test");
49        Window cadwindow = null;
50        cadwindow = WindowInterceptor.run(new Trigger()
51        {
52            public void run()
53            {
54                try
55                {
56                    engine = new CADServer("config/cad_simulator_config.properties");
57                } catch (Exception e)
58                {
59                    fail("Couldn't launch CADSimulator");
60                }
61            }
62        });
63
64        // Check CAD Server appears with no script and nothing connected
65        assertTrue("Title bar incorrect", cadwindow.getTitle().trim().startsWith("CAD Server"));
66        Panel mainPanel = cadwindow.getPanel("contentPane");
67        TextBox txtStatus = mainPanel.getTextBox("simulationStatus");
68        assertEquals("No Script", txtStatus.getText());
69        TextBox terms = mainPanel.getTextBox("termConnectedTF");
70        assertEquals("0", terms.getText().trim());
71        assertEquals("No", mainPanel.getTextBox("managerConnectedTF").getText().trim());
72        assertEquals("network id should be None", "None", mainPanel.getTextBox("networkLoadedTF").getText().trim());
73
74
75        // Note: Can't set visible ANY windows during UISpec test
76
77        Window simMgrWindow = null;
78        simMgrWindow = WindowInterceptor.run(new Trigger()
79        {
80            public void run()
81            {
82                try
83                {
84                    simMgrApp = new SimulationManager("config/sim_manager_systest_config.properties");
85                } catch (Exception ex)
86                {
87                    fail("Couldn't launch Simulation Manager");
88                }
89            }
90        });
91
92        // TODO: Check that the Sim Mgr GUI appears without a script loaded yet
93
94        Panel contentPanel = simMgrWindow.getPanel("contentPane");
95        TextBox txtSimStatus = contentPanel.getTextBox("simulationStatusText");
96        assertEquals("No Script", txtSimStatus.getText());
97
98
99        // Load a script file
100        String autoloadScriptname = SCENARIOS_DIR+"/system_test_script.xml";
101        simMgrApp.loadScript(new File(autoloadScriptname));
102        try
103        {
104            Thread.sleep(500);
105        } catch (Exception ex)
106        {
107        }
108
109        // The status should now say Ready
110        assertEquals("Ready", txtSimStatus.getText());
111
112        // Click "Start"
113        simMgrWindow.getButton("Start").click();
114        try
115        {
116            Thread.sleep(200);
117        } catch (Exception ex)
118        {
119            ex.printStackTrace();
120        }
121        assertEquals("Running", txtSimStatus.getText());
122        System.out.println("Running Passed");
123        try
124        {
125            Thread.sleep(9000);
126        } catch (InterruptedException ex)
127        {
128        }
129        simMgrWindow.getButton("Pause").click();
130        try
131        {
132            Thread.sleep(3000);
133        } catch (InterruptedException ex)
134        {
135        }
136        simMgrWindow.getButton("Resume").click();
137        try
138        {
139            Thread.sleep(3000);
140        } catch (InterruptedException ex)
141        {
142        }
143        simMgrWindow.getButton("Pause").click();
144        simMgrWindow.getMenuBar().getMenu("File").getSubMenu("Exit").click();
145        System.out.println("Exiting.");
146    }
147
148    // Write the test data to a file
149    public static void writedata(String filename, String data)
150    {
151        PrintWriter writer = null;
152        try
153        {
154            writer = new PrintWriter(new FileWriter(filename));
155            writer.println(data);
156            writer.close();
157        } catch (Exception ex)
158        {
159            ex.printStackTrace();
160        }
161    }
162}
Note: See TracBrowser for help on using the repository browser.