| 1 | package tmcsim.paramicslog; |
|---|
| 2 | |
|---|
| 3 | import java.io.File; |
|---|
| 4 | import java.io.FileInputStream; |
|---|
| 5 | import java.io.FileNotFoundException; |
|---|
| 6 | import java.io.IOException; |
|---|
| 7 | import java.rmi.RemoteException; |
|---|
| 8 | import java.util.Properties; |
|---|
| 9 | import java.util.logging.Logger; |
|---|
| 10 | import static junit.framework.Assert.assertEquals; |
|---|
| 11 | import static junit.framework.Assert.assertTrue; |
|---|
| 12 | import static junit.framework.Assert.fail; |
|---|
| 13 | import junit.framework.TestCase; |
|---|
| 14 | import tmcsim.cadsimulator.CADServer; |
|---|
| 15 | import tmcsim.common.ScriptException; |
|---|
| 16 | import tmcsim.common.SimulationException; |
|---|
| 17 | |
|---|
| 18 | /** |
|---|
| 19 | * |
|---|
| 20 | * @author jdalbey |
|---|
| 21 | */ |
|---|
| 22 | public class ParamicsLogFileHandlerTest extends TestCase |
|---|
| 23 | { |
|---|
| 24 | |
|---|
| 25 | public ParamicsLogFileHandlerTest(String testName) |
|---|
| 26 | { |
|---|
| 27 | super(testName); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | @Override |
|---|
| 31 | protected void setUp() throws Exception |
|---|
| 32 | { |
|---|
| 33 | super.setUp(); |
|---|
| 34 | } |
|---|
| 35 | String propsfile = "config/paramics_communicator_logging.properties"; |
|---|
| 36 | |
|---|
| 37 | /** |
|---|
| 38 | * Test of getInstance method, of class ParamicsLog. |
|---|
| 39 | */ |
|---|
| 40 | public void testGetInstance() throws ScriptException, SimulationException, RemoteException, FileNotFoundException, IOException |
|---|
| 41 | { |
|---|
| 42 | System.out.println("getInstance"); |
|---|
| 43 | try |
|---|
| 44 | { |
|---|
| 45 | new CADServer("config/cad_simulator_console_config.properties"); |
|---|
| 46 | } catch (Exception e) |
|---|
| 47 | { |
|---|
| 48 | fail("Couldn't launch CADSimulator"); |
|---|
| 49 | } |
|---|
| 50 | //ParamicsLog plog = ParamicsLog.getInstance(); |
|---|
| 51 | Properties paramicsLogProp = new Properties(); |
|---|
| 52 | paramicsLogProp.load(new FileInputStream(propsfile)); |
|---|
| 53 | String logFilename = paramicsLogProp.getProperty("LogFile"); |
|---|
| 54 | // This test requires a CADSimulator running. |
|---|
| 55 | Logger logger = Logger.getLogger("tmcsim.parmicsLog"); |
|---|
| 56 | ParamicsLogFileHandler fh = ParamicsLogFileHandler.getInstance(); |
|---|
| 57 | logger.addHandler(fh); |
|---|
| 58 | // write a message to the log. |
|---|
| 59 | logger.info("Hello friendly log."); |
|---|
| 60 | // Read from the log file and see if the desired msg is there. |
|---|
| 61 | File logFile = new File(logFilename); |
|---|
| 62 | assertTrue("log file doesn't exist", logFile.exists()); |
|---|
| 63 | String expected = "\n<!-- Time written to file: 00:00:00 -->\nHello friendly log.\n"; |
|---|
| 64 | String actual = fh.getLog(); |
|---|
| 65 | assertEquals("log written incorrectly", expected, actual); |
|---|
| 66 | } |
|---|
| 67 | } |
|---|