package tmcsim.paramicslog; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.rmi.RemoteException; import java.util.Properties; import java.util.logging.Logger; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import junit.framework.TestCase; import tmcsim.common.ScriptException; import tmcsim.common.SimulationException; /** * * @author jdalbey */ public class ParamicsLogFileHandlerTest extends TestCase { public ParamicsLogFileHandlerTest(String testName) { super(testName); } @Override protected void setUp() throws Exception { super.setUp(); } String propsfile = "config/paramics_communicator_logging.properties"; /** * Test of getInstance method, of class ParamicsLog. */ public void testGetInstance() throws ScriptException, SimulationException, RemoteException, FileNotFoundException, IOException { System.out.println("getInstance"); //ParamicsLog plog = ParamicsLog.getInstance(); Properties paramicsLogProp = new Properties(); paramicsLogProp.load(new FileInputStream(propsfile)); String logFilename = paramicsLogProp.getProperty("LogFile"); // This test assumes there is NO CADSimulator running. Logger logger = Logger.getLogger("tmcsim.parmicsLog"); ParamicsLogFileHandler fh = ParamicsLogFileHandler.getInstance(); logger.addHandler(fh); logger.info("Hello friendly log."); File logFile = new File(logFilename); assertTrue("log file doesn't exist", logFile.exists()); String expected = "\n\nHello friendly log.\n"; String actual = fh.getLog(); assertEquals("log written incorrectly", expected, actual); } }