This is an automated email from the git hooks/post-receive script. New commit to branch feature/8170 in repository echobase. See https://gitlab.nuiton.org/codelutin/echobase.git commit 3f175c7dfb7b2da5e59a778057a18ab5d2784fd0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Apr 2 15:15:45 2016 +0200 Upgrade test import databases --- .../services/FakeEchoBaseServiceContext.java | 55 +++++---- .../service/importdata/MigrateDatabasesIT.java | 134 +++++++++++++++++++++ .../echobase-catches-and-voyage-result.h2.db.gz | Bin 705722 -> 703063 bytes .../import-data/echobase-catches.h2.db.gz | Bin 662677 -> 659616 bytes .../import-data/echobase-commonData.h2.db.gz | Bin 178638 -> 179054 bytes .../resources/import-data/echobase-nodata.h2.db.gz | Bin 129028 -> 129703 bytes .../echobase-operation-total-samples.h2.db.gz | Bin 663495 -> 660514 bytes .../import-data/echobase-operation.h2.db.gz | Bin 324421 -> 323654 bytes 8 files changed, 165 insertions(+), 24 deletions(-) diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/FakeEchoBaseServiceContext.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/FakeEchoBaseServiceContext.java index 0cc107d..3ab7499 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/FakeEchoBaseServiceContext.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/FakeEchoBaseServiceContext.java @@ -30,21 +30,20 @@ import fr.ifremer.echobase.entities.EchoBaseUserTopiaApplicationContext; import fr.ifremer.echobase.persistence.EchoBaseDbMeta; import fr.ifremer.echobase.persistence.EchobaseTopiaApplicationContexts; import fr.ifremer.echobase.persistence.JdbcConfiguration; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.nuiton.topia.persistence.TopiaConfigurationConstants; -import org.nuiton.util.FileUtil; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Date; import java.util.Locale; import java.util.Properties; @@ -65,7 +64,7 @@ public class FakeEchoBaseServiceContext extends TestWatcher implements EchoBaseS /** A time-stamp, allow to make multiple build and keep the tests data. */ protected static final String TIMESTAMP = String.valueOf(System.nanoTime()); - protected final String initDb; + protected String initDb; protected Date fakeCurrentTime; @@ -80,12 +79,17 @@ public class FakeEchoBaseServiceContext extends TestWatcher implements EchoBaseS private EchoBaseUserTopiaApplicationContext echoBaseTopiaApplicationContext; private final EchobaseAieOC injector; + protected String methodName; public FakeEchoBaseServiceContext(String initDb) { this.initDb = initDb; this.injector = new ServiceEchobaseAieOC(); } + protected void setInitDb(String initDb) { + this.initDb = initDb; + } + protected File getTestSpecificDirectory(Description description) { // Trying to look for the temporary folder to store data for the test String tempDirPath = System.getProperty("java.io.tmpdir"); @@ -100,16 +104,26 @@ public class FakeEchoBaseServiceContext extends TestWatcher implements EchoBaseS // create the directory to store database data String dataBasePath = description.getClassName() - + File.separator // a directory with the test class name - + description.getMethodName()// a sub-directory with the method name - + '_' - + TIMESTAMP; // and a timestamp + + File.separator // a directory with the test class name + + description.getMethodName()// a sub-directory with the method name + + '_' + + TIMESTAMP; // and a timestamp return new File(tempDirFile, dataBasePath); } + public Path getWorkingDatabaseFile() { + File dbDirectory = new File(testDir, "db"); + return new File(dbDirectory, "echobase.h2.db").toPath(); + } + + public String getMethodName() { + return methodName; + } + @Override protected void starting(Description description) { super.starting(description); + methodName = description.getMethodName(); testDir = getTestSpecificDirectory(description); if (log.isInfoEnabled()) { log.info("Test dir = " + testDir); @@ -117,29 +131,21 @@ public class FakeEchoBaseServiceContext extends TestWatcher implements EchoBaseS if (initDb != null) { - // let's use this path as the initial db. + Path destinationDb = getWorkingDatabaseFile(); - File dbDirectory = new File(testDir, "db"); - File destinationDb = new File(dbDirectory, "echobase.h2.db"); - InputStream inputStream = getClass().getResourceAsStream(initDb); - Preconditions.checkNotNull(inputStream, "Could not find resource from " + initDb); - try { - FileUtil.createDirectoryIfNecessary(dbDirectory); + try (InputStream inputStream = getClass().getResourceAsStream(initDb)) { + Preconditions.checkNotNull(inputStream, "Could not find resource from " + initDb); - GZIPInputStream gzipStream = new GZIPInputStream(inputStream); + Files.createDirectories(destinationDb.getParent()); - FileOutputStream outputStream = new FileOutputStream(destinationDb); - try { - IOUtils.copy(gzipStream, outputStream); - } finally { - outputStream.close(); + try (GZIPInputStream gzipStream = new GZIPInputStream(inputStream)) { + Files.copy(gzipStream, destinationDb); } } catch (IOException e) { throw new EchoBaseTechnicalException("Could not copy db", e); - } finally { - IOUtils.closeQuietly(inputStream); } + } // init configuration @@ -190,7 +196,8 @@ public class FakeEchoBaseServiceContext extends TestWatcher implements EchoBaseS } @Override - public void setEchoBaseInternalPersistenceContext(EchoBaseInternalPersistenceContext internalTopiaPersistenceContext) { + public void setEchoBaseInternalPersistenceContext(EchoBaseInternalPersistenceContext + internalTopiaPersistenceContext) { this.echoBaseInternalPersistenceContext = internalTopiaPersistenceContext; } diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/MigrateDatabasesIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/MigrateDatabasesIT.java new file mode 100644 index 0000000..7c9d8c7 --- /dev/null +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/MigrateDatabasesIT.java @@ -0,0 +1,134 @@ +/* + * #%L + * EchoBase :: Services + * %% + * Copyright (C) 2011 - 2012 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.services.service.importdata; + +import com.google.common.collect.ImmutableMap; +import fr.ifremer.echobase.services.EchoBaseServiceFixtures; +import fr.ifremer.echobase.services.EchoBaseServiceSupport; +import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.Description; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; +import java.util.zip.GZIPOutputStream; + +/** + * To upgrade all import databases (in src/test/resources/import-data). + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +@Ignore +public class MigrateDatabasesIT extends EchoBaseServiceSupport { + + /** Logger. */ + private static final Log log = LogFactory.getLog(MigrateDatabasesIT.class); + + private static final EchoBaseServiceFixtures FIXTURES = new EchoBaseServiceFixtures(); + + private static final Map<String, String> NAME_TO_DATABASE = ImmutableMap + .<String, String>builder() + .put("noData", FIXTURES.IMPORT_DATA_ECHOBASE_NO_DATA()) + .put("commonData", FIXTURES.IMPORT_DATA_ECHOBASE_COMMON_DATA()) + .put("operation", FIXTURES.IMPORT_DATA_ECHOBASE_OPERATION()) + .put("operationWithTotalSamples", FIXTURES.IMPORT_DATA_ECHOBASE_OPERATION_TOTAL_SAMPLES()) + .put("catches", FIXTURES.IMPORT_DATA_ECHOBASE_CATCHES()) + .put("catchesWithVoyageResult", FIXTURES.IMPORT_DATA_ECHOBASE_CATCHES_AND_VOYAGE_RESULT()) + .build(); + + @Rule + public FakeEchoBaseServiceContext fakeServiceContext = new FakeEchoBaseServiceContext(null) { + + @Override + protected void starting(Description description) { + String methodName = description.getMethodName(); + String databaseLocation = NAME_TO_DATABASE.get(methodName); + setInitDb(databaseLocation); + super.starting(description); + } + }; + + @Before + public void setUp() throws Exception { + + this.serviceContext = fakeServiceContext; + + } + + @After + public void tearDown() throws Exception { + + Path sourceDatabase = fakeServiceContext.getWorkingDatabaseFile(); + + String methodName = fakeServiceContext.getMethodName(); + String databaseLocation = NAME_TO_DATABASE.get(methodName); + + fakeServiceContext.getEchoBaseUserApplicationContext().closeContext(); + + Path databaseTargetPath = Paths.get("").toAbsolutePath() + .resolve("src") + .resolve("test") + .resolve("resources") + .resolve("import-data") + .resolve(Paths.get(databaseLocation).getName(1)); + if (log.isInfoEnabled()) { + log.info("Migrates from:\n" + sourceDatabase + "\nto:\n" + databaseTargetPath); + } + + try (GZIPOutputStream outputStream = new GZIPOutputStream(Files.newOutputStream(databaseTargetPath))) { + Files.copy(sourceDatabase, outputStream); + } + + } + + @Test + public void noData() { + } + + @Test + public void commonData() { + } + + @Test + public void operation() { + } + + @Test + public void operationWithTotalSamples() { + } + + @Test + public void catches() { + } + + @Test + public void catchesWithVoyageResult() { + } +} diff --git a/echobase-services/src/test/resources/import-data/echobase-catches-and-voyage-result.h2.db.gz b/echobase-services/src/test/resources/import-data/echobase-catches-and-voyage-result.h2.db.gz index 0f3629d..2abcc07 100644 Binary files a/echobase-services/src/test/resources/import-data/echobase-catches-and-voyage-result.h2.db.gz and b/echobase-services/src/test/resources/import-data/echobase-catches-and-voyage-result.h2.db.gz differ diff --git a/echobase-services/src/test/resources/import-data/echobase-catches.h2.db.gz b/echobase-services/src/test/resources/import-data/echobase-catches.h2.db.gz index f773742..e12e37f 100644 Binary files a/echobase-services/src/test/resources/import-data/echobase-catches.h2.db.gz and b/echobase-services/src/test/resources/import-data/echobase-catches.h2.db.gz differ diff --git a/echobase-services/src/test/resources/import-data/echobase-commonData.h2.db.gz b/echobase-services/src/test/resources/import-data/echobase-commonData.h2.db.gz index 10b5843..c5f02e9 100644 Binary files a/echobase-services/src/test/resources/import-data/echobase-commonData.h2.db.gz and b/echobase-services/src/test/resources/import-data/echobase-commonData.h2.db.gz differ diff --git a/echobase-services/src/test/resources/import-data/echobase-nodata.h2.db.gz b/echobase-services/src/test/resources/import-data/echobase-nodata.h2.db.gz index 472d6ca..e60883d 100644 Binary files a/echobase-services/src/test/resources/import-data/echobase-nodata.h2.db.gz and b/echobase-services/src/test/resources/import-data/echobase-nodata.h2.db.gz differ diff --git a/echobase-services/src/test/resources/import-data/echobase-operation-total-samples.h2.db.gz b/echobase-services/src/test/resources/import-data/echobase-operation-total-samples.h2.db.gz index 364e38f..2592445 100644 Binary files a/echobase-services/src/test/resources/import-data/echobase-operation-total-samples.h2.db.gz and b/echobase-services/src/test/resources/import-data/echobase-operation-total-samples.h2.db.gz differ diff --git a/echobase-services/src/test/resources/import-data/echobase-operation.h2.db.gz b/echobase-services/src/test/resources/import-data/echobase-operation.h2.db.gz index e65a57a..b84c415 100644 Binary files a/echobase-services/src/test/resources/import-data/echobase-operation.h2.db.gz and b/echobase-services/src/test/resources/import-data/echobase-operation.h2.db.gz differ -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.