source: tmcsimulator/trunk/test/tmcsim/paramicslog/ParamicsLogRMITestSkeleton.java @ 664

Revision 664, 3.0 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.

Line 
1package tmcsim.paramicslog;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.FileNotFoundException;
6import java.io.IOException;
7import java.rmi.RemoteException;
8import java.text.ParseException;
9import java.text.SimpleDateFormat;
10import java.util.Date;
11import java.util.Properties;
12import static junit.framework.Assert.assertEquals;
13import static junit.framework.Assert.fail;
14import junit.framework.TestCase;
15import tmcsim.cadsimulator.CADServer;
16import tmcsim.common.ScriptException;
17import tmcsim.common.SimulationException;
18
19/**
20 *
21 * @author jdalbey
22 */
23public class ParamicsLogRMITestSkeleton extends TestCase
24{
25
26    public ParamicsLogRMITestSkeleton(String testName)
27    {
28        super(testName);
29    }
30
31    @Override
32    protected void setUp() throws Exception
33    {
34        super.setUp();
35    }
36    String propsfile = "config/logging_paramics_communicator.properties";
37
38    /**
39     * Test of getInstance method, of class ParamicsLog.
40     */
41    public void testGetInstance() throws ScriptException, SimulationException, RemoteException, FileNotFoundException, IOException
42    {
43        System.out.println("getInstance");
44        try
45        {
46            CADServer engine = new CADServer("config/cad_server_console.properties");
47        } catch (Exception e)
48        {
49            fail("Couldn't launch CADSimulator");
50        }
51        try
52        {
53            Thread.sleep(2000);
54        } catch (InterruptedException ex)
55        {
56        }
57        // This seems to fail because the ParamicsLog static initializer gets
58        // run before the CADSimulator is created, so no RMI connection can be made.
59        ParamicsLog plog = ParamicsLog.getInstance();
60        Properties paramicsLogProp = new Properties();
61        paramicsLogProp.load(new FileInputStream(propsfile));
62        String logFilename = paramicsLogProp.getProperty("LogFile");
63        File logFile = new File(logFilename);
64        assertTrue("log file doesn't exist", logFile.exists());
65
66        plog.writeToLog("Hello friendly log.");
67        String expected = "\n<!-- Time written to file: ? -->\nHello friendly log.\n";
68        String actual = plog.getLog();
69        assertEquals("log written incorrectly", expected, actual);
70    }
71
72    public void testFormatEasyTime()
73    {
74        ParamicsLog plog = ParamicsLog.getInstance();
75        String expected = "00:01:02";
76        String actual = plog.formatTime(62l);
77        assertEquals("time format wrong", expected, actual);
78
79        expected = "1:00:01";
80        actual = plog.formatTime(3601l);
81        assertEquals("time format wrong", expected, actual);
82    }
83
84    public void testFormatDate() throws ParseException
85    {
86        ParamicsLog plog = ParamicsLog.getInstance();
87        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
88        String expected = "01:01:01";
89        Date one = formatter.parse(expected);
90        long millis = one.getTime();
91        String actual = plog.formatTime(millis);
92        assertEquals("time format wrong", expected, actual);
93    }
94}
Note: See TracBrowser for help on using the repository browser.