This is an automated email from the git hooks/post-receive script. New commit to branch feature/spgeed in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit ab91f0ab42bd94e569a1166fd2d01261bc607aad Author: Killian <killian.herbreteau@epitech.eu> Date: Mon Sep 30 11:00:32 2019 +0200 passing service test to embedded postgres --- pollen-services/pom.xml | 5 ++++ .../test/FakePollenApplicationContext.java | 29 +++++++++++++++++++--- .../src/test/resources/pollen-services.properties | 10 ++++---- pom.xml | 6 +++++ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/pollen-services/pom.xml b/pollen-services/pom.xml index 0bc5add8..77bfad20 100644 --- a/pollen-services/pom.xml +++ b/pollen-services/pom.xml @@ -55,6 +55,11 @@ <artifactId>pollen-votecounting-borda</artifactId> <version>${project.version}</version> </dependency> + + <dependency> + <groupId>ru.yandex.qatools.embed</groupId> + <artifactId>postgresql-embedded</artifactId> + </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>pollen-votecounting-instant-runoff</artifactId> diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenApplicationContext.java b/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenApplicationContext.java index ea75fa6d..28261d1f 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenApplicationContext.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenApplicationContext.java @@ -24,6 +24,8 @@ package org.chorem.pollen.services.test; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import com.google.common.base.StandardSystemProperty; +import com.google.common.collect.ImmutableList; +import de.flapdoodle.embed.process.config.IRuntimeConfig; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,16 +42,20 @@ import org.chorem.pollen.services.config.PollenServicesConfig; import org.chorem.pollen.services.config.PollenServicesConfigOption; import org.chorem.pollen.services.service.FixturesService; import org.chorem.pollen.votecounting.VoteCountingFactory; -import org.junit.Assert; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.nuiton.topia.persistence.BeanTopiaConfiguration; +import org.nuiton.topia.persistence.TopiaConfiguration; import org.nuiton.topia.persistence.TopiaConfigurationBuilder; import org.nuiton.util.DateUtil; import org.nuiton.util.FileUtil; +import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; +import ru.yandex.qatools.embed.postgresql.distribution.Version; +import ru.yandex.qatools.embed.postgresql.distribution.Version.Main; import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.net.ServerSocket; import java.util.LinkedList; import java.util.List; @@ -112,7 +118,7 @@ public class FakePollenApplicationContext extends TestWatcher implements PollenA File tempDirectoryFile = new File(javaIoTmpDir); FileUtil.createDirectoryIfNecessary(tempDirectoryFile); - String path = Joiner.on(File.separator).join(TIMESTAMP, description.getTestClass().getName(), description.getMethodName(), "h2"); + String path = Joiner.on(File.separator).join(TIMESTAMP, description.getTestClass().getName(), description.getMethodName(), "postgres"); // get test directory testBasedir = new File(tempDirectoryFile, path); @@ -124,6 +130,23 @@ public class FakePollenApplicationContext extends TestWatcher implements PollenA log.debug("testBasedir: " + testBasedir); } + + EmbeddedPostgres embeddedPostgres = new EmbeddedPostgres(Main.V9_6); + IRuntimeConfig cachedRuntimeConfig = EmbeddedPostgres.cachedRuntimeConfig(testBasedir.toPath()); + + String jdbcConnectionUrl; + try { + jdbcConnectionUrl = embeddedPostgres.start(cachedRuntimeConfig, "127.0.0.1", currentPortNumber, "pollen", "pollen", "pollen", ImmutableList.of("-E", "UTF-8")); + } catch (IOException e) { + throw new UncheckedIOException("ne peut pas démarrer postgresql", e); + } + + TopiaConfiguration topiaConfiguration = new TopiaConfigurationBuilder() + .forPostgresqlDatabase(jdbcConnectionUrl, "pollen", "pollen") + .useFlyway() + .validateSchemaOnStartup() + .useDefaultConnectionPool() + .build(); init(); } @@ -140,8 +163,6 @@ public class FakePollenApplicationContext extends TestWatcher implements PollenA // --- create configuration --- // Properties defaultvalues = new Properties(); - Assert.assertNotNull(PollenServicesConfigOption.DATA_DIRECTORY); - Assert.assertNotNull(testBasedir); defaultvalues.put(PollenServicesConfigOption.DATA_DIRECTORY.getKey(), testBasedir.getAbsolutePath()); configuration = new PollenServicesConfig(configurationPath, defaultvalues); diff --git a/pollen-services/src/test/resources/pollen-services.properties b/pollen-services/src/test/resources/pollen-services.properties index 26598cf5..791f869e 100644 --- a/pollen-services/src/test/resources/pollen-services.properties +++ b/pollen-services/src/test/resources/pollen-services.properties @@ -18,11 +18,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # #L% ### -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.connection.url=jdbc:h2:file:${pollen.data.directory}/db/pollen-rest-api -hibernate.connection.username=sa -hibernate.connection.password=sa -hibernate.connection.driver_class=org.h2.Driver +hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +hibernate.connection.url=jdbc:postgresql://localhost:5432/pollenprod?allowMultiQueries=true +hibernate.connection.username=pollen +hibernate.connection.password=pollen +hibernate.connection.driver_class=org.postgresql.Driver #hibernate.hbm2ddl.auto=update pollen.version=${project.version} pollen.devMode=true diff --git a/pom.xml b/pom.xml index 87a20642..f469c81b 100644 --- a/pom.xml +++ b/pom.xml @@ -364,6 +364,12 @@ <version>${postgresqlVersion}</version> </dependency> + <dependency> + <groupId>ru.yandex.qatools.embed</groupId> + <artifactId>postgresql-embedded</artifactId> + <version>2.10</version> + </dependency> + <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.