Author: chatellier Date: 2009-05-14 18:09:22 +0000 (Thu, 14 May 2009) New Revision: 2230 Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/AbstractIsisFishTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/DataStorageTestHelper.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PersistenceTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/LoggerHelper.java Removed: isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/PersistenceTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/TestUtil.java Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/AnalysePlanStorageTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/ExportStorageTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/FormuleStorageTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/RuleStorageTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/ScriptStorageTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SensitivityStorageTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SimulatorStorageTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/SimulationLoggerUtilTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderUtilTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/MexicoHelperTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationHelperTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationParameterTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/sensitivity/FactorTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/sensitivity/SensitivityCalculatorRandomMock.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModelTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/widget/filter/FilterDialogModelMock.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/CompileHelperTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/EvaluateHelperTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java Log: Refactor all tests. Now all test must inherit abtract test that build a test environment with a proper isolated database. Deleted: isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -1,133 +0,0 @@ -/* *##% - * Copyright (C) 2009 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; - -import java.io.File; -import java.io.FileFilter; - -import org.apache.commons.io.FileUtils; -import org.codelutin.util.FileUtil; - -import fr.ifremer.isisfish.IsisFish; -import fr.ifremer.isisfish.util.ClasspathTemplateLoader; -import freemarker.cache.TemplateLoader; -import freemarker.ext.beans.BeansWrapper; -import freemarker.template.Configuration; - -/** - * Une classe pour avoir des choses utiles pour tous les tests d'isis - * - * @author chemit - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public abstract class TestUtils { - - protected static File basedir; - - protected static File targetdir; - - protected static File dirDatabase; - - public static File getBasedir() { - if (basedir == null) { - String base = System.getProperty("basedir"); - if (base == null || base.isEmpty()) { - base = new File("").getAbsolutePath(); - } - basedir = new File(base); - //System.out.println("basedir for test " + basedir); - } - return basedir; - } - - public static File getTargetdir() { - if (targetdir == null) { - targetdir = new File(getBasedir(), "target"); - //System.out.println("targetdir for test " + targetdir); - } - return targetdir; - } - - /** - * Toujours appeler cette method pour les test d'isis. - * (sinon,il ira ecrire dans le isis-database-3 officiel). - * - * Create a temp dir and init isis with that temp dir as database. - * - * @throws Exception - */ - public static void init() throws Exception { - - File mavenTestDir = new File(getTargetdir() + File.separator + "surefire-workdir"); - dirDatabase = FileUtil.createTempDirectory("isisdbtest", "", mavenTestDir); - - System.setProperty("database.directory", dirDatabase.getAbsolutePath()); - System.setProperty("launch.ui", "false"); - System.setProperty("user.home", dirDatabase.getAbsolutePath()); - - IsisFish.init(); - IsisFish.initVCS(); - - FileUtils.copyDirectory(new File("src/test/resources/test-database"), dirDatabase, new FileFilter() { - @Override - public boolean accept(File pathname) { - boolean result = true; - if(pathname.getAbsolutePath().indexOf(File.separator + ".svn") != -1) { - result = false; - } - return result; - } - }); - } - - /** - * Delete created temp directory. - */ - public static void clean() { - System.setProperty("user.home", ""); - if(dirDatabase != null) { - FileUtil.deleteRecursively(dirDatabase); - dirDatabase = null; - } - } - - /** - * Return common script freemarker configuration. - * - * @return freemarker {@link Configuration} - */ - public static Configuration getFreemarkerConfiguration() { - Configuration freemarkerConfiguration = new Configuration(); - - // needed to overwrite "Defaults to default system encoding." - // fix encoding issue on some systems - freemarkerConfiguration.setDefaultEncoding("utf-8"); - - // specific template loader to get template from jars (classpath) - TemplateLoader templateLoader = new ClasspathTemplateLoader(); - freemarkerConfiguration.setTemplateLoader(templateLoader); - - freemarkerConfiguration.setObjectWrapper(new BeansWrapper()); - - return freemarkerConfiguration; - } -} Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/AbstractIsisFishTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/AbstractIsisFishTest.java (rev 0) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/AbstractIsisFishTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -0,0 +1,149 @@ +/* *##% + * Copyright (C) 2009 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; + +import java.io.File; +import java.io.FileFilter; + +import org.apache.commons.io.FileUtils; +import org.codelutin.util.FileUtil; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +import fr.ifremer.isisfish.util.ClasspathTemplateLoader; +import freemarker.cache.TemplateLoader; +import freemarker.ext.beans.BeansWrapper; +import freemarker.template.Configuration; + +/** + * Abtract test case for isis fish. + * + * Contains BeforeClass and AfterClass method to proper init cases. + * + * @author chatellier + * @version $Revision: 1.0 $ + * + * Last update : $Date: 14 mai 2009 $ + * By : $Author: chatellier $ + */ +public abstract class AbstractIsisFishTest { + + protected static File basedir; + + protected static File targetdir; + + protected static File dirDatabase; + + protected static File getBasedir() { + if (basedir == null) { + String base = System.getProperty("basedir"); + if (base == null || base.isEmpty()) { + base = new File("").getAbsolutePath(); + } + basedir = new File(base); + } + return basedir; + } + + protected static File getTargetdir() { + if (targetdir == null) { + targetdir = new File(getBasedir(), "target"); + } + return targetdir; + } + + /** + * Toujours appeler cette method pour les test d'isis. + * (sinon,il ira ecrire dans le isis-database-3 officiel). + * + * Create a temp dir and init isis with that temp dir as database. + * + * @throws Exception + */ + @BeforeClass + public static void init() throws Exception { + + File mavenTestDir = new File(getTargetdir() + File.separator + "surefire-workdir"); + dirDatabase = FileUtil.createTempDirectory("isisdbtest", "", mavenTestDir); + + System.setProperty("user.home", dirDatabase.getAbsolutePath()); + System.setProperty(IsisConfig.Option.LAUNCH_UI.key, "false"); + System.setProperty(IsisConfig.Option.DATABASE_DIRECTORY.key, dirDatabase.getAbsolutePath()); + System.setProperty(IsisConfig.Option.SSH_KEY_FILE.key, dirDatabase.getAbsolutePath() + File.separator + "ssh" + File.separator + "isis_test_dsa"); + System.setProperty(IsisConfig.Option.VCS_SSH_KEY_FILE.key, dirDatabase.getAbsolutePath() + File.separator + "ssh" + File.separator + "isis_test_rsa"); + + IsisFish.init(); + IsisFish.initVCS(); + + FileUtils.copyDirectory(new File("src/test/resources/test-database"), + dirDatabase, new FileFilter() { + @Override + public boolean accept(File pathname) { + boolean result = true; + if (pathname.getAbsolutePath().indexOf( + File.separator + ".svn") != -1) { + result = false; + } + return result; + } + }); + } + + /** + * Return current database directory. + * + * @return current database directory + */ + protected static File getCurrentDatabaseDirectory() { + return dirDatabase; + } + + /** + * Delete created temp directory. + */ + @AfterClass + public static void clean() { + System.clearProperty("user.home"); + if (dirDatabase != null) { + FileUtil.deleteRecursively(dirDatabase); + dirDatabase = null; + } + } + + /** + * Return common script freemarker configuration. + * + * @return freemarker {@link Configuration} + */ + protected static Configuration getFreemarkerConfiguration() { + Configuration freemarkerConfiguration = new Configuration(); + + // needed to overwrite "Defaults to default system encoding." + // fix encoding issue on some systems + freemarkerConfiguration.setDefaultEncoding("utf-8"); + + // specific template loader to get template from jars (classpath) + TemplateLoader templateLoader = new ClasspathTemplateLoader(); + freemarkerConfiguration.setTemplateLoader(templateLoader); + + freemarkerConfiguration.setObjectWrapper(new BeansWrapper()); + + return freemarkerConfiguration; + } +} Deleted: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/PersistenceTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/PersistenceTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/PersistenceTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -1,770 +0,0 @@ -/* *##% -* Copyright (C) 2002, 2009 Code Lutin, Cédric Pineau, Benjamin Poussin -* -* 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; - -import java.util.Collection; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.topia.TopiaContext; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import fr.ifremer.TestUtils; -import fr.ifremer.isisfish.datastore.RegionStorage; -import fr.ifremer.isisfish.entities.Cell; -import fr.ifremer.isisfish.entities.CellDAO; -import fr.ifremer.isisfish.entities.EffortDescription; -import fr.ifremer.isisfish.entities.EffortDescriptionDAO; -import fr.ifremer.isisfish.entities.FisheryRegion; -import fr.ifremer.isisfish.entities.FisheryRegionDAO; -import fr.ifremer.isisfish.entities.Gear; -import fr.ifremer.isisfish.entities.GearDAO; -import fr.ifremer.isisfish.entities.Metier; -import fr.ifremer.isisfish.entities.MetierDAO; -import fr.ifremer.isisfish.entities.MetierSeasonInfo; -import fr.ifremer.isisfish.entities.MetierSeasonInfoDAO; -import fr.ifremer.isisfish.entities.Population; -import fr.ifremer.isisfish.entities.PopulationDAO; -import fr.ifremer.isisfish.entities.PopulationGroup; -import fr.ifremer.isisfish.entities.PopulationGroupDAO; -import fr.ifremer.isisfish.entities.PopulationSeasonInfo; -import fr.ifremer.isisfish.entities.PopulationSeasonInfoDAO; -import fr.ifremer.isisfish.entities.Port; -import fr.ifremer.isisfish.entities.PortDAO; -import fr.ifremer.isisfish.entities.Result; -import fr.ifremer.isisfish.entities.ResultDAO; -import fr.ifremer.isisfish.entities.Season; -import fr.ifremer.isisfish.entities.SeasonDAO; -import fr.ifremer.isisfish.entities.Selectivity; -import fr.ifremer.isisfish.entities.SelectivityDAO; -import fr.ifremer.isisfish.entities.SetOfVessels; -import fr.ifremer.isisfish.entities.SetOfVesselsDAO; -import fr.ifremer.isisfish.entities.Species; -import fr.ifremer.isisfish.entities.SpeciesDAO; -import fr.ifremer.isisfish.entities.Strategy; -import fr.ifremer.isisfish.entities.StrategyDAO; -import fr.ifremer.isisfish.entities.StrategyMonthInfo; -import fr.ifremer.isisfish.entities.StrategyMonthInfoDAO; -import fr.ifremer.isisfish.entities.TargetSpecies; -import fr.ifremer.isisfish.entities.TargetSpeciesDAO; -import fr.ifremer.isisfish.entities.TripType; -import fr.ifremer.isisfish.entities.TripTypeDAO; -import fr.ifremer.isisfish.entities.VesselType; -import fr.ifremer.isisfish.entities.VesselTypeDAO; -import fr.ifremer.isisfish.entities.Zone; -import fr.ifremer.isisfish.entities.ZoneDAO; - -/** - * PersistenceTest. - * - * Created: 3 août 2004 - * - * @author Benjamin Poussin <poussin at codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class PersistenceTest { - - /** - * Logger for this class - */ - private static final Log log = LogFactory.getLog(PersistenceTest.class); - - // Persistence - protected TopiaContext context = null; - protected RegionStorage rs; - - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - } - - @AfterClass - public static void clean() { - TestUtils.clean(); - } - - @Before - public void setUp() throws Exception { - rs = RegionStorage.create("test"); - context = rs.getStorage(); - } - - @After - public void tearDown() throws Exception { - rs.delete(false); - } - - @Test - public void testInstanciate() throws Exception { - TopiaContext context = this.context.beginTransaction(); - - FisheryRegionDAO fisheryRegionDAO = IsisFishDAOHelper.getFisheryRegionDAO(context); - FisheryRegion fisheryRegion = fisheryRegionDAO.create(); - log.debug(fisheryRegion + " - " + fisheryRegion.getClass().getName()); - - EffortDescriptionDAO effortDescriptionDAO = IsisFishDAOHelper.getEffortDescriptionDAO(context); - EffortDescription effortDescription = effortDescriptionDAO.create(); - log.debug(effortDescription + " - " + effortDescription.getClass().getName()); - - GearDAO gearDAO = IsisFishDAOHelper.getGearDAO(context); - Gear gear = gearDAO.create(); - log.debug(gear + " - " + gear.getClass().getName()); - - CellDAO cellDAO = IsisFishDAOHelper.getCellDAO(context); - Cell cell = cellDAO.create(); - log.debug(cell + " - " + cell.getClass().getName()); - - SpeciesDAO speciesDAO = IsisFishDAOHelper.getSpeciesDAO(context); - Species species = speciesDAO.create(); - log.debug(species + " - " + species.getClass().getName()); - - MetierDAO metierDAO = IsisFishDAOHelper.getMetierDAO(context); - Metier metier = metierDAO.create(); - log.debug(metier + " - " + metier.getClass().getName()); - - MetierSeasonInfoDAO metierSeasonInfoDAO = IsisFishDAOHelper.getMetierSeasonInfoDAO(context); - MetierSeasonInfo metierSeasonInfo = metierSeasonInfoDAO.create(); - log.debug(metierSeasonInfo + " - " +metierSeasonInfo.getClass().getName()); - - PopulationGroupDAO populationGroupDAO = IsisFishDAOHelper.getPopulationGroupDAO(context); - PopulationGroup populationGroup = populationGroupDAO.create(); - log.debug(populationGroup + " - " + populationGroup.getClass().getName()); - - PopulationDAO populationDAO = IsisFishDAOHelper.getPopulationDAO(context); - Population population = populationDAO.create(); - log.debug(population + " - " + population.getClass().getName()); - - PortDAO portDAO = IsisFishDAOHelper.getPortDAO(context); - Port port = portDAO.create(); - log.debug(port + " - " + port.getClass().getName()); - - ResultDAO resultDAO = IsisFishDAOHelper.getResultDAO(context); - Result result = resultDAO.create(); - log.debug(result + " - " + result.getClass().getName()); - - SeasonDAO seasonDAO = IsisFishDAOHelper.getSeasonDAO(context); - Season season = seasonDAO.create(); - log.debug(season + " - " + season.getClass().getName()); - - PopulationSeasonInfoDAO PopulationSeasonInfoDAO = IsisFishDAOHelper.getPopulationSeasonInfoDAO(context); - PopulationSeasonInfo PopulationSeasonInfo = PopulationSeasonInfoDAO.create(); - log.debug(PopulationSeasonInfo + " - " + PopulationSeasonInfo.getClass().getName()); - - SelectivityDAO selectivityDAO = IsisFishDAOHelper.getSelectivityDAO(context); - Selectivity selectivity = selectivityDAO.create(); - log.debug(selectivity + " - " + selectivity.getClass().getName()); - - SetOfVesselsDAO setOfVesselsDAO = IsisFishDAOHelper.getSetOfVesselsDAO(context); - SetOfVessels setOfVessels = setOfVesselsDAO.create(); - log.debug(setOfVessels + " - " + setOfVessels.getClass().getName()); - - StrategyMonthInfoDAO strategyMonthInfoDAO = IsisFishDAOHelper.getStrategyMonthInfoDAO(context); - StrategyMonthInfo strategyMonthInfo = strategyMonthInfoDAO.create(); - log.debug(strategyMonthInfo + " - " + strategyMonthInfo.getClass().getName()); - - StrategyDAO strategyDAO = IsisFishDAOHelper.getStrategyDAO(context); - Strategy strategy = strategyDAO.create(); - log.debug(strategy + " - " + strategy.getClass().getName()); - - TargetSpeciesDAO targetSpeciesDAO = IsisFishDAOHelper.getTargetSpeciesDAO(context); - TargetSpecies targetSpecies = targetSpeciesDAO.create(); - log.debug(targetSpecies + " - " + targetSpecies.getClass().getName()); - - TripTypeDAO tripTypeDAO = IsisFishDAOHelper.getTripTypeDAO(context); - TripType tripType = tripTypeDAO.create(); - log.debug(tripType + " - " + tripType.getClass().getName()); - - VesselTypeDAO vesselTypeDAO = IsisFishDAOHelper.getVesselTypeDAO(context); - VesselType vesselType = vesselTypeDAO.create(); - log.debug(vesselType + " - " + vesselType.getClass().getName()); - - ZoneDAO zoneDAO = IsisFishDAOHelper.getZoneDAO(context); - Zone zone = zoneDAO.create(); - log.debug(zone + " - " + zone.getClass().getName()); - - context.rollbackTransaction(); - } - - - @Test - public void testMakePersistence() throws Exception { - TopiaContext context = this.context.beginTransaction(); -// { -// AgeGroupDAO ps = IsisFishDAOHelper.getAgeGroupDAO(context); -// AgeGroup o = ps.create(); -// o = ps.update(o); -// } - { - FisheryRegionDAO ps = IsisFishDAOHelper.getFisheryRegionDAO(context); - FisheryRegion o = ps.create(); - o = ps.update(o); - } -// { -// CompositeZoneDAO ps = IsisFishDAOHelper.getCompositeZoneDAO(context); -// CompositeZone o = ps.create(); -// o = ps.update(o); -// } - { - EffortDescriptionDAO ps = IsisFishDAOHelper.getEffortDescriptionDAO(context); - EffortDescription o = ps.create(); - o = ps.update(o); - } -// { -// EmigrationDAO ps = IsisFishDAOHelper.getEmigrationDAO(context); -// Emigration o = ps.create(); -// o = ps.update(o); -// } -// { -// EquationDAO ps = IsisFishDAOHelper.getEquationDAO(context); -// Equation o = ps.create(); -// o = ps.update(o); -// } - { - GearDAO ps = IsisFishDAOHelper.getGearDAO(context); - Gear o = ps.create(); - o = ps.update(o); - } -// { -// ImmigrationDAO ps = IsisFishDAOHelper.getImmigrationDAO(context); -// Immigration o = ps.create(); -// o = ps.update(o); -// } -// { -// LengthGroupDAO ps = IsisFishDAOHelper.getLengthGroupDAO(context); -// LengthGroup o = ps.create(); -// o = ps.update(o); -// } -// { -// MappingZoneReproZoneRecruDAO ps = IsisFishDAOHelper.getMappingZoneReproZoneRecruDAO(context); -// MappingZoneReproZoneRecru o = ps.create(); -// o = ps.update(o); -// } - { - CellDAO ps = IsisFishDAOHelper.getCellDAO(context); - Cell o = ps.create(); - o = ps.update(o); - } - { - SpeciesDAO ps = IsisFishDAOHelper.getSpeciesDAO(context); - Species o = ps.create(); - o = ps.update(o); - } - { - MetierDAO ps = IsisFishDAOHelper.getMetierDAO(context); - Metier o = ps.create(); - o = ps.update(o); - } - { - MetierSeasonInfoDAO ps = IsisFishDAOHelper.getMetierSeasonInfoDAO(context); - MetierSeasonInfo o = ps.create(); - o = ps.update(o); - } -// { -// MigrationDAO ps = IsisFishDAOHelper.getMigrationDAO(context); -// Migration o = ps.create(); -// o = ps.update(o); -// } - { -// try{ - PopulationGroupDAO ps = IsisFishDAOHelper.getPopulationGroupDAO(context); - PopulationGroup o = ps.create(); - o = ps.update(o); -// assertTrue(false); // normalement on a pas le droit d'instancier une entity abstraite -// }catch(TopiaException eee){ -// assertTrue(true); -// } - } - { - PopulationDAO ps = IsisFishDAOHelper.getPopulationDAO(context); - Population o = ps.create(); - o = ps.update(o); - } - { - PortDAO ps = IsisFishDAOHelper.getPortDAO(context); - Port o = ps.create(); - o = ps.update(o); - } - { - ResultDAO ps = IsisFishDAOHelper.getResultDAO(context); - Result o = ps.create(); - o = ps.update(o); - } - { - PopulationSeasonInfoDAO ps = IsisFishDAOHelper.getPopulationSeasonInfoDAO(context); - PopulationSeasonInfo o = ps.create(); - o = ps.update(o); - } - { - SelectivityDAO ps = IsisFishDAOHelper.getSelectivityDAO(context); - Selectivity o = ps.create(); - o = ps.update(o); - } - { - SetOfVesselsDAO ps = IsisFishDAOHelper.getSetOfVesselsDAO(context); - SetOfVessels o = ps.create(); - o = ps.update(o); - } -// { -// SimpleZoneDAO ps = IsisFishDAOHelper.getSimpleZoneDAO(context); -// SimpleZone o = ps.create(); -// o = ps.update(o); -// } - { - StrategyMonthInfoDAO ps = IsisFishDAOHelper.getStrategyMonthInfoDAO(context); - StrategyMonthInfo o = ps.create(); - o = ps.update(o); - } - { - StrategyDAO ps = IsisFishDAOHelper.getStrategyDAO(context); - Strategy o = ps.create(); - o = ps.update(o); - } - { - TargetSpeciesDAO ps = IsisFishDAOHelper.getTargetSpeciesDAO(context); - TargetSpecies o = ps.create(); - o = ps.update(o); - } - { - TripTypeDAO ps = IsisFishDAOHelper.getTripTypeDAO(context); - TripType o = ps.create(); - o = ps.update(o); - } - { - VesselTypeDAO ps = IsisFishDAOHelper.getVesselTypeDAO(context); - VesselType o = ps.create(); - o = ps.update(o); - } - { - ZoneDAO ps = IsisFishDAOHelper.getZoneDAO(context); - Zone o = ps.create(); - o = ps.update(o); - } - context.rollbackTransaction(); - } - - @Test - public void testFindAll() throws Exception { - TopiaContext context = this.context.beginTransaction(); -// { -// AgeGroupDAO ps = IsisFishDAOHelper.getAgeGroupDAO(context); -// Collection<AgeGroup> list = ps.findAll(); -// log.debug(list + " - " +ps.getClass().getName()); -// } - { - FisheryRegionDAO ps = IsisFishDAOHelper.getFisheryRegionDAO(context); - Collection<FisheryRegion> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } -// { -// CompositeZoneDAO ps = IsisFishDAOHelper.getCompositeZoneDAO(context); -// Collection list<CompositeZone> = ps.findAll(); -// } - { - EffortDescriptionDAO ps = IsisFishDAOHelper.getEffortDescriptionDAO(context); - Collection<EffortDescription> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } -// { -// EmigrationDAO ps = IsisFishDAOHelper.getEmigrationDAO(context); -// Collection<Emigration> list = ps.findAll(); -// log.debug(list + " - " +ps.getClass().getName()); -// } - { - GearDAO ps = IsisFishDAOHelper.getGearDAO(context); - Collection<Gear> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } -// { -// ImmigrationDAO ps = IsisFishDAOHelper.getImmigrationDAO(context); -// Collection<Immigration> list = ps.findAll(); -// log.debug(list + " - " +ps.getClass().getName()); -// } -// { -// LengthGroupDAO ps = IsisFishDAOHelper.getLengthGroupDAO(context); -// Collection<LengthGroup> list = ps.findAll(); -// log.debug(list + " - " +ps.getClass().getName()); -// } -// { -// MappingZoneReproZoneRecruDAO ps = IsisFishDAOHelper.getMappingZoneReproZoneRecruDAO(context); -// Collection<MappingZoneReproZoneRecru> list = ps.findAll(); -// log.debug(list + " - " +ps.getClass().getName()); -// } - { - CellDAO ps = IsisFishDAOHelper.getCellDAO(context); - Collection<Cell> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - SpeciesDAO ps = IsisFishDAOHelper.getSpeciesDAO(context); - Collection<Species> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - MetierDAO ps = IsisFishDAOHelper.getMetierDAO(context); - Collection<Metier> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - MetierSeasonInfoDAO ps = IsisFishDAOHelper.getMetierSeasonInfoDAO(context); - Collection<MetierSeasonInfo> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } -// { -// MigrationDAO ps = IsisFishDAOHelper.getMigrationDAO(context); -// Collection<Migration> list = ps.findAll(); -// log.debug(list + " - " +ps.getClass().getName()); -// } - { - PopulationGroupDAO ps = IsisFishDAOHelper.getPopulationGroupDAO(context); - Collection<PopulationGroup> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - PopulationDAO ps = IsisFishDAOHelper.getPopulationDAO(context); - Collection<Population> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - PortDAO ps = IsisFishDAOHelper.getPortDAO(context); - Collection<Port> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - ResultDAO ps = IsisFishDAOHelper.getResultDAO(context); - Collection<Result> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - PopulationSeasonInfoDAO ps = IsisFishDAOHelper.getPopulationSeasonInfoDAO(context); - Collection<PopulationSeasonInfo> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - SelectivityDAO ps = IsisFishDAOHelper.getSelectivityDAO(context); - Collection<Selectivity> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - SetOfVesselsDAO ps = IsisFishDAOHelper.getSetOfVesselsDAO(context); - Collection<SetOfVessels> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } -// { -// SimpleZoneDAO ps = IsisFishDAOHelper.getSimpleZoneDAO(context); -// Collection<SimpleZone> list = ps.findAll(); -// } - { - StrategyMonthInfoDAO ps = IsisFishDAOHelper.getStrategyMonthInfoDAO(context); - Collection<StrategyMonthInfo> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - StrategyDAO ps = IsisFishDAOHelper.getStrategyDAO(context); - Collection<Strategy> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - TargetSpeciesDAO ps = IsisFishDAOHelper.getTargetSpeciesDAO(context); - Collection<TargetSpecies> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - TripTypeDAO ps = IsisFishDAOHelper.getTripTypeDAO(context); - Collection<TripType> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - VesselTypeDAO ps = IsisFishDAOHelper.getVesselTypeDAO(context); - Collection<VesselType> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - { - ZoneDAO ps = IsisFishDAOHelper.getZoneDAO(context); - Collection<Zone> list = ps.findAll(); - log.debug(list + " - " +ps.getClass().getName()); - } - context.rollbackTransaction(); - } -/* - public void testDelete() throws Exception { - TopiaContext context = this.context.beginTransaction(); - { - AgeGroupDAO ps = IsisFishDAOHelper.getAgeGroupDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - AgeGroup o = (AgeGroup)i.next(); - ps.delete(o); - } - } - { - RegionDAO ps = IsisFishDAOHelper.getRegionDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Region o = (Region)i.next(); - ps.delete(o); - } - } - { - CompositeZoneDAO ps = IsisFishDAOHelper.getCompositeZoneDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - CompositeZone o = (CompositeZone)i.next(); - ps.delete(o); - } - } - { - EffortDescriptionDAO ps = IsisFishDAOHelper.getEffortDescriptionDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - EffortDescription o = (EffortDescription)i.next(); - ps.delete(o); - } - } - { - EmigrationDAO ps = IsisFishDAOHelper.getEmigrationDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Emigration o = (Emigration)i.next(); - ps.delete(o); - } - } - { - EquationDAO ps = IsisFishDAOHelper.getEquationDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Equation o = (Equation)i.next(); - ps.delete(o); - } - } - { - GearDAO ps = IsisFishDAOHelper.getGearDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Gear o = (Gear)i.next(); - ps.delete(o); - } - } - { - ImmigrationDAO ps = IsisFishDAOHelper.getImmigrationDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Immigration o = (Immigration)i.next(); - ps.delete(o); - } - } - { - LengthGroupDAO ps = IsisFishDAOHelper.getLengthGroupDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - LengthGroup o = (LengthGroup)i.next(); - ps.delete(o); - } - } - { - MappingZoneReproZoneRecruDAO ps = IsisFishDAOHelper.getMappingZoneReproZoneRecruDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - MappingZoneReproZoneRecru o = (MappingZoneReproZoneRecru)i.next(); - ps.delete(o); - } - } - { - CellDAO ps = IsisFishDAOHelper.getCellDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Cell o = (Cell)i.next(); - ps.delete(o); - } - } - { - SpeciesDAO ps = IsisFishDAOHelper.getSpeciesDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Species o = (Species)i.next(); - ps.delete(o); - } - } - { - MetierDAO ps = IsisFishDAOHelper.getMetierDAO(context); - Metier o = ps.create(); - } - { - MetierSeasonInfoDAO ps = IsisFishDAOHelper.getMetierSeasonInfoDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - MetierSeasonInfo o = (MetierSeasonInfo)i.next(); - ps.delete(o); - } - } - { - MigrationDAO ps = IsisFishDAOHelper.getMigrationDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Migration o = (Migration)i.next(); - ps.delete(o); - } - } - { - MonthDAO ps = IsisFishDAOHelper.getMonthDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Month o = (Month)i.next(); - ps.delete(o); - } - } - { - PopulationGroupDAO ps = IsisFishDAOHelper.getPopulationGroupDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - PopulationGroup o = (PopulationGroup)i.next(); - ps.delete(o); - } - } - { - PopulationDAO ps = IsisFishDAOHelper.getPopulationDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Population o = (Population)i.next(); - ps.delete(o); - } - } - { - PortDAO ps = IsisFishDAOHelper.getPortDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Port o = (Port)i.next(); - ps.delete(o); - } - } - { - ResultManagerDAO ps = IsisFishDAOHelper.getResultManagerDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - ResultStorage o = (ResultStorage)i.next(); - ps.delete(o); - } - } - { - SeasonDAO ps = IsisFishDAOHelper.getSeasonDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Season o = (Season)i.next(); - ps.delete(o); - } - } - { - PopulationSeasonInfoDAO ps = IsisFishDAOHelper.getPopulationSeasonInfoDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - PopulationSeasonInfo o = (PopulationSeasonInfo)i.next(); - ps.delete(o); - } - } - { - SelectivityDAO ps = IsisFishDAOHelper.getSelectivityDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Selectivity o = (Selectivity)i.next(); - ps.delete(o); - } - } - { - SetOfVesselsDAO ps = IsisFishDAOHelper.getSetOfVesselsDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - SetOfVessels o = (SetOfVessels)i.next(); - ps.delete(o); - } - } - { - SimpleZoneDAO ps = IsisFishDAOHelper.getSimpleZoneDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - SimpleZone o = (SimpleZone)i.next(); - ps.delete(o); - } - } - { - StrategyMonthInfoDAO ps = IsisFishDAOHelper.getStrategyMonthInfoDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - StrategyMonthInfo o = (StrategyMonthInfo)i.next(); - ps.delete(o); - } - } - { - StrategyDAO ps = IsisFishDAOHelper.getStrategyDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Strategy o = (Strategy)i.next(); - ps.delete(o); - } - } - { - TargetSpeciesDAO ps = IsisFishDAOHelper.getTargetSpeciesDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - TargetSpecies o = (TargetSpecies)i.next(); - ps.delete(o); - } - } - { - TimeUnitDAO ps = IsisFishDAOHelper.getTimeUnitDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - TimeUnit o = (TimeUnit)i.next(); - ps.delete(o); - } - } - { - TripTypeDAO ps = IsisFishDAOHelper.getTripTypeDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - TripType o = (TripType)i.next(); - ps.delete(o); - } - } - { - VesselTypeDAO ps = IsisFishDAOHelper.getVesselTypeDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - VesselType o = (VesselType)i.next(); - ps.delete(o); - } - } - { - ZoneDAO ps = IsisFishDAOHelper.getZoneDAO(context); - Collection list = ps.findAll(); - for(Iterator i=list.iterator(); i.hasNext();){ - Zone o = (Zone)i.next(); - ps.delete(o); - } - } - context.rollbackTransaction(); - } - */ -} // Persistence - Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/AnalysePlanStorageTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/AnalysePlanStorageTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/AnalysePlanStorageTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -26,10 +26,10 @@ import java.util.Map; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFish; import freemarker.template.Configuration; import freemarker.template.Template; @@ -45,14 +45,13 @@ * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ * by : $Author: tchemit $ */ -public class AnalysePlanStorageTest { +public class AnalysePlanStorageTest extends AbstractIsisFishTest { - protected static Configuration freemarkerConfiguration; + protected Configuration freemarkerConfiguration; - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - freemarkerConfiguration = TestUtils.getFreemarkerConfiguration(); + @Before + public void setUp() throws Exception { + freemarkerConfiguration = getFreemarkerConfiguration(); } @Test @@ -81,11 +80,11 @@ template.process(root, out); out.flush(); String content = out.toString(); - + // remove it to compile, it's in isis fish data project Assert.assertTrue(content.indexOf("import scripts.ResultName;") > 0); content = content.replaceFirst("import scripts.ResultName;", ""); - + analysePlanStorage.setContent(content); // 0 = compile success Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/DataStorageTestHelper.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/DataStorageTestHelper.java (rev 0) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/DataStorageTestHelper.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -0,0 +1,56 @@ +/* *##% + * Copyright (C) 2009 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 org.junit.Ignore; + +/** + * Helper to acces protected static cache objects. + * + * @author chatellier + * @version $Revision: 1.0 $ + * + * Last update : $Date: 14 mai 2009 $ + * By : $Author: chatellier $ + */ + at Ignore +public class DataStorageTestHelper { + + /** + * Clear static simulation cache. + */ + public static void clearSimulationCache() { + SimulationStorage.simulations.clear(); + } + + /** + * Clear static region cache. + */ + public static void clearRegionCache() { + RegionStorage.regions.clear(); + } + + /** + * Clear all static cache. + */ + public static void clearAllCache() { + clearSimulationCache(); + clearRegionCache(); + } +} Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/ExportStorageTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/ExportStorageTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/ExportStorageTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -26,10 +26,10 @@ import java.util.Map; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFish; import freemarker.template.Configuration; import freemarker.template.Template; @@ -45,14 +45,13 @@ * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ * by : $Author: tchemit $ */ -public class ExportStorageTest { +public class ExportStorageTest extends AbstractIsisFishTest { - protected static Configuration freemarkerConfiguration; + protected Configuration freemarkerConfiguration; - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - freemarkerConfiguration = TestUtils.getFreemarkerConfiguration(); + @Before + public void setUp() throws Exception { + freemarkerConfiguration = getFreemarkerConfiguration(); } @Test @@ -60,8 +59,7 @@ String fileName = "TestExport1"; - ExportStorage exportStorage = ExportStorage - .getExport(fileName); + ExportStorage exportStorage = ExportStorage.getExport(fileName); // get template Template template = freemarkerConfiguration Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/FormuleStorageTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/FormuleStorageTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/FormuleStorageTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -25,10 +25,10 @@ import java.util.HashMap; import java.util.Map; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFish; import freemarker.template.Configuration; import freemarker.template.Template; @@ -44,14 +44,13 @@ * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ * by : $Author: tchemit $ */ -public class FormuleStorageTest { +public class FormuleStorageTest extends AbstractIsisFishTest { - protected static Configuration freemarkerConfiguration; + protected Configuration freemarkerConfiguration; - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - freemarkerConfiguration = TestUtils.getFreemarkerConfiguration(); + @Before + public void setUp() throws Exception { + freemarkerConfiguration = getFreemarkerConfiguration(); } @Test @@ -59,8 +58,8 @@ String fileName = "TestFormule1"; - FormuleStorage formuleStorage = FormuleStorage - .getFormule("test", fileName); + FormuleStorage formuleStorage = FormuleStorage.getFormule("test", + fileName); // get template Template template = freemarkerConfiguration Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/RuleStorageTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/RuleStorageTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/RuleStorageTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -26,10 +26,10 @@ import java.util.Map; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFish; import freemarker.template.Configuration; import freemarker.template.Template; @@ -45,14 +45,13 @@ * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ * by : $Author: tchemit $ */ -public class RuleStorageTest { +public class RuleStorageTest extends AbstractIsisFishTest { - protected static Configuration freemarkerConfiguration; + protected Configuration freemarkerConfiguration; - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - freemarkerConfiguration = TestUtils.getFreemarkerConfiguration(); + @Before + public void setUp() throws Exception { + freemarkerConfiguration = getFreemarkerConfiguration(); } @Test @@ -60,8 +59,7 @@ String fileName = "TestRule1"; - RuleStorage ruleStorage = RuleStorage - .getRule(fileName); + RuleStorage ruleStorage = RuleStorage.getRule(fileName); // get template Template template = freemarkerConfiguration @@ -81,11 +79,11 @@ template.process(root, out); out.flush(); String content = out.toString(); - + // remove it to compile, it's in isis fish data project Assert.assertTrue(content.indexOf("import scripts.ResultName;") > 0); content = content.replaceFirst("import scripts.ResultName;", ""); - + ruleStorage.setContent(content); // 0 = compile success Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/ScriptStorageTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/ScriptStorageTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/ScriptStorageTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -27,10 +27,10 @@ import org.codelutin.util.FileUtil; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFish; import freemarker.template.Configuration; import freemarker.template.Template; @@ -46,17 +46,13 @@ * Last update: $Date$ * by : $Author$ */ -public class ScriptStorageTest { +public class ScriptStorageTest extends AbstractIsisFishTest { - protected static Configuration freemarkerConfiguration; - - /* - * @see TestCase#setUp() - */ - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - freemarkerConfiguration = TestUtils.getFreemarkerConfiguration(); + protected Configuration freemarkerConfiguration; + + @Before + public void setUp() throws Exception { + freemarkerConfiguration = getFreemarkerConfiguration(); } /* @@ -95,8 +91,7 @@ String fileName = "TestScript1"; - ScriptStorage scriptStorage = ScriptStorage - .getScript(fileName); + ScriptStorage scriptStorage = ScriptStorage.getScript(fileName); // get template Template template = freemarkerConfiguration @@ -116,11 +111,11 @@ template.process(root, out); out.flush(); String content = out.toString(); - + // remove it to compile, it's in isis fish data project Assert.assertTrue(content.indexOf("import scripts.ResultName;") > 0); content = content.replaceFirst("import scripts.ResultName;", ""); - + scriptStorage.setContent(content); // 0 = compile success Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SensitivityStorageTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SensitivityStorageTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SensitivityStorageTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -26,10 +26,10 @@ import java.util.Map; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFish; import freemarker.template.Configuration; import freemarker.template.Template; @@ -45,14 +45,13 @@ * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ * by : $Author: tchemit $ */ -public class SensitivityStorageTest { +public class SensitivityStorageTest extends AbstractIsisFishTest { - protected static Configuration freemarkerConfiguration; + protected Configuration freemarkerConfiguration; - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - freemarkerConfiguration = TestUtils.getFreemarkerConfiguration(); + @Before + public void setUp() throws Exception { + freemarkerConfiguration = getFreemarkerConfiguration(); } @Test Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SimulatorStorageTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SimulatorStorageTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SimulatorStorageTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -26,10 +26,10 @@ import java.util.Map; import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFish; import freemarker.template.Configuration; import freemarker.template.Template; @@ -45,14 +45,13 @@ * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ * by : $Author: tchemit $ */ -public class SimulatorStorageTest { +public class SimulatorStorageTest extends AbstractIsisFishTest { - protected static Configuration freemarkerConfiguration; + protected Configuration freemarkerConfiguration; - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - freemarkerConfiguration = TestUtils.getFreemarkerConfiguration(); + @Before + public void setUp() throws Exception { + freemarkerConfiguration = getFreemarkerConfiguration(); } @Test Copied: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PersistenceTest.java (from rev 2214, isis-fish/trunk/src/test/java/fr/ifremer/isisfish/PersistenceTest.java) =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PersistenceTest.java (rev 0) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PersistenceTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -0,0 +1,759 @@ +/* *##% +* Copyright (C) 2002, 2009 Code Lutin, Cédric Pineau, Benjamin Poussin +* +* 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.entity; + +import java.util.Collection; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.TopiaContext; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import fr.ifremer.isisfish.AbstractIsisFishTest; +import fr.ifremer.isisfish.IsisFishDAOHelper; +import fr.ifremer.isisfish.datastore.RegionStorage; +import fr.ifremer.isisfish.entities.Cell; +import fr.ifremer.isisfish.entities.CellDAO; +import fr.ifremer.isisfish.entities.EffortDescription; +import fr.ifremer.isisfish.entities.EffortDescriptionDAO; +import fr.ifremer.isisfish.entities.FisheryRegion; +import fr.ifremer.isisfish.entities.FisheryRegionDAO; +import fr.ifremer.isisfish.entities.Gear; +import fr.ifremer.isisfish.entities.GearDAO; +import fr.ifremer.isisfish.entities.Metier; +import fr.ifremer.isisfish.entities.MetierDAO; +import fr.ifremer.isisfish.entities.MetierSeasonInfo; +import fr.ifremer.isisfish.entities.MetierSeasonInfoDAO; +import fr.ifremer.isisfish.entities.Population; +import fr.ifremer.isisfish.entities.PopulationDAO; +import fr.ifremer.isisfish.entities.PopulationGroup; +import fr.ifremer.isisfish.entities.PopulationGroupDAO; +import fr.ifremer.isisfish.entities.PopulationSeasonInfo; +import fr.ifremer.isisfish.entities.PopulationSeasonInfoDAO; +import fr.ifremer.isisfish.entities.Port; +import fr.ifremer.isisfish.entities.PortDAO; +import fr.ifremer.isisfish.entities.Result; +import fr.ifremer.isisfish.entities.ResultDAO; +import fr.ifremer.isisfish.entities.Season; +import fr.ifremer.isisfish.entities.SeasonDAO; +import fr.ifremer.isisfish.entities.Selectivity; +import fr.ifremer.isisfish.entities.SelectivityDAO; +import fr.ifremer.isisfish.entities.SetOfVessels; +import fr.ifremer.isisfish.entities.SetOfVesselsDAO; +import fr.ifremer.isisfish.entities.Species; +import fr.ifremer.isisfish.entities.SpeciesDAO; +import fr.ifremer.isisfish.entities.Strategy; +import fr.ifremer.isisfish.entities.StrategyDAO; +import fr.ifremer.isisfish.entities.StrategyMonthInfo; +import fr.ifremer.isisfish.entities.StrategyMonthInfoDAO; +import fr.ifremer.isisfish.entities.TargetSpecies; +import fr.ifremer.isisfish.entities.TargetSpeciesDAO; +import fr.ifremer.isisfish.entities.TripType; +import fr.ifremer.isisfish.entities.TripTypeDAO; +import fr.ifremer.isisfish.entities.VesselType; +import fr.ifremer.isisfish.entities.VesselTypeDAO; +import fr.ifremer.isisfish.entities.Zone; +import fr.ifremer.isisfish.entities.ZoneDAO; + +/** + * PersistenceTest. + * + * Created: 3 août 2004 + * + * @author Benjamin Poussin <poussin at codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class PersistenceTest extends AbstractIsisFishTest { + + /** + * Logger for this class + */ + private static final Log log = LogFactory.getLog(PersistenceTest.class); + + // Persistence + protected TopiaContext context = null; + protected RegionStorage rs; + + @Before + public void setUp() throws Exception { + rs = RegionStorage.create("test"); + context = rs.getStorage(); + } + + @After + public void tearDown() throws Exception { + rs.delete(false); + } + + @Test + public void testInstanciate() throws Exception { + TopiaContext context = this.context.beginTransaction(); + + FisheryRegionDAO fisheryRegionDAO = IsisFishDAOHelper.getFisheryRegionDAO(context); + FisheryRegion fisheryRegion = fisheryRegionDAO.create(); + log.debug(fisheryRegion + " - " + fisheryRegion.getClass().getName()); + + EffortDescriptionDAO effortDescriptionDAO = IsisFishDAOHelper.getEffortDescriptionDAO(context); + EffortDescription effortDescription = effortDescriptionDAO.create(); + log.debug(effortDescription + " - " + effortDescription.getClass().getName()); + + GearDAO gearDAO = IsisFishDAOHelper.getGearDAO(context); + Gear gear = gearDAO.create(); + log.debug(gear + " - " + gear.getClass().getName()); + + CellDAO cellDAO = IsisFishDAOHelper.getCellDAO(context); + Cell cell = cellDAO.create(); + log.debug(cell + " - " + cell.getClass().getName()); + + SpeciesDAO speciesDAO = IsisFishDAOHelper.getSpeciesDAO(context); + Species species = speciesDAO.create(); + log.debug(species + " - " + species.getClass().getName()); + + MetierDAO metierDAO = IsisFishDAOHelper.getMetierDAO(context); + Metier metier = metierDAO.create(); + log.debug(metier + " - " + metier.getClass().getName()); + + MetierSeasonInfoDAO metierSeasonInfoDAO = IsisFishDAOHelper.getMetierSeasonInfoDAO(context); + MetierSeasonInfo metierSeasonInfo = metierSeasonInfoDAO.create(); + log.debug(metierSeasonInfo + " - " +metierSeasonInfo.getClass().getName()); + + PopulationGroupDAO populationGroupDAO = IsisFishDAOHelper.getPopulationGroupDAO(context); + PopulationGroup populationGroup = populationGroupDAO.create(); + log.debug(populationGroup + " - " + populationGroup.getClass().getName()); + + PopulationDAO populationDAO = IsisFishDAOHelper.getPopulationDAO(context); + Population population = populationDAO.create(); + log.debug(population + " - " + population.getClass().getName()); + + PortDAO portDAO = IsisFishDAOHelper.getPortDAO(context); + Port port = portDAO.create(); + log.debug(port + " - " + port.getClass().getName()); + + ResultDAO resultDAO = IsisFishDAOHelper.getResultDAO(context); + Result result = resultDAO.create(); + log.debug(result + " - " + result.getClass().getName()); + + SeasonDAO seasonDAO = IsisFishDAOHelper.getSeasonDAO(context); + Season season = seasonDAO.create(); + log.debug(season + " - " + season.getClass().getName()); + + PopulationSeasonInfoDAO PopulationSeasonInfoDAO = IsisFishDAOHelper.getPopulationSeasonInfoDAO(context); + PopulationSeasonInfo PopulationSeasonInfo = PopulationSeasonInfoDAO.create(); + log.debug(PopulationSeasonInfo + " - " + PopulationSeasonInfo.getClass().getName()); + + SelectivityDAO selectivityDAO = IsisFishDAOHelper.getSelectivityDAO(context); + Selectivity selectivity = selectivityDAO.create(); + log.debug(selectivity + " - " + selectivity.getClass().getName()); + + SetOfVesselsDAO setOfVesselsDAO = IsisFishDAOHelper.getSetOfVesselsDAO(context); + SetOfVessels setOfVessels = setOfVesselsDAO.create(); + log.debug(setOfVessels + " - " + setOfVessels.getClass().getName()); + + StrategyMonthInfoDAO strategyMonthInfoDAO = IsisFishDAOHelper.getStrategyMonthInfoDAO(context); + StrategyMonthInfo strategyMonthInfo = strategyMonthInfoDAO.create(); + log.debug(strategyMonthInfo + " - " + strategyMonthInfo.getClass().getName()); + + StrategyDAO strategyDAO = IsisFishDAOHelper.getStrategyDAO(context); + Strategy strategy = strategyDAO.create(); + log.debug(strategy + " - " + strategy.getClass().getName()); + + TargetSpeciesDAO targetSpeciesDAO = IsisFishDAOHelper.getTargetSpeciesDAO(context); + TargetSpecies targetSpecies = targetSpeciesDAO.create(); + log.debug(targetSpecies + " - " + targetSpecies.getClass().getName()); + + TripTypeDAO tripTypeDAO = IsisFishDAOHelper.getTripTypeDAO(context); + TripType tripType = tripTypeDAO.create(); + log.debug(tripType + " - " + tripType.getClass().getName()); + + VesselTypeDAO vesselTypeDAO = IsisFishDAOHelper.getVesselTypeDAO(context); + VesselType vesselType = vesselTypeDAO.create(); + log.debug(vesselType + " - " + vesselType.getClass().getName()); + + ZoneDAO zoneDAO = IsisFishDAOHelper.getZoneDAO(context); + Zone zone = zoneDAO.create(); + log.debug(zone + " - " + zone.getClass().getName()); + + context.rollbackTransaction(); + } + + + @Test + public void testMakePersistence() throws Exception { + TopiaContext context = this.context.beginTransaction(); +// { +// AgeGroupDAO ps = IsisFishDAOHelper.getAgeGroupDAO(context); +// AgeGroup o = ps.create(); +// o = ps.update(o); +// } + { + FisheryRegionDAO ps = IsisFishDAOHelper.getFisheryRegionDAO(context); + FisheryRegion o = ps.create(); + o = ps.update(o); + } +// { +// CompositeZoneDAO ps = IsisFishDAOHelper.getCompositeZoneDAO(context); +// CompositeZone o = ps.create(); +// o = ps.update(o); +// } + { + EffortDescriptionDAO ps = IsisFishDAOHelper.getEffortDescriptionDAO(context); + EffortDescription o = ps.create(); + o = ps.update(o); + } +// { +// EmigrationDAO ps = IsisFishDAOHelper.getEmigrationDAO(context); +// Emigration o = ps.create(); +// o = ps.update(o); +// } +// { +// EquationDAO ps = IsisFishDAOHelper.getEquationDAO(context); +// Equation o = ps.create(); +// o = ps.update(o); +// } + { + GearDAO ps = IsisFishDAOHelper.getGearDAO(context); + Gear o = ps.create(); + o = ps.update(o); + } +// { +// ImmigrationDAO ps = IsisFishDAOHelper.getImmigrationDAO(context); +// Immigration o = ps.create(); +// o = ps.update(o); +// } +// { +// LengthGroupDAO ps = IsisFishDAOHelper.getLengthGroupDAO(context); +// LengthGroup o = ps.create(); +// o = ps.update(o); +// } +// { +// MappingZoneReproZoneRecruDAO ps = IsisFishDAOHelper.getMappingZoneReproZoneRecruDAO(context); +// MappingZoneReproZoneRecru o = ps.create(); +// o = ps.update(o); +// } + { + CellDAO ps = IsisFishDAOHelper.getCellDAO(context); + Cell o = ps.create(); + o = ps.update(o); + } + { + SpeciesDAO ps = IsisFishDAOHelper.getSpeciesDAO(context); + Species o = ps.create(); + o = ps.update(o); + } + { + MetierDAO ps = IsisFishDAOHelper.getMetierDAO(context); + Metier o = ps.create(); + o = ps.update(o); + } + { + MetierSeasonInfoDAO ps = IsisFishDAOHelper.getMetierSeasonInfoDAO(context); + MetierSeasonInfo o = ps.create(); + o = ps.update(o); + } +// { +// MigrationDAO ps = IsisFishDAOHelper.getMigrationDAO(context); +// Migration o = ps.create(); +// o = ps.update(o); +// } + { +// try{ + PopulationGroupDAO ps = IsisFishDAOHelper.getPopulationGroupDAO(context); + PopulationGroup o = ps.create(); + o = ps.update(o); +// assertTrue(false); // normalement on a pas le droit d'instancier une entity abstraite +// }catch(TopiaException eee){ +// assertTrue(true); +// } + } + { + PopulationDAO ps = IsisFishDAOHelper.getPopulationDAO(context); + Population o = ps.create(); + o = ps.update(o); + } + { + PortDAO ps = IsisFishDAOHelper.getPortDAO(context); + Port o = ps.create(); + o = ps.update(o); + } + { + ResultDAO ps = IsisFishDAOHelper.getResultDAO(context); + Result o = ps.create(); + o = ps.update(o); + } + { + PopulationSeasonInfoDAO ps = IsisFishDAOHelper.getPopulationSeasonInfoDAO(context); + PopulationSeasonInfo o = ps.create(); + o = ps.update(o); + } + { + SelectivityDAO ps = IsisFishDAOHelper.getSelectivityDAO(context); + Selectivity o = ps.create(); + o = ps.update(o); + } + { + SetOfVesselsDAO ps = IsisFishDAOHelper.getSetOfVesselsDAO(context); + SetOfVessels o = ps.create(); + o = ps.update(o); + } +// { +// SimpleZoneDAO ps = IsisFishDAOHelper.getSimpleZoneDAO(context); +// SimpleZone o = ps.create(); +// o = ps.update(o); +// } + { + StrategyMonthInfoDAO ps = IsisFishDAOHelper.getStrategyMonthInfoDAO(context); + StrategyMonthInfo o = ps.create(); + o = ps.update(o); + } + { + StrategyDAO ps = IsisFishDAOHelper.getStrategyDAO(context); + Strategy o = ps.create(); + o = ps.update(o); + } + { + TargetSpeciesDAO ps = IsisFishDAOHelper.getTargetSpeciesDAO(context); + TargetSpecies o = ps.create(); + o = ps.update(o); + } + { + TripTypeDAO ps = IsisFishDAOHelper.getTripTypeDAO(context); + TripType o = ps.create(); + o = ps.update(o); + } + { + VesselTypeDAO ps = IsisFishDAOHelper.getVesselTypeDAO(context); + VesselType o = ps.create(); + o = ps.update(o); + } + { + ZoneDAO ps = IsisFishDAOHelper.getZoneDAO(context); + Zone o = ps.create(); + o = ps.update(o); + } + context.rollbackTransaction(); + } + + @Test + public void testFindAll() throws Exception { + TopiaContext context = this.context.beginTransaction(); +// { +// AgeGroupDAO ps = IsisFishDAOHelper.getAgeGroupDAO(context); +// Collection<AgeGroup> list = ps.findAll(); +// log.debug(list + " - " +ps.getClass().getName()); +// } + { + FisheryRegionDAO ps = IsisFishDAOHelper.getFisheryRegionDAO(context); + Collection<FisheryRegion> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } +// { +// CompositeZoneDAO ps = IsisFishDAOHelper.getCompositeZoneDAO(context); +// Collection list<CompositeZone> = ps.findAll(); +// } + { + EffortDescriptionDAO ps = IsisFishDAOHelper.getEffortDescriptionDAO(context); + Collection<EffortDescription> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } +// { +// EmigrationDAO ps = IsisFishDAOHelper.getEmigrationDAO(context); +// Collection<Emigration> list = ps.findAll(); +// log.debug(list + " - " +ps.getClass().getName()); +// } + { + GearDAO ps = IsisFishDAOHelper.getGearDAO(context); + Collection<Gear> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } +// { +// ImmigrationDAO ps = IsisFishDAOHelper.getImmigrationDAO(context); +// Collection<Immigration> list = ps.findAll(); +// log.debug(list + " - " +ps.getClass().getName()); +// } +// { +// LengthGroupDAO ps = IsisFishDAOHelper.getLengthGroupDAO(context); +// Collection<LengthGroup> list = ps.findAll(); +// log.debug(list + " - " +ps.getClass().getName()); +// } +// { +// MappingZoneReproZoneRecruDAO ps = IsisFishDAOHelper.getMappingZoneReproZoneRecruDAO(context); +// Collection<MappingZoneReproZoneRecru> list = ps.findAll(); +// log.debug(list + " - " +ps.getClass().getName()); +// } + { + CellDAO ps = IsisFishDAOHelper.getCellDAO(context); + Collection<Cell> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + SpeciesDAO ps = IsisFishDAOHelper.getSpeciesDAO(context); + Collection<Species> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + MetierDAO ps = IsisFishDAOHelper.getMetierDAO(context); + Collection<Metier> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + MetierSeasonInfoDAO ps = IsisFishDAOHelper.getMetierSeasonInfoDAO(context); + Collection<MetierSeasonInfo> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } +// { +// MigrationDAO ps = IsisFishDAOHelper.getMigrationDAO(context); +// Collection<Migration> list = ps.findAll(); +// log.debug(list + " - " +ps.getClass().getName()); +// } + { + PopulationGroupDAO ps = IsisFishDAOHelper.getPopulationGroupDAO(context); + Collection<PopulationGroup> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + PopulationDAO ps = IsisFishDAOHelper.getPopulationDAO(context); + Collection<Population> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + PortDAO ps = IsisFishDAOHelper.getPortDAO(context); + Collection<Port> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + ResultDAO ps = IsisFishDAOHelper.getResultDAO(context); + Collection<Result> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + PopulationSeasonInfoDAO ps = IsisFishDAOHelper.getPopulationSeasonInfoDAO(context); + Collection<PopulationSeasonInfo> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + SelectivityDAO ps = IsisFishDAOHelper.getSelectivityDAO(context); + Collection<Selectivity> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + SetOfVesselsDAO ps = IsisFishDAOHelper.getSetOfVesselsDAO(context); + Collection<SetOfVessels> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } +// { +// SimpleZoneDAO ps = IsisFishDAOHelper.getSimpleZoneDAO(context); +// Collection<SimpleZone> list = ps.findAll(); +// } + { + StrategyMonthInfoDAO ps = IsisFishDAOHelper.getStrategyMonthInfoDAO(context); + Collection<StrategyMonthInfo> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + StrategyDAO ps = IsisFishDAOHelper.getStrategyDAO(context); + Collection<Strategy> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + TargetSpeciesDAO ps = IsisFishDAOHelper.getTargetSpeciesDAO(context); + Collection<TargetSpecies> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + TripTypeDAO ps = IsisFishDAOHelper.getTripTypeDAO(context); + Collection<TripType> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + VesselTypeDAO ps = IsisFishDAOHelper.getVesselTypeDAO(context); + Collection<VesselType> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + { + ZoneDAO ps = IsisFishDAOHelper.getZoneDAO(context); + Collection<Zone> list = ps.findAll(); + log.debug(list + " - " +ps.getClass().getName()); + } + context.rollbackTransaction(); + } +/* + public void testDelete() throws Exception { + TopiaContext context = this.context.beginTransaction(); + { + AgeGroupDAO ps = IsisFishDAOHelper.getAgeGroupDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + AgeGroup o = (AgeGroup)i.next(); + ps.delete(o); + } + } + { + RegionDAO ps = IsisFishDAOHelper.getRegionDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Region o = (Region)i.next(); + ps.delete(o); + } + } + { + CompositeZoneDAO ps = IsisFishDAOHelper.getCompositeZoneDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + CompositeZone o = (CompositeZone)i.next(); + ps.delete(o); + } + } + { + EffortDescriptionDAO ps = IsisFishDAOHelper.getEffortDescriptionDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + EffortDescription o = (EffortDescription)i.next(); + ps.delete(o); + } + } + { + EmigrationDAO ps = IsisFishDAOHelper.getEmigrationDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Emigration o = (Emigration)i.next(); + ps.delete(o); + } + } + { + EquationDAO ps = IsisFishDAOHelper.getEquationDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Equation o = (Equation)i.next(); + ps.delete(o); + } + } + { + GearDAO ps = IsisFishDAOHelper.getGearDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Gear o = (Gear)i.next(); + ps.delete(o); + } + } + { + ImmigrationDAO ps = IsisFishDAOHelper.getImmigrationDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Immigration o = (Immigration)i.next(); + ps.delete(o); + } + } + { + LengthGroupDAO ps = IsisFishDAOHelper.getLengthGroupDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + LengthGroup o = (LengthGroup)i.next(); + ps.delete(o); + } + } + { + MappingZoneReproZoneRecruDAO ps = IsisFishDAOHelper.getMappingZoneReproZoneRecruDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + MappingZoneReproZoneRecru o = (MappingZoneReproZoneRecru)i.next(); + ps.delete(o); + } + } + { + CellDAO ps = IsisFishDAOHelper.getCellDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Cell o = (Cell)i.next(); + ps.delete(o); + } + } + { + SpeciesDAO ps = IsisFishDAOHelper.getSpeciesDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Species o = (Species)i.next(); + ps.delete(o); + } + } + { + MetierDAO ps = IsisFishDAOHelper.getMetierDAO(context); + Metier o = ps.create(); + } + { + MetierSeasonInfoDAO ps = IsisFishDAOHelper.getMetierSeasonInfoDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + MetierSeasonInfo o = (MetierSeasonInfo)i.next(); + ps.delete(o); + } + } + { + MigrationDAO ps = IsisFishDAOHelper.getMigrationDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Migration o = (Migration)i.next(); + ps.delete(o); + } + } + { + MonthDAO ps = IsisFishDAOHelper.getMonthDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Month o = (Month)i.next(); + ps.delete(o); + } + } + { + PopulationGroupDAO ps = IsisFishDAOHelper.getPopulationGroupDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + PopulationGroup o = (PopulationGroup)i.next(); + ps.delete(o); + } + } + { + PopulationDAO ps = IsisFishDAOHelper.getPopulationDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Population o = (Population)i.next(); + ps.delete(o); + } + } + { + PortDAO ps = IsisFishDAOHelper.getPortDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Port o = (Port)i.next(); + ps.delete(o); + } + } + { + ResultManagerDAO ps = IsisFishDAOHelper.getResultManagerDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + ResultStorage o = (ResultStorage)i.next(); + ps.delete(o); + } + } + { + SeasonDAO ps = IsisFishDAOHelper.getSeasonDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Season o = (Season)i.next(); + ps.delete(o); + } + } + { + PopulationSeasonInfoDAO ps = IsisFishDAOHelper.getPopulationSeasonInfoDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + PopulationSeasonInfo o = (PopulationSeasonInfo)i.next(); + ps.delete(o); + } + } + { + SelectivityDAO ps = IsisFishDAOHelper.getSelectivityDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Selectivity o = (Selectivity)i.next(); + ps.delete(o); + } + } + { + SetOfVesselsDAO ps = IsisFishDAOHelper.getSetOfVesselsDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + SetOfVessels o = (SetOfVessels)i.next(); + ps.delete(o); + } + } + { + SimpleZoneDAO ps = IsisFishDAOHelper.getSimpleZoneDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + SimpleZone o = (SimpleZone)i.next(); + ps.delete(o); + } + } + { + StrategyMonthInfoDAO ps = IsisFishDAOHelper.getStrategyMonthInfoDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + StrategyMonthInfo o = (StrategyMonthInfo)i.next(); + ps.delete(o); + } + } + { + StrategyDAO ps = IsisFishDAOHelper.getStrategyDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Strategy o = (Strategy)i.next(); + ps.delete(o); + } + } + { + TargetSpeciesDAO ps = IsisFishDAOHelper.getTargetSpeciesDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + TargetSpecies o = (TargetSpecies)i.next(); + ps.delete(o); + } + } + { + TimeUnitDAO ps = IsisFishDAOHelper.getTimeUnitDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + TimeUnit o = (TimeUnit)i.next(); + ps.delete(o); + } + } + { + TripTypeDAO ps = IsisFishDAOHelper.getTripTypeDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + TripType o = (TripType)i.next(); + ps.delete(o); + } + } + { + VesselTypeDAO ps = IsisFishDAOHelper.getVesselTypeDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + VesselType o = (VesselType)i.next(); + ps.delete(o); + } + } + { + ZoneDAO ps = IsisFishDAOHelper.getZoneDAO(context); + Collection list = ps.findAll(); + for(Iterator i=list.iterator(); i.hasNext();){ + Zone o = (Zone)i.next(); + ps.delete(o); + } + } + context.rollbackTransaction(); + } + */ +} // Persistence + Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -39,6 +39,8 @@ import org.codelutin.math.matrix.gui.MatrixPanelEditor; import org.junit.Test; +import fr.ifremer.isisfish.AbstractIsisFishTest; + /** * PopulationSeasonInfoTest. * @@ -50,14 +52,15 @@ * Last update: $Date$ * by : $Author$ */ -public class PopulationSeasonInfoTest{ - +public class PopulationSeasonInfoTest extends AbstractIsisFishTest { + /** Logger for this class */ - private static final Log log = LogFactory.getLog(PopulationSeasonInfoTest.class); - + private static final Log log = LogFactory + .getLog(PopulationSeasonInfoTest.class); + @Test public void testToString() { - String [] s = new String[]{"toto", "titi", "tutu"}; + String[] s = new String[] { "toto", "titi", "tutu" }; System.out.println(Arrays.toString(s)); } @@ -73,28 +76,27 @@ List<String> sem = new ArrayList<String>(); - for (int i=0; i<nbrAge; i++) { - for (int j=0; j<nbrZone; j++) { + for (int i = 0; i < nbrAge; i++) { + for (int j = 0; j < nbrZone; j++) { sem.add("g" + i + "/z" + j); } } - MatrixND mat = MatrixFactory.getInstance().create(new List[]{sem, sem}); - for(MatrixIterator mi=mat.iterator(); mi.next();){ - int [] dim = mi.getCoordinates(); + MatrixND mat = MatrixFactory.getInstance().create( + new List[] { sem, sem }); + for (MatrixIterator mi = mat.iterator(); mi.next();) { + int[] dim = mi.getCoordinates(); int i = dim[0]; int j = dim[1]; - if( - // un element de la diagonale dans le block choisi - (i+nbrZone == j) - || // calcul pour savoir s'il y a le groupe plus + if ( + // un element de la diagonale dans le block choisi + (i + nbrZone == j) || // calcul pour savoir s'il y a le groupe plus (groupplus // regarde si on est bien dans le dernier block - && (nbrAge-1 == i/nbrZone) + && (nbrAge - 1 == i / nbrZone) // regarde si on est bien sur la diagonal - && (i == j)) - ){ + && (i == j))) { mi.setValue(1); } } @@ -106,12 +108,14 @@ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - - JOptionPane.showMessageDialog(dialog, panel,_("Spacialized visualisation"), JOptionPane.INFORMATION_MESSAGE); - + + JOptionPane.showMessageDialog(dialog, panel, + _("Spacialized visualisation"), + JOptionPane.INFORMATION_MESSAGE); + } }); - + Thread t = new Thread(new Runnable() { public void run() { try { @@ -123,12 +127,12 @@ } }); t.start(); - + // it would really be nice to wait the thread, otherwise the test // means nothing!!! t.join(); } catch (HeadlessException he) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("No X11 display available", he); } } @@ -142,31 +146,34 @@ @Test public void testSpacializeLengthChangeMatrix() throws InterruptedException { - int nbsecteurs = 2; int nbclasses = 3; - MatrixND mat = MatrixFactory.getInstance().create(new int[]{nbclasses, nbclasses}); - int i=1; - for (MatrixIterator mi=mat.iterator(); mi.next();) { + MatrixND mat = MatrixFactory.getInstance().create( + new int[] { nbclasses, nbclasses }); + int i = 1; + for (MatrixIterator mi = mat.iterator(); mi.next();) { mi.setValue(i++); } List<String> sem = new ArrayList<String>(); - for (i=0; i<nbclasses; i++) { - for (int j=0; j<nbsecteurs; j++) { + for (i = 0; i < nbclasses; i++) { + for (int j = 0; j < nbsecteurs; j++) { sem.add("g" + i + "/z" + j); } } - MatrixND bigmat = MatrixFactory.getInstance().create(new List[]{sem, sem}); + MatrixND bigmat = MatrixFactory.getInstance().create( + new List[] { sem, sem }); - for(i=0; i<nbclasses; i++){ - for(int j=0; j<nbclasses; j++){ - MatrixND matId = MatrixFactory.getInstance().matrixId(nbsecteurs); - matId.mults(mat.getValue(i,j)); - bigmat.paste(new int[]{i*nbsecteurs, j*nbsecteurs}, matId); + for (i = 0; i < nbclasses; i++) { + for (int j = 0; j < nbclasses; j++) { + MatrixND matId = MatrixFactory.getInstance().matrixId( + nbsecteurs); + matId.mults(mat.getValue(i, j)); + bigmat.paste(new int[] { i * nbsecteurs, j * nbsecteurs }, + matId); } } @@ -184,12 +191,14 @@ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - - JOptionPane.showMessageDialog(dialog, box, _("Spacialized visualisation"), JOptionPane.INFORMATION_MESSAGE); - + + JOptionPane.showMessageDialog(dialog, box, + _("Spacialized visualisation"), + JOptionPane.INFORMATION_MESSAGE); + } }); - + Thread t = new Thread(new Runnable() { public void run() { try { @@ -201,12 +210,12 @@ } }); t.start(); - + // it would really be nice to wait the thread, otherwise the test // means nothing!!! t.join(); } catch (HeadlessException he) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("No X11 display available", he); } } Copied: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/LoggerHelper.java (from rev 2214, isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/TestUtil.java) =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/LoggerHelper.java (rev 0) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/LoggerHelper.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -0,0 +1,413 @@ +/* *##% + * Copyright (C) 2009 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.logging; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.StringUtil; + +/** + * Usefull methods for tests. + * + * @author chemit + */ +public abstract class LoggerHelper { + + public static String filename; + public static long MEGA_STREAM_SIZE = 6 * 100000; + private static long totalPause; + + protected static final Log log = LogFactory.getLog(LoggerHelper.class); + + public static void createMock(File testDir, String filename, int i) throws IOException, InterruptedException { + LoggerHelper.MEGA_STREAM_SIZE = 6 * i; + LoggerHelper.filename = new File(testDir, filename).getAbsolutePath(); + File file = new File(testDir, filename); + long t0 = System.nanoTime(); + mockLogFile(); + long t1; + + t1 = System.nanoTime(); + log.info("create [" + LoggerHelper.MEGA_STREAM_SIZE + "] in " + StringUtil.convertTime(t1 - t0) + " [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "]"); + System.gc(); + } + + static void pause(long time) throws InterruptedException { + Thread.sleep(time); + totalPause += time; + System.gc(); + } + + /** + * create a mock of logEvents + * + * @throws java.io.IOException todo + * @throws InterruptedException todo + */ + public static void mockLogFile() throws IOException, InterruptedException { + File f = new File(filename); + if (f.exists()) { + f.delete(); + } + BufferedWriter s = new BufferedWriter(new FileWriter(f)); + int MAX_0 = (int) (MEGA_STREAM_SIZE / 6); + int i = 0; + long t0, t00; + long t1; + totalPause = 0; + t00 = System.currentTimeMillis(); + t0 = System.currentTimeMillis(); + try { + + for (i = 0; i < MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.FATAL, 0, i + "debug ", "ioreiovrio veuio vreupo xz xe opiu tep uxr u ", "xeoiujoiz xpo puoi rui hp", i, new String[0]); + s.write(record.toString() + '\n'); + s.flush(); + } + + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + + for (i = MAX_0; i < 2 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.WARN, 0, i + " warn", "jkljfdjkl fdkjlkj lkjdlkfjl dfkljl dflkfdj lfdjlk fjdlkj fdl", "vmfof o rieipk?prj,anklvndfkljn gmlrtsoijrmoig", i, new String[0]); + s.write(record.toString() + '\n'); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + for (i = 2 * MAX_0; i < 3 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.INFO, 0, i + " info", "grlgjlrmgr jglerj mgrjm gre pjkogremoiqp jgpo rejopigjrej,m", "grkgherjfezoprjgbpdofajhlbnb;k nfkfjgmjmsg", i, new String[0]); + s.write(record.toString() + '\n'); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + for (i = 3 * MAX_0; i < 4 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.DEBUG, 0, i + " debug", "grmgjueroijiorehjnjodj j gn mbr,nhltrhjjdo jp joi jreio j", "gezoeteroiyerphehkzb,fgbd bcmsherkgheiusbcjkdvberb ", i, new String[0]); + s.write(record.toString() + '\n'); + s.flush(); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + for (i = 4 * MAX_0; i < 5 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " trace", "ffgkdhvlsdknjk eriopgejo ipjiropj i io poi opijgr pe jupoieruj ga geigerihpi oeop erp ", "griofeioteogbbekjbnrjemk prejrlmekhgrehivbn rekhgrhi ", i, new String[0]); + s.write(record.toString() + '\n'); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + for (i = 5 * MAX_0; i < 6 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " user", "grekgrhze t e re klgre ge rgre gre gfer g rjyukj yujty reez ze fz", "gekfhezh zhrze hgerhglkrej ljbvkxdfn df,ekgrrnvkmn", i, new String[0]); + s.write(record.toString() + '\n'); + s.flush(); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + } catch (OutOfMemoryError e) { + t1 = System.currentTimeMillis(); + log.info("failed after | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + e.printStackTrace(); + } finally { + if (s != null) { + s.flush(); + s.close(); + } + } + } + + /** + * create a mock of logEvents + * + * @throws java.io.IOException todo + * @throws InterruptedException todo + */ + public static void mockLogFile2() throws IOException, InterruptedException { + File f = new File(filename); + if (f.exists()) { + f.delete(); + } + BufferedWriter s = new BufferedWriter(new FileWriter(f)); + int MAX_0 = (int) (MEGA_STREAM_SIZE / 6); + int i = 0; + long t0, t00; + long t1; + totalPause = 0; + t00 = System.currentTimeMillis(); + t0 = System.currentTimeMillis(); + try { + + for (i = 0; i < MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.FATAL, 0, i + "debug ", "ioreiovrio veuio vreupo xz xe opiu tep uxr u ", "xeoiujoiz xpo puoi rui hp", i, new String[0]); + s.write(record.toString() + '\n'); + s.flush(); + } + + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + + for (i = MAX_0; i < 2 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.WARN, 0, i + " warn", "jkljfdjkl fdkjlkj lkjdlkfjl dfkljl dflkfdj lfdjlk fjdlkj fdl", "vmfof o rieipk?prj,ùnklvndfkljn gmlrtsoîjrmoig", i, new String[0]); + s.write(record.toString() + '\n'); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + for (i = 2 * MAX_0; i < 3 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.INFO, 0, i + " info", "grlgjlrmgr jglerj mgrjm gre pjkogremoiqp jgpo rejopigjrej,m", "grkgherjfezoprjgbpdofùjhlbnb;k nfkfjgmjmsg", i, new String[0]); + s.write(record.toString() + '\n'); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + for (i = 3 * MAX_0; i < 4 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.DEBUG, 0, i + " debug", "grmgjueroijiorehjnjodj j gn mbr,nhltrhjjdo jp joi jreio j", "gezoeteroiyerphehkzb,fgbd bcmsherkgheiusbcjkdvberb ", i, new String[0]); + s.write(record.toString() + '\n'); + s.flush(); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + for (i = 4 * MAX_0; i < 5 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " trace", "ffgkdhvlsdknjk eriopgejo ipjiropj i io poi opijgr pe jupoieruj g'^ geigerihpi oeop erp ", "griofeioteogbbekjbnrjemk çprejrlmekhgrehivbn rekhgrhi ", i, new String[0]); + s.write(record.toString() + '\n'); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + //pause(500); + t0 = System.currentTimeMillis(); + for (i = 5 * MAX_0; i < 6 * MAX_0; i++) { + LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " user", "grekgrhze t e re klgre ge rgre gre gfer g rjyukj yujty reez ze fz", "gekfhezh zhrze hgerhglkrej ljbvkxdfn df,ekgrrnvkmn", i, new String[0]); + s.write(record.toString() + '\n'); + s.flush(); + } + t1 = System.currentTimeMillis(); + log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + } catch (OutOfMemoryError e) { + t1 = System.currentTimeMillis(); + log.info("failed after | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); + e.printStackTrace(); + } finally { + if (s != null) { + s.flush(); + s.close(); + } + } + } + + /** + * This is a log record (says an entry of a log file). This is abstracted from any + * logging implementation. + * <p/> + * To deal with log, we don't use string version stored in original log file, + * prefer use serialized form of a LogRecord : we keep a lot of time when using + * them to display them in ui, and for filtering process too. + * <p/> + * The LogRecord unicity is base on two properties : + * <ul> + * <li>timestamp</li> + * <li>message</li> + * </ul> + * <p/> + * We can not use only timestamp, more than one event could appear in a same + * timestamp. + * <p/> + * TODO Put this code in lutinLog ? + * + * @author chemit + */ + public static class LogRecord implements java.io.Serializable { + + /** the time of the event */ + protected long timeStamp; + + /** the msg for the event */ + protected String message; + + /** the severity of the event */ + protected int level; + + /** the throwable details the event */ + protected String[] throwableStrRep; + + /** origin filename of the event */ + //protected transient String filename; + + /** origin method name of the event */ + //protected transient String methodName; + + /** origin line number of the event */ + //protected transient int lineNumber; + + /** + * the string represention of logEvent, transient since we use a lazy getter + * we don't need to store it. + * <p/> + * <b>(if not transient : double the size of serialized form...)</b> + */ + protected transient String text; + + /** + * the offset of logRecord in stream. + * <p/> + * This is a transient property, since we compute this value when getting + * the LogRecord from stream + */ + protected transient long offset; + + private static final long serialVersionUID = 1335077740059488080L; + + public static LogRecord newInstance(LogLevel level, + long timestamp, + String message, + String fileName, + String methodName, + int lineNumber, + String[] errors) throws UnsupportedEncodingException { + return new LogRecord( + level == null ? LogLevel.DEBUG.ordinal() : level.ordinal(), + timestamp, + message, + fileName, + methodName, + lineNumber, + errors + ); + } + + protected LogRecord(int level, + long timestamp, + String message, + String filename, + String methodName, + int lineNumber, + String[] throwableStrRep) throws UnsupportedEncodingException { + this.level = level; + this.timeStamp = timestamp; + //this.message = message; + this.message = new String((filename + ":" + lineNumber + " - " + methodName + " - " + message).getBytes("utf-8")); + //this.filename = filename; + //this.methodName = methodName; + //this.lineNumber = lineNumber; + this.throwableStrRep = throwableStrRep; + } + + public String getMessage() { + return message; + } + + public int getLevel() { + return level; + } + + public String[] getThrowableStrRep() { + return throwableStrRep; + } + + public long getTimeStamp() { + return timeStamp; + } + + public int getLineNumber() { + return 0; + //return lineNumber; + } + + public String getMethodName() { + return ""; + //return methodName; + } + + public long getOffset() { + return offset; + } + + public void setOffset(long offset) { + this.offset = offset; + } + + /** + * We use a cache for the representation since we will use a lots of time. + * + * @return the String representation used to display logEvent in ui. + */ + @Override + public String toString() { + if (text == null) { + text = new StringBuilder(LogLevel.getLogLevel(level).toString()). + append(' ').append(message).toString(); + } + /*if (text == null) { + text = new StringBuilder().append(LogLevel.getSimulLogLevel(level)). + append(' ').append(filename).append(':'). + append(lineNumber).append(" - "). + append(methodName).append(" - ").append(message).toString(); + }*/ + return text; + } + + /** + * We base the identiy of a LogEvent on the message, level and timestamp + * + * @param o object to compare + * @return <code>true</code> if same object + */ + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + LogRecord event = (LogRecord) o; + return timeStamp == event.timeStamp && + !(message != null ? !message.equals(event.message) : + event.message != null); + } + + @Override + public int hashCode() { + int result; + result = (int) (timeStamp ^ (timeStamp >>> 32)); + result = 31 * result + (message != null ? message.hashCode() : 0); + return result; + } + + } +} Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/SimulationLoggerUtilTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/SimulationLoggerUtilTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/SimulationLoggerUtilTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -1,20 +1,39 @@ +/* *##% + * Copyright (C) 2009 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.logging; +import java.io.File; +import java.util.ArrayList; +import java.util.List; -import fr.ifremer.TestUtils; import junit.framework.Assert; -import junit.framework.TestCase; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.codelutin.util.FileUtil; +import org.junit.Test; -import java.io.File; -import java.util.ArrayList; -import java.util.List; +import fr.ifremer.isisfish.AbstractIsisFishTest; -public class SimulationLoggerUtilTest extends TestCase { +public class SimulationLoggerUtilTest extends AbstractIsisFishTest { static private final String category = "fr.ifremer.isisfish.logging"; @@ -22,10 +41,9 @@ static private Log log = LogFactory.getLog(category); + @Test public void testSimulationLoggerInfo() throws Exception { - TestUtil.IsisStart(); - Log logInit = LogFactory.getLog(appenderId); Log logInit2 = LogFactory.getLog(appenderId + ".hip"); @@ -44,7 +62,7 @@ Level hibernateLogLevel = hibernatelog.getLevel(); - String loggerFile = new File(TestUtils.getTargetdir(), SimulationLoggerUtilTest.class.getSimpleName() + "_" + System.nanoTime() + ".log").getAbsolutePath(); + String loggerFile = new File(getTargetdir(), SimulationLoggerUtilTest.class.getSimpleName() + "_" + System.nanoTime() + ".log").getAbsolutePath(); System.out.println(">>>> loggerFile " + loggerFile); // todo do a test for addSimulationAppender too! @@ -58,7 +76,7 @@ ); // check hibernate level was not changed - assertEquals(hibernateLogLevel, Logger.getLogger("org.hibernate").getLevel()); + Assert.assertEquals(hibernateLogLevel, Logger.getLogger("org.hibernate").getLevel()); final Log logger = LogFactory.getLog(appenderId); @@ -92,7 +110,7 @@ // it would really be nice to wait the thread, otherwise the test // means nothing!!! t.join(); - assertTrue(!t.isAlive()); + Assert.assertTrue(!t.isAlive()); SimulationLoggerUtil.removeSimulationAppender(appenderId); message = "appender was destoyed WE MUST NOT SEE this message in simulation log file!!!"; @@ -128,10 +146,9 @@ } + @Test public void testSimulationLoggerDebug() throws Exception { - TestUtil.IsisStart(); - Log logInit = LogFactory.getLog(appenderId); Log logInit2 = LogFactory.getLog(appenderId + ".hip"); @@ -162,7 +179,7 @@ ); // check hibernate level was not changed - assertEquals(hibernateLogLevel, Logger.getLogger("org.hibernate").getLevel()); + Assert.assertEquals(hibernateLogLevel, Logger.getLogger("org.hibernate").getLevel()); final Log logger = LogFactory.getLog(appenderId); @@ -196,7 +213,7 @@ // it would really be nice to wait the thread, otherwise the test // means nothing!!! t.join(); - assertTrue(!t.isAlive()); + Assert.assertTrue(!t.isAlive()); SimulationLoggerUtil.removeSimulationAppender(appenderId); message = "appender was destoyed WE MUST NOT SEE this message in simulation log file!!!"; Deleted: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/TestUtil.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/TestUtil.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/TestUtil.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -1,408 +0,0 @@ -package fr.ifremer.isisfish.logging; - -import fr.ifremer.TestUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.log.LutinLogFactory; -import org.codelutin.util.StringUtil; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.UnsupportedEncodingException; - -/** - * Usefull methods for tests. - * - * @author chemit - */ - -public abstract class TestUtil { - - public static String filename; - public static long MEGA_STREAM_SIZE = 6 * 100000; - private static long totalPause; - - protected static final Log log = LogFactory.getLog(TestUtil.class); - - public static void createMock(File testDir, String filename, int i) throws IOException, InterruptedException { - TestUtil.MEGA_STREAM_SIZE = 6 * i; - TestUtil.filename = new File(testDir, filename).getAbsolutePath(); - File file = new File(testDir, filename); - long t0 = System.nanoTime(); - mockLogFile(); - long t1; - - t1 = System.nanoTime(); - log.info("create [" + TestUtil.MEGA_STREAM_SIZE + "] in " + StringUtil.convertTime(t1 - t0) + " [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "]"); - System.gc(); - } - - static void pause(long time) throws InterruptedException { - Thread.sleep(time); - totalPause += time; - System.gc(); - } - - /** - * create a mock of logEvents - * - * @throws java.io.IOException todo - * @throws InterruptedException todo - */ - public static void mockLogFile() throws IOException, InterruptedException { - File f = new File(filename); - if (f.exists()) { - f.delete(); - } - BufferedWriter s = new BufferedWriter(new FileWriter(f)); - int MAX_0 = (int) (MEGA_STREAM_SIZE / 6); - int i = 0; - long t0, t00; - long t1; - totalPause = 0; - t00 = System.currentTimeMillis(); - t0 = System.currentTimeMillis(); - try { - - for (i = 0; i < MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.FATAL, 0, i + "debug ", "ioreiovrio veuio vreupo xz xe opiu tep uxr u ", "xeoiujoiz xpo puoi rui hp", i, new String[0]); - s.write(record.toString() + '\n'); - s.flush(); - } - - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - - for (i = MAX_0; i < 2 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.WARN, 0, i + " warn", "jkljfdjkl fdkjlkj lkjdlkfjl dfkljl dflkfdj lfdjlk fjdlkj fdl", "vmfof o rieipk?prj,anklvndfkljn gmlrtsoijrmoig", i, new String[0]); - s.write(record.toString() + '\n'); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - for (i = 2 * MAX_0; i < 3 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.INFO, 0, i + " info", "grlgjlrmgr jglerj mgrjm gre pjkogremoiqp jgpo rejopigjrej,m", "grkgherjfezoprjgbpdofajhlbnb;k nfkfjgmjmsg", i, new String[0]); - s.write(record.toString() + '\n'); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - for (i = 3 * MAX_0; i < 4 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.DEBUG, 0, i + " debug", "grmgjueroijiorehjnjodj j gn mbr,nhltrhjjdo jp joi jreio j", "gezoeteroiyerphehkzb,fgbd bcmsherkgheiusbcjkdvberb ", i, new String[0]); - s.write(record.toString() + '\n'); - s.flush(); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - for (i = 4 * MAX_0; i < 5 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " trace", "ffgkdhvlsdknjk eriopgejo ipjiropj i io poi opijgr pe jupoieruj ga geigerihpi oeop erp ", "griofeioteogbbekjbnrjemk prejrlmekhgrehivbn rekhgrhi ", i, new String[0]); - s.write(record.toString() + '\n'); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - for (i = 5 * MAX_0; i < 6 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " user", "grekgrhze t e re klgre ge rgre gre gfer g rjyukj yujty reez ze fz", "gekfhezh zhrze hgerhglkrej ljbvkxdfn df,ekgrrnvkmn", i, new String[0]); - s.write(record.toString() + '\n'); - s.flush(); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - } catch (OutOfMemoryError e) { - t1 = System.currentTimeMillis(); - log.info("failed after | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - e.printStackTrace(); - } finally { - if (s != null) { - s.flush(); - s.close(); - } - } - } - - /** - * create a mock of logEvents - * - * @throws java.io.IOException todo - * @throws InterruptedException todo - */ - public static void mockLogFile2() throws IOException, InterruptedException { - File f = new File(filename); - if (f.exists()) { - f.delete(); - } - BufferedWriter s = new BufferedWriter(new FileWriter(f)); - int MAX_0 = (int) (MEGA_STREAM_SIZE / 6); - int i = 0; - long t0, t00; - long t1; - totalPause = 0; - t00 = System.currentTimeMillis(); - t0 = System.currentTimeMillis(); - try { - - for (i = 0; i < MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.FATAL, 0, i + "debug ", "ioreiovrio veuio vreupo xz xe opiu tep uxr u ", "xeoiujoiz xpo puoi rui hp", i, new String[0]); - s.write(record.toString() + '\n'); - s.flush(); - } - - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - - for (i = MAX_0; i < 2 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.WARN, 0, i + " warn", "jkljfdjkl fdkjlkj lkjdlkfjl dfkljl dflkfdj lfdjlk fjdlkj fdl", "vmfof o rieipk?prj,ùnklvndfkljn gmlrtsoîjrmoig", i, new String[0]); - s.write(record.toString() + '\n'); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - for (i = 2 * MAX_0; i < 3 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.INFO, 0, i + " info", "grlgjlrmgr jglerj mgrjm gre pjkogremoiqp jgpo rejopigjrej,m", "grkgherjfezoprjgbpdofùjhlbnb;k nfkfjgmjmsg", i, new String[0]); - s.write(record.toString() + '\n'); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - for (i = 3 * MAX_0; i < 4 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.DEBUG, 0, i + " debug", "grmgjueroijiorehjnjodj j gn mbr,nhltrhjjdo jp joi jreio j", "gezoeteroiyerphehkzb,fgbd bcmsherkgheiusbcjkdvberb ", i, new String[0]); - s.write(record.toString() + '\n'); - s.flush(); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - for (i = 4 * MAX_0; i < 5 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " trace", "ffgkdhvlsdknjk eriopgejo ipjiropj i io poi opijgr pe jupoieruj g'^ geigerihpi oeop erp ", "griofeioteogbbekjbnrjemk çprejrlmekhgrehivbn rekhgrhi ", i, new String[0]); - s.write(record.toString() + '\n'); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - //pause(500); - t0 = System.currentTimeMillis(); - for (i = 5 * MAX_0; i < 6 * MAX_0; i++) { - LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " user", "grekgrhze t e re klgre ge rgre gre gfer g rjyukj yujty reez ze fz", "gekfhezh zhrze hgerhglkrej ljbvkxdfn df,ekgrrnvkmn", i, new String[0]); - s.write(record.toString() + '\n'); - s.flush(); - } - t1 = System.currentTimeMillis(); - log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - } catch (OutOfMemoryError e) { - t1 = System.currentTimeMillis(); - log.info("failed after | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00)); - e.printStackTrace(); - } finally { - if (s != null) { - s.flush(); - s.close(); - } - } - } - - public static void IsisStart() { - System.setProperty("org.apache.commons.logging.LogFactory", - LutinLogFactory.class.getName()); - try { - TestUtils.init(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * This is a log record (says an entry of a log file). This is abstracted from any - * logging implementation. - * <p/> - * To deal with log, we don't use string version stored in original log file, - * prefer use serialized form of a LogRecord : we keep a lot of time when using - * them to display them in ui, and for filtering process too. - * <p/> - * The LogRecord unicity is base on two properties : - * <ul> - * <li>timestamp</li> - * <li>message</li> - * </ul> - * <p/> - * We can not use only timestamp, more than one event could appear in a same - * timestamp. - * <p/> - * TODO Put this code in lutinLog ? - * - * @author chemit - */ - public static class LogRecord implements java.io.Serializable { - - /** the time of the event */ - protected long timeStamp; - - /** the msg for the event */ - protected String message; - - /** the severity of the event */ - protected int level; - - /** the throwable details the event */ - protected String[] throwableStrRep; - - /** origin filename of the event */ - //protected transient String filename; - - /** origin method name of the event */ - //protected transient String methodName; - - /** origin line number of the event */ - //protected transient int lineNumber; - - /** - * the string represention of logEvent, transient since we use a lazy getter - * we don't need to store it. - * <p/> - * <b>(if not transient : double the size of serialized form...)</b> - */ - protected transient String text; - - /** - * the offset of logRecord in stream. - * <p/> - * This is a transient property, since we compute this value when getting - * the LogRecord from stream - */ - protected transient long offset; - - private static final long serialVersionUID = 1335077740059488080L; - - public static LogRecord newInstance(LogLevel level, - long timestamp, - String message, - String fileName, - String methodName, - int lineNumber, - String[] errors) throws UnsupportedEncodingException { - return new LogRecord( - level == null ? LogLevel.DEBUG.ordinal() : level.ordinal(), - timestamp, - message, - fileName, - methodName, - lineNumber, - errors - ); - } - - protected LogRecord(int level, - long timestamp, - String message, - String filename, - String methodName, - int lineNumber, - String[] throwableStrRep) throws UnsupportedEncodingException { - this.level = level; - this.timeStamp = timestamp; - //this.message = message; - this.message = new String((filename + ":" + lineNumber + " - " + methodName + " - " + message).getBytes("utf-8")); - //this.filename = filename; - //this.methodName = methodName; - //this.lineNumber = lineNumber; - this.throwableStrRep = throwableStrRep; - } - - public String getMessage() { - return message; - } - - public int getLevel() { - return level; - } - - public String[] getThrowableStrRep() { - return throwableStrRep; - } - - public long getTimeStamp() { - return timeStamp; - } - - public int getLineNumber() { - return 0; - //return lineNumber; - } - - public String getMethodName() { - return ""; - //return methodName; - } - - public long getOffset() { - return offset; - } - - public void setOffset(long offset) { - this.offset = offset; - } - - /** - * We use a cache for the representation since we will use a lots of time. - * - * @return the String representation used to display logEvent in ui. - */ - @Override - public String toString() { - if (text == null) { - text = new StringBuilder(LogLevel.getLogLevel(level).toString()). - append(' ').append(message).toString(); - } - /*if (text == null) { - text = new StringBuilder().append(LogLevel.getSimulLogLevel(level)). - append(' ').append(filename).append(':'). - append(lineNumber).append(" - "). - append(methodName).append(" - ").append(message).toString(); - }*/ - return text; - } - - /** - * We base the identiy of a LogEvent on the message, level and timestamp - * - * @param o object to compare - * @return <code>true</code> if same object - */ - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - LogRecord event = (LogRecord) o; - return timeStamp == event.timeStamp && - !(message != null ? !message.equals(event.message) : - event.message != null); - } - - @Override - public int hashCode() { - int result; - result = (int) (timeStamp ^ (timeStamp >>> 32)); - result = 31 * result + (message != null ? message.hashCode() : 0); - return result; - } - - } -} Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -1,15 +1,36 @@ +/* *##% + * Copyright (C) 2009 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.logging.io; -import fr.ifremer.TestUtils; -import fr.ifremer.isisfish.logging.TestUtil; -import junit.framework.TestCase; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.util.StringUtil; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; +import fr.ifremer.isisfish.AbstractIsisFishTest; +import fr.ifremer.isisfish.logging.LoggerHelper; /** * User: tony @@ -17,11 +38,11 @@ * Time: 21:41:53 */ -public class LineReaderTest extends TestCase { +public class LineReaderTest extends AbstractIsisFishTest { protected static final Log log = LogFactory.getLog(LineReaderTest.class); - File testDir; + protected File testDir; final static int[] sizes = new int[]{ 10, @@ -39,51 +60,49 @@ //2000000 }; - protected void setUp() throws Exception { - super.setUp(); - - testDir = new File(TestUtils.getTargetdir(), "bench_" + System.nanoTime()); + @Before + public void setUp() throws Exception { + testDir = new File(getTargetdir(), "bench_" + System.nanoTime()); testDir.mkdirs(); System.out.println("benchdir " + testDir); } protected static void createMock(File testDir, int i) throws IOException, InterruptedException { - TestUtil.MEGA_STREAM_SIZE = 6 * i; - TestUtil.filename = new File(testDir, LineReaderTest.class.getSimpleName() + "_" + 6 * i + ".log").getAbsolutePath(); - File file = new File(testDir, TestUtil.filename); + LoggerHelper.MEGA_STREAM_SIZE = 6 * i; + LoggerHelper.filename = new File(testDir, LineReaderTest.class.getSimpleName() + "_" + 6 * i + ".log").getAbsolutePath(); + File file = new File(testDir, LoggerHelper.filename); long t0 = System.nanoTime(); - TestUtil.mockLogFile(); + LoggerHelper.mockLogFile(); long t1; t1 = System.nanoTime(); - log.info("create [" + TestUtil.MEGA_STREAM_SIZE + "] in " + StringUtil.convertTime(t1 - t0) + " [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "]"); + log.info("create [" + LoggerHelper.MEGA_STREAM_SIZE + "] in " + StringUtil.convertTime(t1 - t0) + " [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "]"); System.gc(); } + public void testMakeMock() throws Exception { - public void estMakeMock() throws Exception { - for (int size : sizes) { createMock(testDir, size); } } - public void estCreateOffsets() throws Exception { + public void testCreateOffsets() throws Exception { for (int size : sizes) { createOffset(size); } } - public void estGetNbLines() throws Exception { + public void testGetNbLines() throws Exception { for (int size : sizes) { getNbLines(size); } } - public void estScanAllLines() throws Exception { + public void testScanAllLines() throws Exception { for (int size : sizes) { scanAllLines(size * 6); @@ -94,7 +113,7 @@ } - public void estScanReverseAllLines() throws Exception { + public void testScanReverseAllLines() throws Exception { for (int size : sizes) { scanReverseAllLines(size * 6); @@ -104,7 +123,7 @@ } } - public void estScanThenReverseAllLines() throws Exception { + public void testScanThenReverseAllLines() throws Exception { for (int size : sizes) { scanThenReverseAllLines(size * 6); @@ -121,13 +140,13 @@ } protected void scanAllLines(int size) throws IOException { - TestUtil.MEGA_STREAM_SIZE = size; - TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + TestUtil.MEGA_STREAM_SIZE + ".log"; - File file = new File(TestUtil.filename); + LoggerHelper.MEGA_STREAM_SIZE = size; + LoggerHelper.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + LoggerHelper.MEGA_STREAM_SIZE + ".log"; + File file = new File(LoggerHelper.filename); long t0 = System.currentTimeMillis(); LineReader t = createReader(file, "offsets"); t.open(); - assertEquals(TestUtil.MEGA_STREAM_SIZE, t.getNbLines()); + Assert.assertEquals(LoggerHelper.MEGA_STREAM_SIZE, t.getNbLines()); for (int i = 0; i < t.getNbLines(); i++) { long offset = t.getOffsetReader().getOffset(i); //assertEquals(i,offset); @@ -148,13 +167,13 @@ } protected void scanAllLines(int size, int length) throws IOException { - TestUtil.MEGA_STREAM_SIZE = size; - TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + TestUtil.MEGA_STREAM_SIZE + ".log"; - File file = new File(TestUtil.filename); + LoggerHelper.MEGA_STREAM_SIZE = size; + LoggerHelper.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + LoggerHelper.MEGA_STREAM_SIZE + ".log"; + File file = new File(LoggerHelper.filename); long t0 = System.currentTimeMillis(); LineReader t = createReader(file, "offsets"); t.open(); - assertEquals(TestUtil.MEGA_STREAM_SIZE, t.getNbLines()); + Assert.assertEquals(LoggerHelper.MEGA_STREAM_SIZE, t.getNbLines()); for (int i = 0; i < t.getNbLines(); i += length) { long offset = t.getOffsetReader().getOffset(i); //assertEquals(i,offset); @@ -175,13 +194,13 @@ } protected void scanReverseAllLines(int size) throws IOException { - TestUtil.MEGA_STREAM_SIZE = size; - TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + TestUtil.MEGA_STREAM_SIZE + ".log"; - File file = new File(TestUtil.filename); + LoggerHelper.MEGA_STREAM_SIZE = size; + LoggerHelper.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + LoggerHelper.MEGA_STREAM_SIZE + ".log"; + File file = new File(LoggerHelper.filename); long t0 = System.currentTimeMillis(); LineReader t = createReader(file, "offsets"); t.open(); - assertEquals(TestUtil.MEGA_STREAM_SIZE, t.getNbLines()); + Assert.assertEquals(LoggerHelper.MEGA_STREAM_SIZE, t.getNbLines()); for (int i = 0; i < t.getNbLines(); i += 10) { long offset = t.getOffsetReader().getOffset(i); //assertEquals(i,offset); @@ -202,13 +221,13 @@ } protected void scanReverseAllLines(int size, int length) throws IOException { - TestUtil.MEGA_STREAM_SIZE = size; - TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + TestUtil.MEGA_STREAM_SIZE + ".log"; - File file = new File(TestUtil.filename); + LoggerHelper.MEGA_STREAM_SIZE = size; + LoggerHelper.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + LoggerHelper.MEGA_STREAM_SIZE + ".log"; + File file = new File(LoggerHelper.filename); long t0 = System.currentTimeMillis(); LineReader t = createReader(file, "offsets"); t.open(); - assertEquals(TestUtil.MEGA_STREAM_SIZE, t.getNbLines()); + Assert.assertEquals(LoggerHelper.MEGA_STREAM_SIZE, t.getNbLines()); for (int i = 0; i < t.getNbLines(); i += length) { long offset = t.getOffsetReader().getOffset(i); //assertEquals(i,offset); @@ -229,13 +248,13 @@ } protected void scanThenReverseAllLines(int size) throws IOException { - TestUtil.MEGA_STREAM_SIZE = size; - TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + TestUtil.MEGA_STREAM_SIZE + ".log"; - File file = new File(TestUtil.filename); + LoggerHelper.MEGA_STREAM_SIZE = size; + LoggerHelper.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + LoggerHelper.MEGA_STREAM_SIZE + ".log"; + File file = new File(LoggerHelper.filename); long t0 = System.currentTimeMillis(); LineReader t = createReader(file, "offsets"); t.open(); - assertEquals(TestUtil.MEGA_STREAM_SIZE, t.getNbLines()); + Assert.assertEquals(LoggerHelper.MEGA_STREAM_SIZE, t.getNbLines()); for (int i = 0; i < t.getNbLines(); i += 10) { long offset = t.getOffsetReader().getOffset(i); //assertEquals(i,offset); @@ -254,13 +273,13 @@ } protected void scanThenReverseAllLines(int size, int length) throws IOException { - TestUtil.MEGA_STREAM_SIZE = size; - TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + TestUtil.MEGA_STREAM_SIZE + ".log"; - File file = new File(TestUtil.filename); + LoggerHelper.MEGA_STREAM_SIZE = size; + LoggerHelper.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + LoggerHelper.MEGA_STREAM_SIZE + ".log"; + File file = new File(LoggerHelper.filename); long t0 = System.currentTimeMillis(); LineReader t = createReader(file, "offsets"); t.open(); - assertEquals(TestUtil.MEGA_STREAM_SIZE, t.getNbLines()); + Assert.assertEquals(LoggerHelper.MEGA_STREAM_SIZE, t.getNbLines()); for (int i = 0; i < t.getNbLines(); i += length) { long offset = t.getOffsetReader().getOffset(i); //assertEquals(i,offset); @@ -279,35 +298,35 @@ } protected void getNbLines(int size) throws IOException, InterruptedException { - TestUtil.MEGA_STREAM_SIZE = 6 * size; - TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + 6 * size + ".log"; - File file = new File(TestUtil.filename); + LoggerHelper.MEGA_STREAM_SIZE = 6 * size; + LoggerHelper.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + 6 * size + ".log"; + File file = new File(LoggerHelper.filename); long t0 = System.currentTimeMillis(); LineReader t = createReader(file, "offsets"); t.open(); long nbLines = t.getNbLines(); - assertEquals(TestUtil.MEGA_STREAM_SIZE, nbLines); + Assert.assertEquals(LoggerHelper.MEGA_STREAM_SIZE, nbLines); t.close(); long t1 = System.currentTimeMillis(); - log.info("(" + nbLines + ") [" + TestUtil.MEGA_STREAM_SIZE + "] in " + time(t0, t1) + " [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "]"); + log.info("(" + nbLines + ") [" + LoggerHelper.MEGA_STREAM_SIZE + "] in " + time(t0, t1) + " [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "]"); } protected void createOffset(int size) throws IOException, InterruptedException { - TestUtil.MEGA_STREAM_SIZE = 6 * size; - TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + 6 * size + ".log"; - File file = new File(TestUtil.filename); - File offsetfile = new File(TestUtil.filename + ".offsets"); + LoggerHelper.MEGA_STREAM_SIZE = 6 * size; + LoggerHelper.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + 6 * size + ".log"; + File file = new File(LoggerHelper.filename); + File offsetfile = new File(LoggerHelper.filename + ".offsets"); if (offsetfile.exists()) { if (!offsetfile.delete()) { - fail("could not delete file " + offsetfile); + Assert.fail("could not delete file " + offsetfile); } } long t0 = System.currentTimeMillis(); LineReader t = createReader(file, "offsets"); - assertEquals(TestUtil.MEGA_STREAM_SIZE, t.getNbLines()); + Assert.assertEquals(LoggerHelper.MEGA_STREAM_SIZE, t.getNbLines()); t.close(); long t1 = System.currentTimeMillis(); - log.info("time (" + time(t0, t1) + ") [" + TestUtil.MEGA_STREAM_SIZE + "] [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "] [offsetfile: " + offsetfile + ", length: " + StringUtil.convertMemory(offsetfile.length()) + "]"); + log.info("time (" + time(t0, t1) + ") [" + LoggerHelper.MEGA_STREAM_SIZE + "] [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "] [offsetfile: " + offsetfile + ", length: " + StringUtil.convertMemory(offsetfile.length()) + "]"); } public static String time(long t0, long t1) { @@ -328,10 +347,11 @@ sb.append(secondes).append("s "); } sb.append(total).append("ms "); - sb.append(" ~ ").append((float) (t1 - t0) / TestUtil.MEGA_STREAM_SIZE); + sb.append(" ~ ").append((float) (t1 - t0) / LoggerHelper.MEGA_STREAM_SIZE); return sb.toString(); } + @Test public void testSimple() throws Exception { String filename = "bench/LineReaderTest_30.log"; Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderUtilTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderUtilTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderUtilTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -1,14 +1,35 @@ +/* *##% + * Copyright (C) 2009 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.logging.io; -import fr.ifremer.TestUtils; -import fr.ifremer.isisfish.logging.LogLevel; -import fr.ifremer.isisfish.logging.LogLevelUtil; -import fr.ifremer.isisfish.logging.TestUtil; -import junit.framework.TestCase; +import java.io.File; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; -import java.io.File; +import fr.ifremer.isisfish.AbstractIsisFishTest; +import fr.ifremer.isisfish.logging.LogLevel; +import fr.ifremer.isisfish.logging.LogLevelUtil; +import fr.ifremer.isisfish.logging.LoggerHelper; /** * Tests unitaires sur les implantations de LineReader @@ -16,15 +37,15 @@ * @author chemit */ -public class LineReaderUtilTest extends TestCase { +public class LineReaderUtilTest extends AbstractIsisFishTest { protected static final Log log = LogFactory.getLog(LineReaderUtilTest.class); - static File testDir; + protected static File testDir; public static File getTestDir() { if (testDir == null) { - testDir = new File(TestUtils.getTargetdir(), "bench_" + System.nanoTime()); + testDir = new File(getTargetdir(), "bench_" + System.nanoTime()); if (!testDir.mkdirs()) { throw new IllegalStateException("could not create directory " + testDir); } @@ -49,19 +70,18 @@ }; File f; - protected void setUp() throws Exception { - super.setUp(); - + @Before + public void setUp() throws Exception { System.out.println("benchdir " + getTestDir()); String filename = "LineReaderTest_30.log"; f = new File(testDir, filename); if (!f.exists()) { - TestUtil.createMock(testDir, filename, 5); + LoggerHelper.createMock(testDir, filename, 5); } } - + @Test public void testLevelReader() throws Exception { long nbLines; @@ -71,7 +91,7 @@ reader.getOffsetReader().deleteOffsetFile(); reader.open(); nbLines = reader.getNbLines(); - assertEquals(30, nbLines); + Assert.assertEquals(30, nbLines); log.info("found " + nbLines + " in reader " + reader); reader2 = new LineReaderUtil.LevelLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + LogLevel.DEBUG.mask())), LogLevel.FATAL); @@ -79,7 +99,7 @@ reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(5, nbLines); + Assert.assertEquals(5, nbLines); reader2.close(); reader2 = new LineReaderUtil.LevelLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + LogLevel.DEBUG.mask())), LogLevel.DEBUG); @@ -87,7 +107,7 @@ reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(5, nbLines); + Assert.assertEquals(5, nbLines); reader2.close(); reader2 = new LineReaderUtil.LevelLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + LogLevel.INFO.mask())), LogLevel.INFO); @@ -95,7 +115,7 @@ reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(5, nbLines); + Assert.assertEquals(5, nbLines); reader2.getOffsetReader().deleteOffsetFile(); reader2.close(); @@ -103,6 +123,7 @@ reader.close(); } + @Test public void testLevelsReader() throws Exception { LineReader reader, reader2, reader3; @@ -113,7 +134,7 @@ reader.getOffsetReader().deleteOffsetFile(); reader.open(); nbLines = reader.getNbLines(); - assertEquals(30, nbLines); + Assert.assertEquals(30, nbLines); log.info("found " + nbLines + " in reader " + reader); levels = LogLevelUtil.createSet(LogLevel.DEBUG, LogLevel.INFO); @@ -122,57 +143,57 @@ reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(10, nbLines); + Assert.assertEquals(10, nbLines); reader2.getOffsetReader().deleteOffsetFile(); reader2.close(); levels = LogLevelUtil.createSet(LogLevel.WARN, LogLevel.INFO); reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.INFO, LogLevel.WARN); reader2.getOffsetReader().deleteOffsetFile(); - assertTrue(reader2.getOffsetReader().needCreate()); + Assert.assertTrue(reader2.getOffsetReader().needCreate()); reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(10, nbLines); + Assert.assertEquals(10, nbLines); levels = LogLevelUtil.createSet(LogLevel.INFO); reader3 = new LineReaderUtil.LevelsLineReader(reader2, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.INFO); reader3.getOffsetReader().deleteOffsetFile(); - assertTrue(reader3.getOffsetReader().needCreate()); + Assert.assertTrue(reader3.getOffsetReader().needCreate()); reader3.open(); nbLines = reader3.getNbLines(); log.info("found " + nbLines + " in reader " + reader3); - assertEquals(5, nbLines); + Assert.assertEquals(5, nbLines); reader2.close(); reader3.close(); levels = LogLevelUtil.createSet(LogLevel.INFO, LogLevel.WARN); reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.WARN, LogLevel.INFO); - assertFalse(reader2.getOffsetReader().needCreate()); + Assert.assertFalse(reader2.getOffsetReader().needCreate()); reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(10, nbLines); + Assert.assertEquals(10, nbLines); reader2.getOffsetReader().deleteOffsetFile(); reader2.close(); levels = LogLevelUtil.createSet(LogLevel.DEBUG); reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.DEBUG); - assertFalse(reader2.getOffsetReader().needCreate()); + Assert.assertFalse(reader2.getOffsetReader().needCreate()); reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(5, nbLines); + Assert.assertEquals(5, nbLines); reader2.close(); levels = LogLevelUtil.createSet(LogLevel.DEBUG, LogLevel.DEBUG); reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.DEBUG, LogLevel.DEBUG); - assertFalse(reader2.getOffsetReader().needCreate()); + Assert.assertFalse(reader2.getOffsetReader().needCreate()); reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(5, nbLines); + Assert.assertEquals(5, nbLines); reader2.getOffsetReader().deleteOffsetFile(); reader2.close(); @@ -181,6 +202,7 @@ reader.close(); } + @Test public void testPatternReader() throws Exception { LineReader reader, reader2; @@ -190,7 +212,7 @@ reader.getOffsetReader().deleteOffsetFile(); reader.open(); nbLines = reader.getNbLines(); - assertEquals(30, nbLines); + Assert.assertEquals(30, nbLines); log.info("found " + nbLines + " in reader " + reader); reader2 = new LineReaderUtil.PatternLineReader(reader, new MemoryOffsetReader(100), "DEBUG.*", 0); @@ -198,7 +220,7 @@ reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(5, nbLines); + Assert.assertEquals(5, nbLines); reader2.close(); reader2 = new LineReaderUtil.PatternLineReader(reader, new MemoryOffsetReader(100), "ADEBUG.*", 0); @@ -206,7 +228,7 @@ reader2.open(); nbLines = reader2.getNbLines(); log.info("found " + nbLines + " in reader " + reader2); - assertEquals(0, nbLines); + Assert.assertEquals(0, nbLines); reader2.close(); reader.getOffsetReader().deleteOffsetFile(); Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/MexicoHelperTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/MexicoHelperTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/MexicoHelperTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -31,7 +31,7 @@ import org.codelutin.util.FileUtil; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan; import fr.ifremer.isisfish.simulator.sensitivity.Factor; import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; @@ -48,7 +48,7 @@ * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ by : * $Author: tchemit $ */ -public class MexicoHelperTest { +public class MexicoHelperTest extends AbstractIsisFishTest { /** Commons logging log. */ private static Log log = LogFactory.getLog(MexicoHelperTest.class); @@ -67,9 +67,9 @@ matrix1.setValue(new int[] { 2, 1 }, -1); // factor 1 - Factor<Double,Double> factorContinuous = new Factor<Double,Double>( + Factor<Double, Double> factorContinuous = new Factor<Double, Double>( "factor 1 (double continuous)"); - ContinuousDomain<Double,Double> domain1 = new ContinuousDomain<Double,Double>(); + ContinuousDomain<Double, Double> domain1 = new ContinuousDomain<Double, Double>(); domain1.setMinBound(0.0); domain1.setMaxBound(50.0); factorContinuous.setDomain(domain1); @@ -77,8 +77,9 @@ .setPath("fr.ifremer.isisfish.entities.PopulationGroup#1156461521013#0.1715620681984218#maxLength"); // factor 2 - Factor<Double,Double> factorDiscrete = new Factor<Double,Double>("factor 2 (double discrete)"); - DiscreteDomain<Double,Double> domain2 = new DiscreteDomain<Double,Double>(); + Factor<Double, Double> factorDiscrete = new Factor<Double, Double>( + "factor 2 (double discrete)"); + DiscreteDomain<Double, Double> domain2 = new DiscreteDomain<Double, Double>(); domain2.getValues().put(0.0, 12.3); domain2.getValues().put(1.0, 70.9); domain2.getValues().put(2.0, 21.0); @@ -90,8 +91,9 @@ factorDiscrete.setValue(3.0); // factor 3 - Factor<Integer,Double> factorContinuous2 = new Factor<Integer,Double>("factor 3 (integer discrete)"); - DiscreteDomain<Integer,Double> domain3 = new DiscreteDomain<Integer,Double>(); + Factor<Integer, Double> factorContinuous2 = new Factor<Integer, Double>( + "factor 3 (integer discrete)"); + DiscreteDomain<Integer, Double> domain3 = new DiscreteDomain<Integer, Double>(); domain3.getValues().put(0.0, 13); domain3.getValues().put(0.0, 14); domain3.getValues().put(0.0, 15); @@ -100,7 +102,7 @@ .setPath("fr.ifremer.isisfish.entities.PopulationGroup#1156461521076#0.6526656643346673#minLength"); // factor 4 - Factor<MatrixND,Double> factorMatrixContinuous = new Factor<MatrixND,Double>( + Factor<MatrixND, Double> factorMatrixContinuous = new Factor<MatrixND, Double>( "factor 4 (MatrixContinuous)"); MatrixContinuousDomain domain4 = new MatrixContinuousDomain(); domain4.setCoefficient(0.1); @@ -111,7 +113,7 @@ .setPath("fr.ifremer.isisfish.entities.PopulationGroup#1156461521076#0.6526656643346673#minLength"); // factor 5 - Factor<Double,Double> factorEquationContinuous = new Factor<Double,Double>( + Factor<Double, Double> factorEquationContinuous = new Factor<Double, Double>( "factor 5 (EquationContinuous)"); EquationContinuousDomain domain5 = new EquationContinuousDomain(); domain5.setCoefficient(0.1); @@ -144,13 +146,14 @@ // test xml export String xml = MexicoHelper.getDesignPlanAsXML(testDesignPlan); - Assert.assertTrue(xml.indexOf("<factor name=\"factor 2 (double discrete)\"") != -1); + Assert.assertTrue(xml + .indexOf("<factor name=\"factor 2 (double discrete)\"") != -1); //Assert.assertTrue(xml.indexOf("<range min=\"12.0\" max=\"99.0\" />") != -1); Assert.assertTrue(xml.indexOf("<value>70.9</value>") != -1); if (log.isDebugEnabled()) { xml = xml.replaceAll(">", ">\n"); - FileUtil.writeString(new File(TestUtils.getTargetdir(), + FileUtil.writeString(new File(getTargetdir(), "mexicohelper_designplan.xml"), xml); log.info("testGetDesignPlanAsXML xml = " + xml); } @@ -163,8 +166,9 @@ */ @Test public void testGetDesignPlanFromXML() throws IOException { - - File testFile = new File("src/test/resources/mexico/mexicohelper_designplan.xml"); + + File testFile = new File( + "src/test/resources/mexico/mexicohelper_designplan.xml"); // topia context can be null in tests DesignPlan plan = MexicoHelper.getDesignPlanFromXML(testFile, null); @@ -174,7 +178,7 @@ xml = xml.replaceAll(">", ">\n"); log.info("testGetDesignPlanFromXML xml = " + xml); } - + /** * Test que l'export XML de l'import XML produise le meme xml. * @@ -187,14 +191,15 @@ DesignPlan testDesignPlan = getTestDesignPlan(); String xml1 = MexicoHelper.getDesignPlanAsXML(testDesignPlan); log.debug("xml 1 = " + xml1); - + // export - File testFile = new File("src/test/resources/mexico/mexicohelper_designplan.xml"); + File testFile = new File( + "src/test/resources/mexico/mexicohelper_designplan.xml"); // topia context can be null in tests DesignPlan plan = MexicoHelper.getDesignPlanFromXML(testFile, null); String xml2 = MexicoHelper.getDesignPlanAsXML(plan); log.debug("xml 2 = " + xml2); - + Assert.assertEquals(xml1, xml2); } } Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationHelperTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationHelperTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationHelperTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -27,12 +27,10 @@ import org.codelutin.math.matrix.DoubleBigVector; import org.codelutin.math.matrix.MatrixFactory; import org.codelutin.topia.TopiaContext; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.datastore.ResultStorage; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.entities.Result; @@ -50,7 +48,7 @@ * Last update: $Date$ * by : $Author$ */ -public class SimulationHelperTest { +public class SimulationHelperTest extends AbstractIsisFishTest { /** Commons logging log. */ private static Log log = LogFactory.getLog(SimulationHelperTest.class); @@ -59,16 +57,6 @@ "src" + File.separator + "test" + File.separator + "resources" + File.separator + "simulations" + File.separator + "test-nonregression-20090203.zip", // put here other zip simulation test }; - - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - } - - @AfterClass - public static void clean() { - TestUtils.clean(); - } // public void testVerifResult() throws Exception { // try { @@ -140,7 +128,7 @@ for (String zipName : SIMULATION_ZIP_FILE) { // recuperation du fichier zip de la simulation de test - File zip = new File(TestUtils.getBasedir(), zipName); + File zip = new File(getBasedir(), zipName); // import de cette simulation String name = "simulation-test-" + System.currentTimeMillis(); Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationParameterTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationParameterTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationParameterTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -22,14 +22,12 @@ import junit.framework.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; /** - * TODO COMMENT ME. + * Simulation parameter test class. * * @author chatellier * @version $Revision: 1.0 $ @@ -37,14 +35,8 @@ * Last update : $Date: 19 mars 2009 $ * By : $Author: chatellier $ */ - at Ignore -public class SimulationParameterTest { +public class SimulationParameterTest extends AbstractIsisFishTest { - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - } - /** * Test to build one simulation parameters. * @@ -53,19 +45,18 @@ */ @Test public void testToPropertiesFromPropertties() { - + SimulationParameter params = new SimulationParameter(); params.setIsisFishVersion("3.2.0.4"); params.setDescription("desc"); - + // make transform Properties props = params.toProperties(); SimulationParameter params2 = new SimulationParameter(); params2.fromProperties(null, props); - + Assert.assertEquals("3.2.0.4", params2.getIsisFishVersion()); Assert.assertEquals("desc", params2.getDescription()); } - - + } Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -36,10 +36,9 @@ import org.codelutin.topia.TopiaException; import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFishDAOHelper; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.datastore.StorageException; @@ -70,31 +69,27 @@ * Last update : $Date: 24 févr. 2009 $ * By : $Author: chatellier $ */ -public class SimulationPreScriptTest { +public class SimulationPreScriptTest extends AbstractIsisFishTest { - /** Commons logging log. */ + /** log. */ private static Log log = LogFactory.getLog(SimulationPreScriptTest.class); - //protected TopiaContext rootContext; - protected static Configuration freemarkerConfiguration; - - @BeforeClass - public static void init() throws Exception { - freemarkerConfiguration = TestUtils.getFreemarkerConfiguration(); - } - + @Before public void setUp() throws Exception { // not do it in @BeforeClass // test will fail ! - TestUtils.init(); - System.setProperty("hibernate.hbm2ddl.auto", "create"); + init(); + freemarkerConfiguration = getFreemarkerConfiguration(); + // very important , other test wil fail with that + //System.setProperty("hibernate.hbm2ddl.auto", "create"); } @After public void tearDown() { - System.setProperty("hibernate.hbm2ddl.auto", ""); + // very important , other test wil fail with that + //System.clearProperty("hibernate.hbm2ddl.auto"); } /** @@ -165,6 +160,7 @@ context.setSimulationStorage(simulation); // FIXME here is the error, getDb throw exception //simulationPreScript.beforeSimulation(context); + SimulationContext.remove(); // try to find previous entity vesselType = vesselTypeDAO.findByTopiaId(topiaId); @@ -270,6 +266,7 @@ context.setSimulationStorage(simulation); // FIXME here is the error, getDb throw exception //simulationPreScript.beforeSimulation(context); + SimulationContext.remove(); // try to find previous entity populationSeasonInfo = populationSeasonInfoDAO.findByTopiaId(topiaId); Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -28,7 +28,7 @@ import org.junit.Before; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.entities.Population; import fr.ifremer.isisfish.entities.PopulationGroup; import fr.ifremer.isisfish.entities.PopulationImpl; @@ -51,7 +51,7 @@ * * Last update : $Date: 24 févr. 2009 $ By : $Author: chatellier $ */ -public class SimulationServiceTest { +public class SimulationServiceTest extends AbstractIsisFishTest { /** Commons logging log. */ private static Log log = LogFactory.getLog(SimulationServiceTest.class); @@ -60,7 +60,7 @@ public void setUp() throws Exception { // not do it in @BeforeClass // test will fail ! - TestUtils.init(); + AbstractIsisFishTest.init(); } /** Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -22,10 +22,9 @@ import junit.framework.Assert; -import org.junit.BeforeClass; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.IsisFish; import freemarker.template.TemplateException; @@ -39,13 +38,8 @@ * Last update : $Date: 22 janv. 2009 $ * By : $Author: chatellier $ */ -public class SshSimulatorLauncherTest { +public class SshSimulatorLauncherTest extends AbstractIsisFishTest { - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - } - /** * Test l'instantiation du script qsub (caparmor). * Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/sensitivity/FactorTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/sensitivity/FactorTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/sensitivity/FactorTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -25,7 +25,6 @@ import org.junit.Assert; import org.junit.Test; -import fr.ifremer.isisfish.entities.Equation; import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain; import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain; Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/sensitivity/SensitivityCalculatorRandomMock.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/sensitivity/SensitivityCalculatorRandomMock.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/sensitivity/SensitivityCalculatorRandomMock.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.codelutin.math.matrix.MatrixND; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.simulator.launcher.SimulationServiceTest; Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModelTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModelTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/sensitivity/FactorTreeModelTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -21,7 +21,6 @@ import static org.codelutin.i18n.I18n._; import java.awt.HeadlessException; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -38,6 +37,7 @@ import org.codelutin.math.matrix.MatrixND; import org.junit.Test; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.simulator.sensitivity.Factor; import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain; @@ -53,8 +53,8 @@ * Last update: $Date: 2009-02-03 17:44:23 +0100 (mar 03 fév 2009) $ * by : $Author: chatellier $ */ -public class FactorTreeModelTest{ - +public class FactorTreeModelTest extends AbstractIsisFishTest { + /** Logger for this class */ private static final Log log = LogFactory.getLog(FactorTreeModelTest.class); @@ -65,8 +65,9 @@ */ protected List<Factor> getFactors() { - Factor<Integer,Integer> factor1 = new Factor<Integer,Integer>("testint"); - ContinuousDomain<Integer,Integer> domain1 = new ContinuousDomain<Integer,Integer>(); + Factor<Integer, Integer> factor1 = new Factor<Integer, Integer>( + "testint"); + ContinuousDomain<Integer, Integer> domain1 = new ContinuousDomain<Integer, Integer>(); domain1.setMinBound(0); domain1.setMaxBound(50); factor1.setDomain(domain1); @@ -94,14 +95,16 @@ matrix2.setValue(new int[] { 1, 2 }, -13000); // factor - Factor<MatrixND,String> factor2 = new Factor<MatrixND,String>("testmatrix"); - DiscreteDomain<MatrixND,String> domain2 = new DiscreteDomain<MatrixND,String>(); + Factor<MatrixND, String> factor2 = new Factor<MatrixND, String>( + "testmatrix"); + DiscreteDomain<MatrixND, String> domain2 = new DiscreteDomain<MatrixND, String>(); domain2.getValues().put("m1", matrix1); domain2.getValues().put("m2", matrix2); factor2.setDomain(domain2); - factor2.setPath("org.codelutin.math.matrix.MatrixND#563456293453#2.456347646#dim"); + factor2 + .setPath("org.codelutin.math.matrix.MatrixND#563456293453#2.456347646#dim"); factor2.setValueForIdentifier("m2"); - + List<Factor> factors1 = new ArrayList<Factor>(); factors1.add(factor1); factors1.add(factor2); @@ -114,7 +117,7 @@ */ @Test public void testJTreeModel() throws InterruptedException { - + TreeNode root = new DefaultMutableTreeNode(getFactors()); final JTree tree = new JTree(root); tree.setRootVisible(true); @@ -127,10 +130,12 @@ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - JOptionPane.showMessageDialog(dialog, tree,_("Tree factor model"), JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(dialog, tree, + _("Tree factor model"), + JOptionPane.INFORMATION_MESSAGE); } }); - + Thread t = new Thread(new Runnable() { public void run() { try { @@ -142,12 +147,12 @@ } }); t.start(); - + // it would really be nice to wait the thread, otherwise the test // means nothing!!! t.join(); } catch (HeadlessException he) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("No X11 display available", he); } } Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/widget/filter/FilterDialogModelMock.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/widget/filter/FilterDialogModelMock.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/widget/filter/FilterDialogModelMock.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -13,6 +13,8 @@ * A simple mock of filter to test Filter operations. * <p/> * To be used in unit tests + * + * @deprecated on 20090514 never used */ public class FilterDialogModelMock extends FilterModel<FilterDialogModelMock.ModelMock, FilterDialogModelMock.ModelMock> { Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/CompileHelperTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/CompileHelperTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/CompileHelperTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -29,10 +29,9 @@ import org.apache.commons.logging.LogFactory; import org.codelutin.util.FileUtil; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; /** * CompileHelperTest. @@ -46,21 +45,12 @@ * Last update: $Date$ * by : $Author$ */ -public class CompileHelperTest { +public class CompileHelperTest extends AbstractIsisFishTest { /** Class logger */ private static Log log = LogFactory.getLog(CompileHelperTest.class); /** - * Called once before all class tests. - * @throws Exception - */ - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - } - - /** * Return a Java code content in Java 6. * * @param name Class name @@ -77,7 +67,7 @@ content.append("}"); return content.toString(); } - + /** * Return a Java code content in Java 6 that extends a class. * @@ -87,7 +77,8 @@ */ protected String getSecondClassContent(String name, String extendsName) { StringBuffer content = new StringBuffer(); - content.append("public class " + name + " extends " + extendsName + " {"); + content.append("public class " + name + " extends " + extendsName + + " {"); content.append(" @Override"); content.append(" public boolean isEmpty(String s) {"); content.append(" return false;"); @@ -95,7 +86,7 @@ content.append("}"); return content.toString(); } - + /** * Test une compilation de classe et une * instantiation de la classe compilée. @@ -105,7 +96,7 @@ */ @Test public void testCompile() throws IOException, ClassNotFoundException { - File f = File.createTempFile("testCompile", ".java", TestUtils.getTargetdir()); + File f = File.createTempFile("testCompile", ".java", getTargetdir()); String filename = FileUtil.basename(f, ".java"); String code = getFirstClassContent(filename); FileUtil.writeString(f, code); @@ -122,7 +113,7 @@ Class<?> c = cl.loadClass(filename); log.info("class name: " + c.getName()); Assert.assertEquals(filename, c.getName()); - + // delete File fclass = new File(f.getAbsolutePath().replaceAll("java$", "class")); fclass.delete(); @@ -138,12 +129,12 @@ @Test public void testCompileDepend() throws IOException, ClassNotFoundException { - File fA = File.createTempFile("testCompileA", ".java", TestUtils.getTargetdir()); + File fA = File.createTempFile("testCompileA", ".java", getTargetdir()); String filenameA = FileUtil.basename(fA, ".java"); String codeA = getFirstClassContent(filenameA); FileUtil.writeString(fA, codeA); - File fB = File.createTempFile("testCompileB", ".java", TestUtils.getTargetdir()); + File fB = File.createTempFile("testCompileB", ".java", getTargetdir()); String filenameB = FileUtil.basename(fB, ".java"); String codeB = getSecondClassContent(filenameB, filenameA); FileUtil.writeString(fB, codeB); @@ -152,8 +143,8 @@ List<File> classpath = new ArrayList<File>(); classpath.add(fB.getParentFile()); - CompileHelper.compile(classpath, Collections.singletonList(fB), - dest, null); + CompileHelper.compile(classpath, Collections.singletonList(fB), dest, + null); // essai de chargement de la classe URL[] cp = new URL[] { dest.toURI().toURL() }; @@ -169,11 +160,13 @@ c = cl.loadClass(filenameA); log.info("class name: " + c.getName()); Assert.assertEquals(filenameA, c.getName()); - + // delete - File fclassA = new File(fA.getAbsolutePath().replaceAll("java$", "class")); + File fclassA = new File(fA.getAbsolutePath().replaceAll("java$", + "class")); fclassA.delete(); - File fclassB = new File(fB.getAbsolutePath().replaceAll("java$", "class")); + File fclassB = new File(fB.getAbsolutePath().replaceAll("java$", + "class")); fclassB.delete(); fA.delete(); fB.delete(); Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/EvaluateHelperTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/EvaluateHelperTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/EvaluateHelperTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -23,10 +23,9 @@ import junit.framework.Assert; -import org.junit.BeforeClass; import org.junit.Test; -import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.AbstractIsisFishTest; import fr.ifremer.isisfish.equation.EmigrationEquation; import fr.ifremer.isisfish.equation.PopulationGrowth; import fr.ifremer.isisfish.equation.PopulationGrowthReverse; @@ -40,13 +39,8 @@ * Last update : $Date$ * By : $Author$ */ -public class EvaluateHelperTest { +public class EvaluateHelperTest extends AbstractIsisFishTest { - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - } - /** * Test #normalizeClassName(). */ @@ -87,28 +81,30 @@ Assert.assertNotNull(result); Assert.assertEquals("4.0", result.toString()); } - + /** * Test #evaluate() but twice to check that previous * class don't stay in class loader. */ @Test public void testDoubleContentEvaluate() { - + Map<String, Object> args = new HashMap<String, Object>(); args.put("context", null); args.put("length", 2.0); args.put("group", null); - + String equationContent = "return length * 2.0;"; Object result = EvaluatorHelper.evaluate("org.codelutin.equation", - "TestDoubleContentEvaluate", PopulationGrowthReverse.class, equationContent, args); + "TestDoubleContentEvaluate", PopulationGrowthReverse.class, + equationContent, args); Assert.assertNotNull(result); Assert.assertEquals("4.0", result.toString()); - + equationContent = "return length * 3.0;"; result = EvaluatorHelper.evaluate("org.codelutin.equation", - "TestDoubleContentEvaluate", PopulationGrowthReverse.class, equationContent, args); + "TestDoubleContentEvaluate", PopulationGrowthReverse.class, + equationContent, args); Assert.assertNotNull(result); Assert.assertEquals("6.0", result.toString()); } Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java 2009-05-13 17:13:02 UTC (rev 2229) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java 2009-05-14 18:09:22 UTC (rev 2230) @@ -32,7 +32,6 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.tmatesoft.svn.core.SVNCommitInfo; @@ -47,8 +46,7 @@ import org.tmatesoft.svn.core.wc.SVNUpdateClient; import org.tmatesoft.svn.core.wc.SVNWCClient; -import fr.ifremer.TestUtils; -import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.AbstractIsisFishTest; /** * Class de test VCS. @@ -61,12 +59,12 @@ * * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ by : $Author: tchemit $ */ -public class VCSSVNTest { +public class VCSSVNTest extends AbstractIsisFishTest { /** Class logger */ private static Log log = LogFactory.getLog(VCSSVNTest.class); - public static final File TMPDIR = TestUtils.getTargetdir(); + public static final File TMPDIR = getTargetdir(); public static final String FILECONTENTTAG = "Version 3.1.0"; public static final String FILECONTENTTRUNK = "Version 3.2.0"; @@ -86,49 +84,19 @@ } /** - * Static test init. - * @throws Exception - */ - @BeforeClass - public static void init() throws Exception { - TestUtils.init(); - - template = new File(TMPDIR, "testsvn-template"); - remoteRepo = new File(TMPDIR, "testsvn-repo"); - localRepo = new File(TMPDIR, "testsvn-local"); - localRepoTrunk = new File(TMPDIR, "testsvn-localTrunk"); - } - - /** - * Clean repo directories. - */ - @Ignore - protected void clean() { - // un peu de nettoyage - if (template.exists()) { - FileUtil.deleteRecursively(template); - } - if (remoteRepo.exists()) { - FileUtil.deleteRecursively(remoteRepo); - } - if (localRepo.exists()) { - FileUtil.deleteRecursively(localRepo); - } - if (localRepoTrunk.exists()) { - FileUtil.deleteRecursively(localRepoTrunk); - } - } - - /** * Init call before each test. * @throws IOException * @throws SVNException */ @Before public void setUp() throws IOException, SVNException { + template = new File(TMPDIR, "testsvn-template"); + remoteRepo = new File(TMPDIR, "testsvn-repo"); + localRepo = new File(TMPDIR, "testsvn-local"); + localRepoTrunk = new File(TMPDIR, "testsvn-localTrunk"); // un peu de nettoyage - clean(); + tearDown(); // creation de l'instance de notre VCS pour les tests // on le fait au debut pour que la l'init de la lib svn soit fait @@ -182,12 +150,23 @@ } /** - * After each test. + * Clean repo directories. */ @After public void tearDown() { // un peu de nettoyage - //clean(); + if (template.exists()) { + FileUtil.deleteRecursively(template); + } + if (remoteRepo.exists()) { + FileUtil.deleteRecursively(remoteRepo); + } + if (localRepo.exists()) { + FileUtil.deleteRecursively(localRepo); + } + if (localRepoTrunk.exists()) { + FileUtil.deleteRecursively(localRepoTrunk); + } } /** @@ -434,7 +413,7 @@ vcs.checkProtocol(); } - + /** * Test cleanup. * @@ -1065,9 +1044,10 @@ Map<File, SVNStatus> files = vcs.getRemoteStatus(null, true); log.info("Will update file = " + files.keySet()); Assert.assertTrue("Must be one file updated", files.size() == 1); - + // try to update... List<File> filesInConflict = vcs.update(null, true); - Assert.assertTrue("No file should be in conflit", filesInConflict.isEmpty()); + Assert.assertTrue("No file should be in conflit", filesInConflict + .isEmpty()); } } \ No newline at end of file