Author: chatellier Date: 2009-09-02 10:42:23 +0000 (Wed, 02 Sep 2009) New Revision: 2571 Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SimulationInformationTest.java Log: Add tests about simulation information Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SimulationInformationTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SimulationInformationTest.java (rev 0) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SimulationInformationTest.java 2009-09-02 10:42:23 UTC (rev 2571) @@ -0,0 +1,140 @@ +/* *##% + * Copyright (C) 2009 Ifremer, Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package fr.ifremer.isisfish.datastore; + +import java.io.File; +import java.io.IOException; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import junit.framework.Assert; + +import org.junit.Test; + +/** + * Test for {@link SimulationInformation} class. + * + * No need for isolated directory (system directory not used). + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SimulationInformationTest { + + /** + * Test simulation information with no data. + * + * @throws IOException + */ + @Test + public void testSimulationEmpty() throws IOException { + + File file = File.createTempFile("information-empty", ".txt"); + file.deleteOnExit(); + + SimulationInformation info = new SimulationInformation(file); + Assert.assertEquals(new Date(0), info.getSimulationStart()); + Assert.assertEquals(new Date(0), info.getSimulationEnd()); + Assert.assertFalse(info.hasError()); + Assert.assertNull(info.getException()); + Assert.assertEquals(0, info.getExportTime("test")); + } + + /** + * Test simulation date storage. + * + * @throws IOException + * @throws ParseException + */ + @Test + public void testSimulationDate() throws IOException, ParseException { + + // Do not use same format as {@link SimulationInformation#dateFormat} + DateFormat df = new SimpleDateFormat("hh:mm:ss a"); + + File file = File.createTempFile("information-date", ".txt"); + file.deleteOnExit(); + + SimulationInformation info = new SimulationInformation(file); + + Date d1 = df.parse("3:30:32 pm"); + Date d2 = df.parse("3:50:47 pm"); + info.setSimulationStart(d1); + info.setSimulationEnd(d2); + + info.store(); + + SimulationInformation testInfo = new SimulationInformation(file); + Assert.assertEquals(d1, testInfo.getSimulationStart()); + Assert.assertEquals(d2, testInfo.getSimulationEnd()); + } + + /** + * Test simulation exception storage. + * + * @throws IOException + */ + @Test + public void testSimulationException() throws IOException { + File file = File.createTempFile("information-exception", ".txt"); + file.deleteOnExit(); + + SimulationInformation info = new SimulationInformation(file); + Assert.assertFalse(info.hasError()); + + Exception e = new Exception("Oula la, ya eu une exception super grave"); + info.setException(e); + info.store(); + + SimulationInformation testInfo = new SimulationInformation(file); + Assert.assertTrue(testInfo.hasError()); + Assert.assertTrue(testInfo.getException().indexOf("grave") > 0); + + } + + /** + * Test simulation export time. + * @throws IOException + */ + @Test + public void testSimulationExportTime() throws IOException { + File file = File.createTempFile("information-export", ".txt"); + file.deleteOnExit(); + + SimulationInformation info = new SimulationInformation(file); + info.addExportTime("export1", 30); + info.addExportTime("export2", 40); + info.addExportTime("export3", 50); + info.addExportTime("export4", 60); + + info.store(); + + SimulationInformation testInfo = new SimulationInformation(file); + Assert.assertFalse(testInfo.hasError()); + Assert.assertEquals(30, testInfo.getExportTime("export1")); + Assert.assertEquals(40, testInfo.getExportTime("export2")); + Assert.assertEquals(50, testInfo.getExportTime("export3")); + Assert.assertEquals(60, testInfo.getExportTime("export4")); + } +} Property changes on: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SimulationInformationTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL"