+
+
+
+
Application
+
+ - GroupId: ibm.gse.eda
+ - ArtifactId: vaccine-order-mgr
+ - Version: 1.0.0
+ - Quarkus Version: 0.11.0
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
new file mode 100644
index 0000000..6e7c69a
--- /dev/null
+++ b/src/main/resources/application.properties
@@ -0,0 +1,7 @@
+# Configuration file
+# key = value
+quarkus.swagger-ui.always-include=true
+quarkus.mongodb.connection-string=mongodb://localhost:27017/vaccinedb
+# mandatory if you don't specify the name of the database using @MongoEntity
+quarkus.mongodb.database=vaccinedb
+quarkus.openshift.expose=true
diff --git a/src/test/java/ibm/gse/eda/api/MongoDbContainer.java b/src/test/java/ibm/gse/eda/api/MongoDbContainer.java
new file mode 100644
index 0000000..b0f4460
--- /dev/null
+++ b/src/test/java/ibm/gse/eda/api/MongoDbContainer.java
@@ -0,0 +1,26 @@
+package ibm.gse.eda.api;
+
+import javax.validation.constraints.NotNull;
+
+import org.testcontainers.containers.GenericContainer;
+
+public class MongoDbContainer extends GenericContainer
{
+
+ public static final String DEFAULT_IMAGE_AND_TAG = "mongo:4.2.6";
+ public static final String MONGODB_HOST = "localhost";
+ public static final int MONGODB_PORT = 27017;
+
+ public MongoDbContainer() {
+ this(DEFAULT_IMAGE_AND_TAG);
+ }
+
+ public MongoDbContainer(@NotNull String image) {
+ super(image);
+ addExposedPort(MONGODB_PORT);
+ }
+
+ @NotNull
+ public Integer getPort() {
+ return getMappedPort(MONGODB_PORT);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/ibm/gse/eda/api/NativeOrderResourceIT.java b/src/test/java/ibm/gse/eda/api/NativeOrderResourceIT.java
new file mode 100644
index 0000000..4cb317f
--- /dev/null
+++ b/src/test/java/ibm/gse/eda/api/NativeOrderResourceIT.java
@@ -0,0 +1,9 @@
+package ibm.gse.eda.api;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+public class NativeOrderResourceIT extends OrderResourceTest {
+
+ // Execute the same tests but in native mode.
+}
\ No newline at end of file
diff --git a/src/test/java/ibm/gse/eda/api/OrderResourceTest.java b/src/test/java/ibm/gse/eda/api/OrderResourceTest.java
new file mode 100644
index 0000000..b17fd58
--- /dev/null
+++ b/src/test/java/ibm/gse/eda/api/OrderResourceTest.java
@@ -0,0 +1,119 @@
+package ibm.gse.eda.api;
+
+import static ibm.gse.eda.api.MongoDbContainer.MONGODB_HOST;
+import static ibm.gse.eda.api.MongoDbContainer.MONGODB_PORT;
+import static io.restassured.config.LogConfig.logConfig;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.github.dockerjava.api.model.ExposedPort;
+import com.github.dockerjava.api.model.PortBinding;
+import com.github.dockerjava.api.model.Ports;
+
+import org.bson.types.ObjectId;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+
+import ibm.gse.eda.api.dto.VaccineOrder;
+import ibm.gse.eda.vaccines.domain.OrderStatus;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.config.ObjectMapperConfig;
+import io.restassured.http.ContentType;
+import io.restassured.parsing.Parser;
+import org.assertj.core.api.Assertions;
+
+@Testcontainers
+@QuarkusTest
+public class OrderResourceTest {
+
+ @Container
+ static GenericContainer MONGO_DB_CONTAINER = new MongoDbContainer()
+ .withCreateContainerCmdModifier(cmd -> cmd.withHostName(MONGODB_HOST)
+ .withPortBindings(new PortBinding(Ports.Binding.bindPort(MONGODB_PORT), new ExposedPort(MONGODB_PORT))));
+
+ @BeforeAll
+ static void initAll() {
+ RestAssured.defaultParser = Parser.JSON;
+ RestAssured.config
+ .logConfig((logConfig().enableLoggingOfRequestAndResponseIfValidationFails()))
+ .objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory((type, s) -> new ObjectMapper()
+ .registerModule(new Jdk8Module())
+ .registerModule(new JavaTimeModule())
+ .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)));
+ }
+ @Test
+ public void testOrderCRUD() {
+ String order1 = "{ \"deliveryLocation\" : \"Paris\",\"quantity\" : \"2\", \"status\" : \"OPEN\", \"priority\" : \"1\" , \"deliveryDate\" : \"2020-09-30\" }";
+ RestAssured.given()
+ .contentType(ContentType.JSON)
+ .body(order1)
+ .when()
+ .post("/orders")
+ .then()
+ .statusCode(201);
+
+ String order2 = "{ \"id\" : \"5889273c093d1c3e614bf2fa\",\"deliveryLocation\" : \"Hanoi\",\"quantity\" : \"1\", \"status\" : \"OPEN\", \"priority\" : \"1\" , \"deliveryDate\" : \"2020-08-30\" }";
+ RestAssured.given()
+ .contentType(ContentType.JSON)
+ .body(order2)
+ .when()
+ .post("/orders")
+ .then()
+ .statusCode(201);
+
+ VaccineOrder order = RestAssured
+ .given()
+ .when()
+ .contentType(ContentType.JSON)
+ .get("/orders/search/{destination}", "Paris")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().as(VaccineOrder.class);
+
+ Assertions.assertThat(order.deliveryLocation).isEqualTo("Paris");
+ Assertions.assertThat(order.status).isEqualTo(OrderStatus.OPEN);
+
+ order = RestAssured
+ .given()
+ .when()
+ .contentType(ContentType.JSON)
+ .get("/orders/{id}", "5889273c093d1c3e614bf2fa")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().as(VaccineOrder.class);
+
+ Assertions.assertThat(order.id).isEqualTo("5889273c093d1c3e614bf2fa");
+ Assertions.assertThat(order.deliveryLocation).isEqualTo("Hanoi");
+
+ VaccineOrder[] persons = RestAssured.given()
+ .when()
+ .contentType(ContentType.JSON)
+ .get("/orders")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().as(VaccineOrder[].class);
+
+ Assertions.assertThat(persons.length).isEqualTo(2);
+ Long count = RestAssured
+ .given()
+ .when()
+ .contentType(ContentType.JSON)
+ .get("/orders/count")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().as(Long.class);
+
+ Assertions.assertThat(count).isGreaterThan(1);
+ }
+
+}
\ No newline at end of file