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

source: tmcsimulator/trunk/test/tmcsim/cadsimulator/viewer/CADConsoleViewerTest.java @ 664

Revision 664, 9.2 KB checked in by jdalbey, 4 years ago (diff)

Multifile commit - revise source to match revisions to config filenames. Fix broken system tests. Fix defect #160.

RevLine 
1package tmcsim.cadsimulator.viewer;
2
3import java.io.StringWriter;
4import java.util.logging.Level;
5import java.util.logging.Logger;
6import junit.framework.TestCase;
7import tmcsim.cadsimulator.viewer.model.CADSimulatorState;
8import tmcsim.common.CADEnums;
9
10/**
11 *
12 * @author jdalbey
13 */
14public class CADConsoleViewerTest extends TestCase
15{
16
17    CADConsoleViewer console;
18    CADSimulatorState cadmodel;
19    StringWriter sw;
20
21    public CADConsoleViewerTest(String testName)
22    {
23        super(testName);
24    }
25
26    @Override
27    protected void setUp() throws Exception
28    {
29        super.setUp();
30        console = new CADConsoleViewer("config/cad_server.properties");
31        cadmodel = new CADSimulatorState();
32        cadmodel.addObserver(console);
33        sw = new StringWriter();
34        console.setWriter(sw);
35    }
36    /** compare StringWriter contents against expected
37     *  @param expected contains just the most recent lines of output
38     *  @param errmsg message to be displayed if test fails
39     *  improved to verify line by line
40     */
41    private void verify(String errmsg, String expect)
42    {
43       
44        String result = sw.toString().trim().replace("\r","");  // Remove windows line feed characters
45        String[] results = result.split("\n"); //System.getProperty("line.separator"));   // split into lines
46        String[] expecteds = expect.trim().split("\n");
47        int rIdx = results.length-1;  // index to results array
48        // Work backwards from the most recent line of output
49        for (int eIdx=expecteds.length-1; eIdx >= 0; eIdx--)
50        {
51            //System.out.println("Verifying "+eIdx+". "+expecteds[eIdx]+" against "+results[rIdx]);
52            assertEquals(errmsg + " line "+eIdx, expecteds[eIdx], results[rIdx]);
53            rIdx--;
54        }   
55    } 
56
57    public static void pause(int millis)
58    {
59        try
60        {
61            Thread.sleep(millis);
62        } catch (InterruptedException ex)
63        {
64        }
65    }
66
67    /**
68     * Test of setVisible method, of class CADConsoleViewer.
69     */
70    public void testSetVisible()
71    {
72        String expected1 =
73                "--- CAD Simulator ---\n"
74                + "Elapsed Simulation Time     : 0:00:00\n"
75                + "Status                      : No Script\n"
76                + "Connected CAD Terminals     : 0\n"
77                + "Simulation Manager Connected: No\n"
78                + "Connected to Paramics       : No\n"
79                + "Network Loaded              : None\n"
80                + "-- Info Messages --\n\n"
81                + "-- Error Messages --";
82        System.out.println("setVisible");
83        console.setVisible(true);
84        String out = sw.toString().trim();
85        assertEquals(expected1, out);
86    }
87
88    public void testConnect()
89    {
90        String expected2 =
91                "--- CAD Simulator ---\n"
92                + "Elapsed Simulation Time     : 0:00:00\n"
93                + "Status                      : No Script\n"
94                + "Connected CAD Terminals     : 1\n"
95                + "Simulation Manager Connected: No\n"
96                + "Connected to Paramics       : No\n"
97                + "Network Loaded              : None\n"
98                + "-- Info Messages --\n\n"
99                + "-- Error Messages --\n\n";
100        cadmodel.connectClient();
101        verify("connected 1 terminal output incorrect: ", expected2);
102    }
103
104    public void testConnect2()
105    {
106        String expected3 =
107                "--- CAD Simulator ---\n"
108                + "Elapsed Simulation Time     : 0:00:00\n"
109                + "Status                      : No Script\n"
110                + "Connected CAD Terminals     : 2\n"
111                + "Simulation Manager Connected: No\n"
112                + "Connected to Paramics       : No\n"
113                + "Network Loaded              : None\n"
114                + "-- Info Messages --\n\n"
115                + "-- Error Messages --\n\n";
116        cadmodel.connectClient();
117        cadmodel.connectClient();
118        verify("connected 2 terminals output incorrect: ", expected3);
119    }
120
121    public void testDisconnect()
122    {
123        String expected3 =
124                "--- CAD Simulator ---\n"
125                + "Elapsed Simulation Time     : 0:00:00\n"
126                + "Status                      : No Script\n"
127                + "Connected CAD Terminals     : 2\n"
128                + "Simulation Manager Connected: No\n"
129                + "Connected to Paramics       : No\n"
130                + "Network Loaded              : None\n"
131                + "-- Info Messages --\n\n"
132                + "-- Error Messages --\n\n";
133        cadmodel.connectClient();
134        cadmodel.connectClient();
135        cadmodel.connectClient();
136        cadmodel.disconnectClient();
137        verify("disconnect terminal output incorrect: ", expected3);
138    }
139
140    public void testSimMgrConnect()
141    {
142        String expected4 =
143                "--- CAD Simulator ---\n"
144                + "Elapsed Simulation Time     : 0:00:00\n"
145                + "Status                      : No Script\n"
146                + "Connected CAD Terminals     : 0\n"
147                + "Simulation Manager Connected: Yes\n"
148                + "Connected to Paramics       : No\n"
149                + "Network Loaded              : None\n"
150                + "-- Info Messages --\n\n"
151                + "-- Error Messages --\n\n";
152        cadmodel.setSimManagerStatus(true);
153        verify("sim mgr connected output incorrect: ", expected4);
154    }
155
156    public void testInfoPane()
157    {
158        String expected5 =
159                "--- CAD Simulator ---\n"
160                + "Elapsed Simulation Time     : 0:00:00\n"
161                + "Status                      : No Script\n"
162                + "Connected CAD Terminals     : 0\n"
163                + "Simulation Manager Connected: No\n"
164                + "Connected to Paramics       : No\n"
165                + "Network Loaded              : None\n"
166                + "-- Info Messages --\n"
167                + ". = Console Info Message.\n"
168                + "-- Error Messages --\n\n";
169        Logger cadSimLogger = Logger.getLogger("tmcsim.cadsimulator");
170        cadSimLogger.logp(Level.INFO, "", "", "Console Info Message.");
171        verify("Info message output incorrect: ", expected5);
172    }
173
174    public void testErrorPane()
175    {
176        String expected7 =
177                "--- CAD Simulator ---\n"
178                + "Elapsed Simulation Time     : 0:00:00\n"
179                + "Status                      : No Script\n"
180                + "Connected CAD Terminals     : 0\n"
181                + "Simulation Manager Connected: No\n"
182                + "Connected to Paramics       : No\n"
183                + "Network Loaded              : None\n"
184                + "-- Info Messages --\n\n"
185                + "-- Error Messages --\n"
186                + "Someclass.Somemethod = Sample error message.\n";
187        Logger cadSimLogger = Logger.getLogger("tmcsim.cadsimulator");
188        cadSimLogger.logp(Level.SEVERE, "Someclass", "Somemethod", "Sample error message.");
189        verify("Error message output incorrect: ", expected7);
190    }
191
192    public void testParamicsChg()
193    {
194        String expected6 =
195                "--- CAD Simulator ---\n"
196                + "Elapsed Simulation Time     : 0:00:00\n"
197                + "Status                      : No Script\n"
198                + "Connected CAD Terminals     : 0\n"
199                + "Simulation Manager Connected: No\n"
200                + "Connected to Paramics       : Yes\n"
201                + "Network Loaded              : None\n"
202                + "-- Info Messages --\n\n"
203                + "-- Error Messages --\n\n";
204        cadmodel.setParamicsStatus(CADEnums.PARAMICS_STATUS.CONNECTED);
205        pause(500);
206        verify("paramics connected should be yes", expected6);
207    }
208
209    public void testSimStatus()
210    {
211        String expected8 =
212                "--- CAD Simulator ---\n"
213                + "Elapsed Simulation Time     : 0:00:00\n"
214                + "Status                      : Ready\n"
215                + "Connected CAD Terminals     : 0\n"
216                + "Simulation Manager Connected: No\n"
217                + "Connected to Paramics       : No\n"
218                + "Network Loaded              : None\n"
219                + "-- Info Messages --\n\n"
220                + "-- Error Messages --\n\n";
221        cadmodel.setScriptStatus(CADEnums.SCRIPT_STATUS.SCRIPT_STOPPED_NOT_STARTED);
222        verify("sim status should be ready", expected8);
223        cadmodel.setScriptStatus(CADEnums.SCRIPT_STATUS.SCRIPT_RUNNING);
224        String result = sw.toString();
225        assertTrue("sim status should be running: " + result, result.contains("Running"));
226    }
227
228    public void testSimTime()
229    {
230        String expected9 =
231                "--- CAD Simulator ---\n"
232                + "Elapsed Simulation Time     : 0:01:01\n"
233                + "Status                      : No Script\n"
234                + "Connected CAD Terminals     : 0\n"
235                + "Simulation Manager Connected: No\n"
236                + "Connected to Paramics       : No\n"
237                + "Network Loaded              : None\n"
238                + "-- Info Messages --\n\n"
239                + "-- Error Messages --\n\n";
240        cadmodel.setTime(61L);
241        verify("sim time should be 0:01:01", expected9);
242    }
243
244   
245}
Note: See TracBrowser for help on using the repository browser.