-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Integration Test for Restaurant Api using DBunit with DBRid…
…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
1 parent
0ed188d
commit bbffe93
Showing
5 changed files
with
150 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...y-registration/src/test/java/dev/helis/registration/RegistrationTestLifecycleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...elivery-registration/src/test/java/dev/helis/registration/rest/RestaurantResourcesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
.../dev/helis/registration/rest/RestaurantResourcesIT.shouldFindAllRestaurants.approved.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"id": 1, | ||
"name": "New Flavor" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
...-registration/src/test/resources/datasets/RestaurantResourcesIT/restaurant-scenario-1.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
restaurant: | ||
- id: 1 | ||
name: New Flavor |