Skip to content

Commit

Permalink
feat: add Integration Test for Restaurant Api using DBunit with DBRid…
Browse files Browse the repository at this point in the history
…er CDI and Approval Test for json asserts

Note: It was necessary remove stax dependency from DBRider Cdi maven dependency  to correct  work
  • Loading branch information
helisfreitas committed Oct 4, 2024
1 parent 0ed188d commit bbffe93
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 17 deletions.
83 changes: 66 additions & 17 deletions my-delivery-registration/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.helis</groupId>
Expand All @@ -11,25 +13,25 @@
<version>0.0.1</version>

<name>Registration Api</name>

<properties>
<compiler-plugin.version>3.13.0</compiler-plugin.version>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.15.1</quarkus.platform.version>
<quarkus.version>3.15.1</quarkus.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.3.1</surefire-plugin.version>
<surefire-plugin.version>3.5.0</surefire-plugin.version>
<testcontainers.version>1.20.2</testcontainers.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -54,27 +56,68 @@
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId> io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
<groupId> io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.database-rider</groupId>
<artifactId>rider-cdi</artifactId>
<version>1.44.0</version>
<scope>test</scope>
<classifier>jakarta</classifier>
<exclusions>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.approvaltests</groupId>
<artifactId>approvaltests</artifactId>
<version>24.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<version>${quarkus.version}</version>
<extensions>true</extensions>
<executions>
<execution>
Expand All @@ -88,16 +131,22 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/*IT.java</include>
<include>**/*Test.java</include>
</includes>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> start() {
POSTGRES.start();

Map<String, String> proprieties = new HashMap<String, String>();

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();
}
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"id": 1,
"name": "New Flavor"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
restaurant:
- id: 1
name: New Flavor

0 comments on commit bbffe93

Please sign in to comment.