diff --git a/my-delivery-registration/pom.xml b/my-delivery-registration/pom.xml index 41f0931..16b5d0f 100644 --- a/my-delivery-registration/pom.xml +++ b/my-delivery-registration/pom.xml @@ -1,5 +1,7 @@ - - + + 4.0.0 dev.helis @@ -11,25 +13,25 @@ 0.0.1 Registration Api - + 3.13.0 21 + 21 + 21 UTF-8 UTF-8 - quarkus-bom - io.quarkus.platform - 3.15.1 + 3.15.1 true - 3.3.1 + 3.5.0 + 1.20.2 - - ${quarkus.platform.group-id} - ${quarkus.platform.artifact-id} - ${quarkus.platform.version} + io.quarkus + quarkus-bom + ${quarkus.version} pom import @@ -54,27 +56,68 @@ quarkus-resteasy-jsonb - io.quarkus - quarkus-hibernate-validator + io.quarkus + quarkus-hibernate-validator io.quarkus quarkus-smallrye-openapi - + io.quarkus quarkus-junit5 test - + + org.testcontainers + testcontainers + ${testcontainers.version} + test + + + org.testcontainers + postgresql + ${testcontainers.version} + test + + + com.github.database-rider + rider-cdi + 1.44.0 + test + jakarta + + + stax-api + stax + + + + + io.rest-assured + rest-assured + test + + + com.approvaltests + approvaltests + 24.7.0 + test + + + com.google.code.gson + gson + 2.11.0 + test + - ${quarkus.platform.group-id} + io.quarkus quarkus-maven-plugin - ${quarkus.platform.version} + ${quarkus.version} true @@ -88,6 +131,7 @@ + org.apache.maven.plugins maven-compiler-plugin ${compiler-plugin.version} @@ -95,9 +139,14 @@ + org.apache.maven.plugins maven-surefire-plugin ${surefire-plugin.version} + + **/*IT.java + **/*Test.java + org.jboss.logmanager.LogManager ${maven.home} diff --git a/my-delivery-registration/src/test/java/dev/helis/registration/RegistrationTestLifecycleManager.java b/my-delivery-registration/src/test/java/dev/helis/registration/RegistrationTestLifecycleManager.java new file mode 100644 index 0000000..af029b1 --- /dev/null +++ b/my-delivery-registration/src/test/java/dev/helis/registration/RegistrationTestLifecycleManager.java @@ -0,0 +1,34 @@ +package dev.helis.registration; + +import java.util.HashMap; +import java.util.Map; + +import org.testcontainers.containers.PostgreSQLContainer; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; + +public class RegistrationTestLifecycleManager implements QuarkusTestResourceLifecycleManager { + + public static final PostgreSQLContainer POSTGRES = new PostgreSQLContainer<>("postgres:12.0"); + + @Override + public Map start() { + POSTGRES.start(); + + Map proprieties = new HashMap(); + + proprieties.put("quarkus.datasource.jdbc.url", POSTGRES.getJdbcUrl()); + proprieties.put("quarkus.datasource.username", POSTGRES.getUsername()); + proprieties.put("quarkus.datasource.password", POSTGRES.getPassword()); + + return proprieties; + } + + @Override + public void stop() { + if(POSTGRES != null && POSTGRES.isRunning()) { + POSTGRES.stop(); + } + } + +} \ No newline at end of file diff --git a/my-delivery-registration/src/test/java/dev/helis/registration/rest/RestaurantResourcesIT.java b/my-delivery-registration/src/test/java/dev/helis/registration/rest/RestaurantResourcesIT.java new file mode 100644 index 0000000..e63a6af --- /dev/null +++ b/my-delivery-registration/src/test/java/dev/helis/registration/rest/RestaurantResourcesIT.java @@ -0,0 +1,41 @@ +package dev.helis.registration.rest; + +import static io.restassured.RestAssured.given; + +import org.approvaltests.JsonApprovals; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import com.github.database.rider.core.api.configuration.DBUnit; +import com.github.database.rider.core.api.configuration.Orthography; +import com.github.database.rider.core.api.dataset.DataSet; +import com.github.database.rider.cdi.api.DBRider; + +import dev.helis.registration.RegistrationTestLifecycleManager; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import jakarta.transaction.Transactional; + +@DBRider +@DBUnit(caseInsensitiveStrategy = Orthography.LOWERCASE, alwaysCleanBefore=true) +@QuarkusTest +@QuarkusTestResource(RegistrationTestLifecycleManager.class) +@Tag("integration") +@Tag("restaurant-feature") +class RestaurantResourcesIT { + + @Test + @DataSet(value = "/RestaurantResourcesIT/restaurant-scenario-1.yml") + @Transactional + void shouldFindAllRestaurants() { + + String response = given() + .when().get(ResourcePaths.RESTAURANTS) + .then() + .statusCode(200) + .extract().asString(); + + JsonApprovals.verifyJson(response); + } + +} diff --git a/my-delivery-registration/src/test/java/dev/helis/registration/rest/RestaurantResourcesIT.shouldFindAllRestaurants.approved.json b/my-delivery-registration/src/test/java/dev/helis/registration/rest/RestaurantResourcesIT.shouldFindAllRestaurants.approved.json new file mode 100644 index 0000000..c546ce9 --- /dev/null +++ b/my-delivery-registration/src/test/java/dev/helis/registration/rest/RestaurantResourcesIT.shouldFindAllRestaurants.approved.json @@ -0,0 +1,6 @@ +[ + { + "id": 1, + "name": "New Flavor" + } +] \ No newline at end of file diff --git a/my-delivery-registration/src/test/resources/datasets/RestaurantResourcesIT/restaurant-scenario-1.yml b/my-delivery-registration/src/test/resources/datasets/RestaurantResourcesIT/restaurant-scenario-1.yml new file mode 100644 index 0000000..976d73f --- /dev/null +++ b/my-delivery-registration/src/test/resources/datasets/RestaurantResourcesIT/restaurant-scenario-1.yml @@ -0,0 +1,3 @@ +restaurant: + - id: 1 + name: New Flavor