Author: tchemit Date: 2011-12-11 20:30:13 +0100 (Sun, 11 Dec 2011) New Revision: 165 Url: http://forge.codelutin.com/repositories/revision/echobase/165 Log: change some tests to IT launchable via maven profiles, svn properties Added: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbZipCreatorIT.java trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseMSAccessToCsvIT.java trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataBadProcessingLoaderTest.java trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataProcessingLoaderTest.java Removed: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbCreatorTest.java trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataBadProcessingTest.java trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataProcessingLoaderTest.java Modified: trunk/echobase-tools/pom.xml trunk/echobase-tools/src/main/resources/csv/baracouda/Data.csv Modified: trunk/echobase-tools/pom.xml =================================================================== --- trunk/echobase-tools/pom.xml 2011-12-11 18:56:22 UTC (rev 164) +++ trunk/echobase-tools/pom.xml 2011-12-11 19:30:13 UTC (rev 165) @@ -154,6 +154,7 @@ </build> <profiles> + <profile> <id>run-loaders</id> <activation> @@ -176,6 +177,42 @@ </plugins> </build> </profile> + + <profile> + <id>msaccess-to-csv</id> + + <build> + <defaultGoal>test</defaultGoal> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <includes> + <include>**/*EchoBaseMSAccessToCsvIT.java</include> + </includes> + </configuration> + </plugin> + </plugins> + </build> + </profile> + + <profile> + <id>db-to-zip</id> + + <build> + <defaultGoal>test</defaultGoal> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <includes> + <include>**/*EchoBaseDbZipCreatorIT.java</include> + </includes> + </configuration> + </plugin> + </plugins> + </build> + </profile> </profiles> </project> Property changes on: trunk/echobase-tools/src/main/resources/csv/baracouda/Data.csv ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbCreatorTest.java =================================================================== --- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbCreatorTest.java 2011-12-11 18:56:22 UTC (rev 164) +++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbCreatorTest.java 2011-12-11 19:30:13 UTC (rev 165) @@ -1,118 +0,0 @@ -/* - * #%L - * EchoBase :: Tools - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 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 Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.tools; - -import fr.ifremer.echobase.tools.loaders.AbstractLoaderTest; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.nuiton.util.FileUtil; - -import java.io.File; - -/** - * To test {@link EchoBaseDbCreator}. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class EchoBaseDbCreatorTest extends AbstractToolTest { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(EchoBaseDbCreatorTest.class); - - protected static File msAccessFile; - - protected File exportdir; - - @BeforeClass - public static void beforeClass() { - AbstractLoaderTest.beforeClass(); - - msAccessFile = FileUtil.getFileFromPaths(TestHelper.getBasedir(), - "src", - "test", - "private", - "baracouda.mdb" - ); - if (!msAccessFile.exists()) { - if (log.isWarnEnabled()) { - log.warn("Could not find " + msAccessFile + - ", the test will be skip."); - } - } - Assume.assumeTrue(msAccessFile.exists()); - } - - @Before - public void setUp() throws Exception { - - super.setUp(); - - exportdir = new File(testdir, "export"); - - // exportdir should not exist - Assert.assertFalse(exportdir.exists()); - - // creates it - FileUtil.createDirectoryIfNecessary(exportdir); - } - - @Test - public void createEchoBaseDb() throws Exception { - - File dir = new File(exportdir, "echobase"); - - if (log.isInfoEnabled()) { - log.info("Generate echobase csv files in " + dir); - } - - File distributionFile = new File(exportdir, "echobase.zip"); - Assert.assertFalse(distributionFile.exists()); - - File basedir = TestHelper.getBasedir(); - File sourceDir = FileUtil.getFileFromFQN(basedir, "src.main.resources.csv"); - new EchoBaseDbCreator().createEchoBaseDb(sourceDir, dir, distributionFile); - - Assert.assertTrue(distributionFile.exists()); - } - - @Test - public void exportMSAccessToCsv() throws Exception { - - File dir = new File(exportdir, "msaccessToCsv"); - - if (log.isInfoEnabled()) { - log.info("Generate msaccess files to csv in " + dir); - } - - new EchoBaseDbCreator().exportMSAccessToCsv(msAccessFile, dir); - } - -} Copied: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbZipCreatorIT.java (from rev 163, trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbCreatorTest.java) =================================================================== --- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbZipCreatorIT.java (rev 0) +++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbZipCreatorIT.java 2011-12-11 19:30:13 UTC (rev 165) @@ -0,0 +1,65 @@ +/* + * #%L + * EchoBase :: Tools + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.tools; + +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.util.FileUtil; + +import java.io.File; + +/** + * To test {@link EchoBaseDbCreator}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class EchoBaseDbZipCreatorIT extends AbstractToolTest { + + protected File exportdir; + + @Test + public void createEchoBaseDb() throws Exception { + + exportdir = new File(testdir, "export"); + + // exportdir should not exist + Assert.assertFalse(exportdir.exists()); + + // creates it + FileUtil.createDirectoryIfNecessary(exportdir); + + File dir = new File(exportdir, "echobase"); + + File distributionFile = new File(exportdir, "echobase.zip"); + Assert.assertFalse(distributionFile.exists()); + + File basedir = TestHelper.getBasedir(); + File sourceDir = FileUtil.getFileFromFQN(basedir, "src.main.resources.csv"); + new EchoBaseDbCreator().createEchoBaseDb(sourceDir, dir, distributionFile); + + Assert.assertTrue(distributionFile.exists()); + } + +} Property changes on: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbZipCreatorIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseMSAccessToCsvIT.java (from rev 163, trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseDbCreatorTest.java) =================================================================== --- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseMSAccessToCsvIT.java (rev 0) +++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/EchoBaseMSAccessToCsvIT.java 2011-12-11 19:30:13 UTC (rev 165) @@ -0,0 +1,85 @@ +/* + * #%L + * EchoBase :: Tools + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.tools; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Test; +import org.nuiton.util.FileUtil; + +import java.io.File; + +/** + * To test {@link EchoBaseDbCreator}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class EchoBaseMSAccessToCsvIT extends AbstractToolTest { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(EchoBaseMSAccessToCsvIT.class); + + protected File msAccessFile; + + protected File exportdir; + + @Test + public void exportMSAccessToCsv() throws Exception { + + msAccessFile = FileUtil.getFileFromPaths(TestHelper.getBasedir(), + "src", + "test", + "private", + "baracouda.mdb" + ); + if (!msAccessFile.exists()) { + if (log.isWarnEnabled()) { + log.warn("Could not find " + msAccessFile + + ", the test will be skip."); + } + } + Assume.assumeTrue(msAccessFile.exists()); + + exportdir = new File(testdir, "export"); + + // exportdir should not exist + Assert.assertFalse(exportdir.exists()); + + // creates it + FileUtil.createDirectoryIfNecessary(exportdir); + + File dir = new File(exportdir, "msaccessToCsv"); + + if (log.isInfoEnabled()) { + log.info("Generate msaccess files to csv in " + dir); + } + + new EchoBaseDbCreator().exportMSAccessToCsv(msAccessFile, dir); + } + +} Copied: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataBadProcessingLoaderTest.java (from rev 163, trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataBadProcessingTest.java) =================================================================== --- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataBadProcessingLoaderTest.java (rev 0) +++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataBadProcessingLoaderTest.java 2011-12-11 19:30:13 UTC (rev 165) @@ -0,0 +1,98 @@ +/* + * #%L + * EchoBase :: Tools + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.tools.loaders; + +import fr.ifremer.echobase.entities.data.Cell; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.List; + +/** + * To test {@link CellLoader}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +@RunWith(Parameterized.class) +public class CellByDataBadProcessingLoaderTest extends AbstractLoaderTest<Cell, CellLoader> { + + /** Id of data processing to treat. */ + private String dataProcessingId; + + @Parameterized.Parameters + public static List<Object[]> data() { + return Arrays.asList(new Object[][]{ + {"EIT_0510_38"}, + {"EIT_83A_38"}, + {"EIT_83B_38"}, + {"EIT_84_38"}, + {"EIT_85_38"}, + {"EIT_86_38"}, + {"EIT_87_38"}, + {"EIT_89A_38"}, + {"EIT_89B_38"}, + {"EIT_90_38"}, + {"EIT_91_38"}, + {"EIT_92_38"}, + {"EIT_93_38"}, + {"EIT_94_38"}, + {"EIT_97_38"}, + }); + } + + static boolean cacheLoaded; + + @Override + public void setUp() throws Exception { + + loadDependencies = false; + + super.setUp(); + + if (!cacheLoaded) { + + // load caches once for all + + loader.loadAllProcessingIdsFromScenario(getDb()); + + cacheLoaded = true; + } + } + + public CellByDataBadProcessingLoaderTest(String dataProcessingId) { + super(CellLoader.class, 0, 0); + this.dataProcessingId = dataProcessingId; + } + + @Test + public void testDataProcessingBad() throws Exception { + boolean contains = loader.getAllProcessingIds().contains(dataProcessingId); + Assert.assertFalse(contains); + } + +} Property changes on: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataBadProcessingLoaderTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataProcessingLoaderTest.java (from rev 163, trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataProcessingLoaderTest.java) =================================================================== --- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataProcessingLoaderTest.java (rev 0) +++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataProcessingLoaderTest.java 2011-12-11 19:30:13 UTC (rev 165) @@ -0,0 +1,236 @@ +/* + * #%L + * EchoBase :: Tools + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.tools.loaders; + +import com.google.common.base.Function; +import com.google.common.collect.Collections2; +import com.google.common.collect.Lists; +import com.healthmarketscience.jackcess.Database; +import fr.ifremer.echobase.EchoBaseIOUtil; +import fr.ifremer.echobase.entities.EchoBaseEntityEnum; +import fr.ifremer.echobase.entities.data.Cell; +import fr.ifremer.echobase.entities.data.DataProcessing; +import fr.ifremer.echobase.entities.meta.AssociationMeta; +import fr.ifremer.echobase.entities.meta.MetaFilenameAware; +import fr.ifremer.echobase.entities.meta.TableMeta; +import fr.ifremer.echobase.services.DbEditorService; +import fr.ifremer.echobase.tools.FileType; +import fr.ifremer.echobase.tools.TestHelper; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.nuiton.topia.TopiaException; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +/** + * To test {@link CellLoader}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +@RunWith(Parameterized.class) +public class CellByDataProcessingLoaderTest extends AbstractLoaderTest<Cell, CellLoader> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(CellByDataProcessingLoaderTest.class); + + /** Id of data processing to treat. */ + private String dataProcessingId; + + @Parameterized.Parameters + public static List<Object[]> data() { + return Arrays.asList(new Object[][]{ + {"EIT_00_38", 0}, + {"EIT_01_38", 0}, + {"EIT_02_38", 0}, + {"EIT_03_38", 0}, + {"EIT_0310_38", 0}, + {"EIT_04_38", 0}, + {"EIT_05_38", 0}, +// {"EIT_0510_38", 0}, + {"EIT_06_38", 0}, + {"EIT_07_38", 0}, + {"EIT_08_38", 0}, + {"EIT_09_38", 0}, + {"EIT_10_38", 0}, +// {"EIT_83A_38", 0}, +// {"EIT_83B_38", 0}, +// {"EIT_84_38", 0}, +// {"EIT_85_38", 0}, +// {"EIT_86_38", 0}, +// {"EIT_87_38", 0}, +// {"EIT_89A_38", 0}, +// {"EIT_89B_38", 0}, +// {"EIT_90_38", 0}, +// {"EIT_91_38", 0}, +// {"EIT_92_38", 0}, +// {"EIT_93_38", 0}, +// {"EIT_94_38", 0}, +// {"EIT_97_38", 0}, + {"EIT_98b_38", 0}, + }); + } + + static boolean cacheLoaded; + + static List<File> directoriesToMerge = Lists.newLinkedList(); + + @Override + public void setUp() throws Exception { + + super.setUp(); + + if (!cacheLoaded) { + + // load caches once for all + + loader.loadCache(getDb()); + + cacheLoaded = true; + } + + Assert.assertTrue(loader.getAllProcessingIds().contains(dataProcessingId)); + } + + static CellLoader lastLoader; + + @Override + public void tearDown() throws Exception { + lastLoader = loader; + super.tearDown(); + + if (log.isInfoEnabled()) { + log.info("TimeLogs : " + DbEditorService.timeLog.getCallCount()); + } + } + + @AfterClass + public static void afterClass() throws Exception { + + // merge all results + if (CollectionUtils.isNotEmpty(directoriesToMerge)) { + + // let's merge all result + File dir = TestHelper.getTestBasedir(CellByDataProcessingLoaderTest.class); + + TableMeta cellMeta = lastLoader.getMeta(); + TableMeta dataMeta = lastLoader.getTable(EchoBaseEntityEnum.Data); + TableMeta dataProcessingMeta = lastLoader.getTable(EchoBaseEntityEnum.DataProcessing); + AssociationMeta dataProcessingToCellMetaAssociation = dataProcessingMeta.getAssociations(DataProcessing.PROPERTY_CELL); + AssociationMeta cellToCellMetaAssociation = cellMeta.getAssociations(Cell.PROPERTY_CHILDS); + AssociationMeta cellToDataMetaAssociation = cellMeta.getAssociations(Cell.PROPERTY_DATA); + + ToFileFromMeta toCellFile = new ToFileFromMeta(lastLoader, cellMeta); + ToFileFromMeta toDataFile = new ToFileFromMeta(lastLoader, dataMeta); + ToFileFromMeta toDataProcessingToCellFile = new ToFileFromMeta(lastLoader, dataProcessingToCellMetaAssociation); + ToFileFromMeta toCellToCellFile = new ToFileFromMeta(lastLoader, cellToCellMetaAssociation); + ToFileFromMeta toCellToDataFile = new ToFileFromMeta(lastLoader, cellToDataMetaAssociation); + + if (log.isInfoEnabled()) { + log.info("Will merge " + directoriesToMerge.size() + " data processing data into " + dir); + } + + mergeFile(dir, toCellFile); + mergeFile(dir, toDataFile); + mergeFile(dir, toDataProcessingToCellFile); + mergeFile(dir, toCellToCellFile); + mergeFile(dir, toCellToDataFile); + } + } + + protected static void mergeFile(File dir, ToFileFromMeta function) throws Exception { + + File mergedFile = function.apply(dir); + if (log.isInfoEnabled()) { + log.info("Will merge to " + mergedFile.getName()); + } + + Collection<File> files = Collections2.transform(directoriesToMerge, function); + + EchoBaseIOUtil.mergeFiles(mergedFile, files); + } + + public CellByDataProcessingLoaderTest(String dataProcessingId, int exceptedDataCount) { + super(CellLoader.class, 0, exceptedDataCount); + this.dataProcessingId = dataProcessingId; + } + + @Test + public void testGenerateEntitiesFromBaracouda() throws Exception { + generateBaracoudaEntities(); + } + + @Override + protected void launchEntitiesFromBaracouda(CellLoader loader, + Database db, + File exportdir) throws IOException, TopiaException, ParseException { + + if (log.isInfoEnabled()) { + log.info("Export to " + exportdir); + } + directoriesToMerge.add(exportdir); + loader.generateEntitiesFromBaracouda(db, exportdir, dataProcessingId, true); + } + + @Override + protected void importEntities(File inFile, + long nbExpected) throws IOException, TopiaException { + // do not use it + } + + private static class ToFileFromMeta implements Function<File, File> { + + private MetaFilenameAware meta; + private FileType fileType; + private CellLoader loader; + + public ToFileFromMeta(CellLoader loader, MetaFilenameAware meta) { + this.meta = meta; + this.loader = loader; + fileType = meta instanceof AssociationMeta ? FileType.ASSOCIATION : FileType.BARACOUDA; + } + + @Override + public File apply(File input) { + + try { + return loader.getTableFile(input, meta, fileType); + } catch (IOException e) { + throw new IllegalStateException("Could not obtain table file", e); + } + } + } +} Property changes on: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellByDataProcessingLoaderTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataBadProcessingTest.java =================================================================== --- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataBadProcessingTest.java 2011-12-11 18:56:22 UTC (rev 164) +++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataBadProcessingTest.java 2011-12-11 19:30:13 UTC (rev 165) @@ -1,98 +0,0 @@ -/* - * #%L - * EchoBase :: Tools - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 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 Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.tools.loaders; - -import fr.ifremer.echobase.entities.data.Cell; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.util.Arrays; -import java.util.List; - -/** - * To test {@link CellLoader}. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -@RunWith(Parameterized.class) -public class CellLoaderByDataBadProcessingTest extends AbstractLoaderTest<Cell, CellLoader> { - - /** Id of data processing to treat. */ - private String dataProcessingId; - - @Parameterized.Parameters - public static List<Object[]> data() { - return Arrays.asList(new Object[][]{ - {"EIT_0510_38"}, - {"EIT_83A_38"}, - {"EIT_83B_38"}, - {"EIT_84_38"}, - {"EIT_85_38"}, - {"EIT_86_38"}, - {"EIT_87_38"}, - {"EIT_89A_38"}, - {"EIT_89B_38"}, - {"EIT_90_38"}, - {"EIT_91_38"}, - {"EIT_92_38"}, - {"EIT_93_38"}, - {"EIT_94_38"}, - {"EIT_97_38"}, - }); - } - - static boolean cacheLoaded; - - @Override - public void setUp() throws Exception { - - loadDependencies = false; - - super.setUp(); - - if (!cacheLoaded) { - - // load caches once for all - - loader.loadAllProcessingIdsFromScenario(getDb()); - - cacheLoaded = true; - } - } - - public CellLoaderByDataBadProcessingTest(String dataProcessingId) { - super(CellLoader.class, 0, 0); - this.dataProcessingId = dataProcessingId; - } - - @Test - public void testDataProcessingBad() throws Exception { - boolean contains = loader.getAllProcessingIds().contains(dataProcessingId); - Assert.assertFalse(contains); - } - -} Deleted: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataProcessingLoaderTest.java =================================================================== --- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataProcessingLoaderTest.java 2011-12-11 18:56:22 UTC (rev 164) +++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/CellLoaderByDataProcessingLoaderTest.java 2011-12-11 19:30:13 UTC (rev 165) @@ -1,236 +0,0 @@ -/* - * #%L - * EchoBase :: Tools - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 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 Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.tools.loaders; - -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; -import com.healthmarketscience.jackcess.Database; -import fr.ifremer.echobase.EchoBaseIOUtil; -import fr.ifremer.echobase.entities.EchoBaseEntityEnum; -import fr.ifremer.echobase.entities.data.Cell; -import fr.ifremer.echobase.entities.data.DataProcessing; -import fr.ifremer.echobase.entities.meta.AssociationMeta; -import fr.ifremer.echobase.entities.meta.MetaFilenameAware; -import fr.ifremer.echobase.entities.meta.TableMeta; -import fr.ifremer.echobase.services.DbEditorService; -import fr.ifremer.echobase.tools.FileType; -import fr.ifremer.echobase.tools.TestHelper; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.nuiton.topia.TopiaException; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -/** - * To test {@link CellLoader}. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -@RunWith(Parameterized.class) -public class CellLoaderByDataProcessingLoaderTest extends AbstractLoaderTest<Cell, CellLoader> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(CellLoaderByDataProcessingLoaderTest.class); - - /** Id of data processing to treat. */ - private String dataProcessingId; - - @Parameterized.Parameters - public static List<Object[]> data() { - return Arrays.asList(new Object[][]{ - {"EIT_00_38", 0}, - {"EIT_01_38", 0}, - {"EIT_02_38", 0}, - {"EIT_03_38", 0}, - {"EIT_0310_38", 0}, - {"EIT_04_38", 0}, - {"EIT_05_38", 0}, -// {"EIT_0510_38", 0}, - {"EIT_06_38", 0}, - {"EIT_07_38", 0}, - {"EIT_08_38", 0}, - {"EIT_09_38", 0}, - {"EIT_10_38", 0}, -// {"EIT_83A_38", 0}, -// {"EIT_83B_38", 0}, -// {"EIT_84_38", 0}, -// {"EIT_85_38", 0}, -// {"EIT_86_38", 0}, -// {"EIT_87_38", 0}, -// {"EIT_89A_38", 0}, -// {"EIT_89B_38", 0}, -// {"EIT_90_38", 0}, -// {"EIT_91_38", 0}, -// {"EIT_92_38", 0}, -// {"EIT_93_38", 0}, -// {"EIT_94_38", 0}, -// {"EIT_97_38", 0}, - {"EIT_98b_38", 0}, - }); - } - - static boolean cacheLoaded; - - static List<File> directoriesToMerge = Lists.newLinkedList(); - - @Override - public void setUp() throws Exception { - - super.setUp(); - - if (!cacheLoaded) { - - // load caches once for all - - loader.loadCache(getDb()); - - cacheLoaded = true; - } - - Assert.assertTrue(loader.getAllProcessingIds().contains(dataProcessingId)); - } - - static CellLoader lastLoader; - - @Override - public void tearDown() throws Exception { - lastLoader = loader; - super.tearDown(); - - if (log.isInfoEnabled()) { - log.info("TimeLogs : " + DbEditorService.timeLog.getCallCount()); - } - } - - @AfterClass - public static void afterClass() throws Exception { - - // merge all results - if (CollectionUtils.isNotEmpty(directoriesToMerge)) { - - // let's merge all result - File dir = TestHelper.getTestBasedir(CellLoaderByDataProcessingLoaderTest.class); - - TableMeta cellMeta = lastLoader.getMeta(); - TableMeta dataMeta = lastLoader.getTable(EchoBaseEntityEnum.Data); - TableMeta dataProcessingMeta = lastLoader.getTable(EchoBaseEntityEnum.DataProcessing); - AssociationMeta dataProcessingToCellMetaAssociation = dataProcessingMeta.getAssociations(DataProcessing.PROPERTY_CELL); - AssociationMeta cellToCellMetaAssociation = cellMeta.getAssociations(Cell.PROPERTY_CHILDS); - AssociationMeta cellToDataMetaAssociation = cellMeta.getAssociations(Cell.PROPERTY_DATA); - - ToFileFromMeta toCellFile = new ToFileFromMeta(lastLoader, cellMeta); - ToFileFromMeta toDataFile = new ToFileFromMeta(lastLoader, dataMeta); - ToFileFromMeta toDataProcessingToCellFile = new ToFileFromMeta(lastLoader, dataProcessingToCellMetaAssociation); - ToFileFromMeta toCellToCellFile = new ToFileFromMeta(lastLoader, cellToCellMetaAssociation); - ToFileFromMeta toCellToDataFile = new ToFileFromMeta(lastLoader, cellToDataMetaAssociation); - - if (log.isInfoEnabled()) { - log.info("Will merge " + directoriesToMerge.size() + " data processing data into " + dir); - } - - mergeFile(dir, toCellFile); - mergeFile(dir, toDataFile); - mergeFile(dir, toDataProcessingToCellFile); - mergeFile(dir, toCellToCellFile); - mergeFile(dir, toCellToDataFile); - } - } - - protected static void mergeFile(File dir, ToFileFromMeta function) throws Exception { - - File mergedFile = function.apply(dir); - if (log.isInfoEnabled()) { - log.info("Will merge to " + mergedFile.getName()); - } - - Collection<File> files = Collections2.transform(directoriesToMerge, function); - - EchoBaseIOUtil.mergeFiles(mergedFile, files); - } - - public CellLoaderByDataProcessingLoaderTest(String dataProcessingId, int exceptedDataCount) { - super(CellLoader.class, 0, exceptedDataCount); - this.dataProcessingId = dataProcessingId; - } - - @Test - public void testGenerateEntitiesFromBaracouda() throws Exception { - generateBaracoudaEntities(); - } - - @Override - protected void launchEntitiesFromBaracouda(CellLoader loader, - Database db, - File exportdir) throws IOException, TopiaException, ParseException { - - if (log.isInfoEnabled()) { - log.info("Export to " + exportdir); - } - directoriesToMerge.add(exportdir); - loader.generateEntitiesFromBaracouda(db, exportdir, dataProcessingId, true); - } - - @Override - protected void importEntities(File inFile, - long nbExpected) throws IOException, TopiaException { - // do not use it - } - - private static class ToFileFromMeta implements Function<File, File> { - - private MetaFilenameAware meta; - private FileType fileType; - private CellLoader loader; - - public ToFileFromMeta(CellLoader loader, MetaFilenameAware meta) { - this.meta = meta; - this.loader = loader; - fileType = meta instanceof AssociationMeta ? FileType.ASSOCIATION : FileType.BARACOUDA; - } - - @Override - public File apply(File input) { - - try { - return loader.getTableFile(input, meta, fileType); - } catch (IOException e) { - throw new IllegalStateException("Could not obtain table file", e); - } - } - } -}
participants (1)
-
tchemit@users.forge.codelutin.com