From 306c6d8c5b6f85af33cdb3de4545617c62015fdf Mon Sep 17 00:00:00 2001 From: pablo gonzalez granados Date: Mon, 17 May 2021 13:47:46 +0200 Subject: [PATCH] Move on 602-spring-data-rest module to devServices --- 602-spring-data-rest/README.md | 1 + 602-spring-data-rest/pom.xml | 5 --- .../src/main/resources/application.properties | 6 +-- .../spring/data/rest/BookRepositoryTest.java | 7 +--- .../data/rest/LibraryRepositoryTest.java | 3 -- .../PostgreSqlDatabaseTestResource.java | 41 ------------------- 6 files changed, 4 insertions(+), 59 deletions(-) delete mode 100644 602-spring-data-rest/src/test/java/org/acme/spring/data/rest/containers/PostgreSqlDatabaseTestResource.java diff --git a/602-spring-data-rest/README.md b/602-spring-data-rest/README.md index 3ed0fc92..a5ce0eb4 100644 --- a/602-spring-data-rest/README.md +++ b/602-spring-data-rest/README.md @@ -4,6 +4,7 @@ Used addition features and functionality: - Hibernate Validator - One-to-Many and Many-to-One relationship +- DevServices Used quarkus-spring-data-rest repositories: - CrudRepository diff --git a/602-spring-data-rest/pom.xml b/602-spring-data-rest/pom.xml index 5f212a19..ea7ef6ad 100644 --- a/602-spring-data-rest/pom.xml +++ b/602-spring-data-rest/pom.xml @@ -24,11 +24,6 @@ io.quarkus quarkus-hibernate-validator - - org.testcontainers - postgresql - test - diff --git a/602-spring-data-rest/src/main/resources/application.properties b/602-spring-data-rest/src/main/resources/application.properties index b4ecf4f3..0488d51e 100644 --- a/602-spring-data-rest/src/main/resources/application.properties +++ b/602-spring-data-rest/src/main/resources/application.properties @@ -1,8 +1,4 @@ +# Using devServices quarkus.datasource.db-kind=postgresql -quarkus.datasource.username=quarkus_test -quarkus.datasource.password=quarkus_test -quarkus.datasource.jdbc.url=jdbc:postgresql:quarkus_test -quarkus.datasource.jdbc.max-size=8 -quarkus.datasource.jdbc.min-size=2 quarkus.hibernate-orm.database.generation=drop-and-create quarkus.hibernate-orm.sql-load-script=import.sql \ No newline at end of file diff --git a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/BookRepositoryTest.java b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/BookRepositoryTest.java index 0385e8ef..6ef46390 100644 --- a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/BookRepositoryTest.java +++ b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/BookRepositoryTest.java @@ -4,22 +4,19 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.core.IsNot.not; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.acme.spring.data.rest.containers.PostgreSqlDatabaseTestResource; import org.apache.http.HttpStatus; -import org.junit.Assert; import org.junit.jupiter.api.Test; -import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.Response; @QuarkusTest -@QuarkusTestResource(PostgreSqlDatabaseTestResource.class) class BookRepositoryTest { @Test @@ -101,7 +98,7 @@ void testAllRepositoryMethods() throws InterruptedException { .statusCode(200).extract().response(); List bookNamesRepositorySortedDesc = response.jsonPath().getList("name"); - Assert.assertEquals(bookNamesSortedDesc, bookNamesRepositorySortedDesc); + assertEquals(bookNamesSortedDesc, bookNamesRepositorySortedDesc); } diff --git a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/LibraryRepositoryTest.java b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/LibraryRepositoryTest.java index 2c170e4e..4ca30c07 100644 --- a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/LibraryRepositoryTest.java +++ b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/LibraryRepositoryTest.java @@ -4,15 +4,12 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.notNullValue; -import org.acme.spring.data.rest.containers.PostgreSqlDatabaseTestResource; import org.apache.http.HttpStatus; import org.junit.jupiter.api.Test; -import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest -@QuarkusTestResource(PostgreSqlDatabaseTestResource.class) public class LibraryRepositoryTest { @Test void testAllRepositoryMethods() throws InterruptedException { diff --git a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/containers/PostgreSqlDatabaseTestResource.java b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/containers/PostgreSqlDatabaseTestResource.java deleted file mode 100644 index 6790b74f..00000000 --- a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/containers/PostgreSqlDatabaseTestResource.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.acme.spring.data.rest.containers; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.PostgreSQLContainer; - -import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; - -public class PostgreSqlDatabaseTestResource implements QuarkusTestResourceLifecycleManager { - - private static final String QUARKUS_DB_KIND = "quarkus.datasource.db-kind"; - private static final String QUARKUS_DB_JDBC_URL = "quarkus.datasource.jdbc.url"; - private static final String QUARKUS_DB_USER = "quarkus.datasource.username"; - private static final String QUARKUS_DB_PASSWORD = "quarkus.datasource.password"; - private static final String POSTGRESQL = "postgresql"; - - private PostgreSQLContainer container; - - @Override - public Map start() { - container = new PostgreSQLContainer<>("postgres:13.1"); - container.start(); - - Map config = new HashMap<>(); - config.put(QUARKUS_DB_KIND, POSTGRESQL); - config.put(QUARKUS_DB_JDBC_URL, container.getJdbcUrl()); - config.put(QUARKUS_DB_USER, container.getUsername()); - config.put(QUARKUS_DB_PASSWORD, container.getPassword()); - - return Collections.unmodifiableMap(config); - } - - @Override - public void stop() { - Optional.ofNullable(container).ifPresent(GenericContainer::stop); - } -} \ No newline at end of file