diff --git a/pom.xml b/pom.xml
index 6f2b19a..e5f612c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,6 +108,21 @@
rest-assured
test
+
+ org.testcontainers
+ testcontainers
+ test
+
+
+ org.testcontainers
+ junit-jupiter
+ test
+
+
+ org.testcontainers
+ postgresql
+ test
+
io.quarkus
@@ -122,13 +137,6 @@
io.quarkus
quarkus-logging-json
-
-
- org.tkit.quarkus
- tkit-quarkus-test
- 1.12.0
- test
-
@@ -187,34 +195,25 @@
- org.tkit.maven
- tkit-mp-restclient-plugin
- 0.11.0
+ org.openapitools
+ openapi-generator-maven-plugin
+ 5.1.0
- test
- codegen
+ generate
src/main/resources/product-service-openapi.yaml
-
- com.devonfw.quarkus.general.restclient.product
- com.devonfw.quarkus.general.restclient.product.models
- false
- false
- LOMBOK
- JACKSON
-
- org.eclipse.microprofile.rest.client.inject.RegisterRestClient(configKey="product-service-key")
- javax.enterprise.context.ApplicationScoped
-
-
- lombok.ToString
- io.quarkus.runtime.annotations.RegisterForReflection
-
+ jaxrs-spec
+ com.devonfw.quarkus.ordermanagement.restclient.product
+ com.devonfw.quarkus.ordermanagement.restclient.product.models
restclient
+ false
+ true
+ true
+ false
diff --git a/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java b/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java
index 5bb4799..5a3389f 100644
--- a/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java
+++ b/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java
@@ -4,73 +4,74 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
-import javax.persistence.Transient;
import javax.persistence.Version;
/**
- * Abstract base class for all persistence entities with an {@link #getId() id} and a
+ * Abstract base class for all {@link PersistenceEntity persistence entities} with an {@link #getId() id} and a
* {@link #getModificationCounter() modificationCounter} (version) field. All persistence entities of this application
- * should inherit from this class. It is using JPA annotations at the getters what has several advantages but also
- * implies that you have to annotate transient getter methods with the {@link Transient} annotation.
+ * should inherit from this class.
*/
@MappedSuperclass
public abstract class ApplicationPersistenceEntity {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
- private Integer modificationCounter;
+ @Version
+ private Integer modificationCounter;
- public ApplicationPersistenceEntity() {
+ /**
+ * The constructor.
+ */
+ public ApplicationPersistenceEntity() {
- super();
- }
+ super();
+ }
- public Long getId() {
+ public Long getId() {
- return this.id;
- }
+ return this.id;
+ }
- public void setId(Long id) {
+ public void setId(Long id) {
- this.id = id;
- }
+ this.id = id;
+ }
- @Version
- public Integer getModificationCounter() {
+ public Integer getModificationCounter() {
- return this.modificationCounter;
- }
+ return this.modificationCounter;
+ }
- public void setModificationCounter(Integer version) {
+ public void setModificationCounter(Integer version) {
- this.modificationCounter = version;
- }
+ this.modificationCounter = version;
+ }
- @Override
- public String toString() {
+ @Override
+ public String toString() {
- StringBuilder buffer = new StringBuilder();
- toString(buffer);
- return buffer.toString();
- }
+ StringBuilder buffer = new StringBuilder();
+ toString(buffer);
+ return buffer.toString();
+ }
+
+ /**
+ * Method to extend {@link #toString()} logic.
+ *
+ * @param buffer is the {@link StringBuilder} where to {@link StringBuilder#append(Object) append} the string
+ * representation.
+ */
+ protected void toString(StringBuilder buffer) {
- /**
- * Method to extend {@link #toString()} logic.
- *
- * @param buffer is the {@link StringBuilder} where to {@link StringBuilder#append(Object) append} the string
- * representation.
- */
- protected void toString(StringBuilder buffer) {
-
- buffer.append(getClass().getSimpleName());
- if (this.id != null) {
- buffer.append("[id=");
- buffer.append(this.id);
- buffer.append("]");
- }
+ buffer.append(getClass().getSimpleName());
+ if (this.id != null) {
+ buffer.append("[id=");
+ buffer.append(this.id);
+ buffer.append("]");
}
+ }
}
diff --git a/src/main/java/com/devonfw/quarkus/ordermanagement/domain/model/ItemEntity.java b/src/main/java/com/devonfw/quarkus/ordermanagement/domain/model/ItemEntity.java
index 547b722..40d50ee 100644
--- a/src/main/java/com/devonfw/quarkus/ordermanagement/domain/model/ItemEntity.java
+++ b/src/main/java/com/devonfw/quarkus/ordermanagement/domain/model/ItemEntity.java
@@ -1,16 +1,18 @@
package com.devonfw.quarkus.ordermanagement.domain.model;
-import com.devonfw.quarkus.general.domain.model.ApplicationPersistenceEntity;
-import lombok.Getter;
-import lombok.Setter;
+import java.math.BigDecimal;
+import java.time.Instant;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
-import java.math.BigDecimal;
-import java.time.Instant;
+
+import com.devonfw.quarkus.general.domain.model.ApplicationPersistenceEntity;
+
+import lombok.Getter;
+import lombok.Setter;
@Getter
@Setter
@@ -18,15 +20,15 @@
@Table(name = "ITEM")
public class ItemEntity extends ApplicationPersistenceEntity {
- private String title;
+ private String title;
- private BigDecimal price;
+ private BigDecimal price;
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "productorder", referencedColumnName = "id")
- private OrderEntity productorder;
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "productorder", referencedColumnName = "id")
+ private OrderEntity productorder;
- private Instant creationDate;
+ private Instant creationDate;
- private Long productId;
+ private Long productId;
}
diff --git a/src/main/java/com/devonfw/quarkus/ordermanagement/logic/UcManageOrder.java b/src/main/java/com/devonfw/quarkus/ordermanagement/logic/UcManageOrder.java
index 442bd29..4ffb55c 100644
--- a/src/main/java/com/devonfw/quarkus/ordermanagement/logic/UcManageOrder.java
+++ b/src/main/java/com/devonfw/quarkus/ordermanagement/logic/UcManageOrder.java
@@ -10,18 +10,17 @@
import javax.inject.Inject;
import javax.inject.Named;
import javax.transaction.Transactional;
-import javax.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.inject.RestClient;
-import com.devonfw.quarkus.general.restclient.product.ProductsRestClient;
-import com.devonfw.quarkus.general.restclient.product.models.ProductDto;
import com.devonfw.quarkus.ordermanagement.domain.model.ItemEntity;
import com.devonfw.quarkus.ordermanagement.domain.model.OrderEntity;
import com.devonfw.quarkus.ordermanagement.domain.model.OrderStatus;
import com.devonfw.quarkus.ordermanagement.domain.repo.ItemRepository;
import com.devonfw.quarkus.ordermanagement.domain.repo.OrderRepository;
import com.devonfw.quarkus.ordermanagement.rest.v1.model.NewOrderDto;
+import com.devonfw.quarkus.ordermanagement.restclient.product.ProductRestClient;
+import com.devonfw.quarkus.ordermanagement.restclient.product.models.ProductDto;
@Named
@Transactional
@@ -36,7 +35,7 @@ public class UcManageOrder {
@Inject
@RestClient
- ProductsRestClient productsRestClient;
+ ProductRestClient productsRestClient;
public void saveOrder(NewOrderDto dto) {
@@ -48,13 +47,12 @@ public void saveOrder(NewOrderDto dto) {
List listItems = new ArrayList<>();
BigDecimal totalPrice = new BigDecimal(0.0);
for (Long id : dto.getOrderedProductIds()) {
- Response response = this.productsRestClient.getProductById(String.valueOf(id));
- ProductDto productDto = response.readEntity(ProductDto.class);
+ ProductDto productDto = this.productsRestClient.productV1IdGet(String.valueOf(id));
ItemEntity itemEntity = new ItemEntity();
- itemEntity.setTitle(productDto.title);
- itemEntity.setProductId(productDto.id);
+ itemEntity.setTitle(productDto.getTitle());
+ itemEntity.setProductId(productDto.getId());
itemEntity.setCreationDate(Instant.now());
- itemEntity.setPrice(productDto.price);
+ itemEntity.setPrice(productDto.getPrice());
totalPrice = totalPrice.add(itemEntity.getPrice());
listItems.add(itemEntity);
}
diff --git a/src/main/java/com/devonfw/quarkus/ordermanagement/restclient/product/ProductRestClient.java b/src/main/java/com/devonfw/quarkus/ordermanagement/restclient/product/ProductRestClient.java
new file mode 100644
index 0000000..3816c9a
--- /dev/null
+++ b/src/main/java/com/devonfw/quarkus/ordermanagement/restclient/product/ProductRestClient.java
@@ -0,0 +1,15 @@
+package com.devonfw.quarkus.ordermanagement.restclient.product;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.ws.rs.Path;
+
+import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
+
+import com.devonfw.quarkus.ordermanagement.restclient.product.DefaultApi;
+
+@Path("/product/v1")
+@RegisterRestClient(configKey = "product-service-key")
+@ApplicationScoped
+public interface ProductRestClient extends DefaultApi {
+
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index a04ae32..aea4785 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -17,9 +17,10 @@ quarkus.datasource.password=demo
%dev.quarkus.log.console.format=%d{HH:mm:ss} %-5p traceId=%X{traceId}, parentId=%X{parentId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{2.}] (%t) %s%e%n
# TEST profile
-%test.quarkus.datasource.password=demo
+%test.quarkus.datasource.jdbc.driver=org.testcontainers.jdbc.ContainerDatabaseDriver
+%test.quarkus.datasource.jdbc.url=jdbc:tc:postgresql:11.5://demo_db
%test.quarkus.datasource.username=demo
+%test.quarkus.datasource.password=demo
%test.quarkus.hibernate-orm.database.generation=drop-and-create
-%test.quarkus.hibernate-orm.log.sql=true
-
+ryuk.container.image=testcontainersofficial/ryuk
diff --git a/src/main/resources/product-service-openapi.yaml b/src/main/resources/product-service-openapi.yaml
index ad3b775..ffbd225 100644
--- a/src/main/resources/product-service-openapi.yaml
+++ b/src/main/resources/product-service-openapi.yaml
@@ -1,5 +1,5 @@
# OpenAPI specification of devon4quarkus product service https://github.com/devonfw-sample/devon4quarkus-reference
-# Used by tkit-mp-restclient-plugin to generate the corresponding rest client
+# Used by openapi-generator-maven-plugin to generate the corresponding API for the rest client
---
openapi: 3.0.3
info:
@@ -11,227 +11,39 @@ tags:
- name: product
description: Product API.
paths:
- /products:
+ /product/v1:
get:
- description: "Returns list of Products matching given criteria, uses pagination"
- operationId: Get Products
- parameters:
- - name: page
- in: query
- schema:
- format: int32
- default: 0
- type: integer
- - name: price
- in: query
- schema:
- type: number
- - name: priceMax
- in: query
- schema:
- type: number
- - name: priceMin
- in: query
- schema:
- type: number
- - name: size
- in: query
- schema:
- format: int32
- default: 10
- type: integer
- - name: title
- in: query
- schema:
- type: string
responses:
"200":
description: OK
content:
application/json:
schema:
- $ref: '#/components/schemas/PagedProductResponse'
- "500": {}
+ $ref: '#/components/schemas/PageProductDto'
post:
- description: Stores new Product in DB
- operationId: createNewProduct
requestBody:
content:
application/json:
schema:
- $ref: '#/components/schemas/NewProductDto'
- responses:
- "201":
- description: "OK, New Product created"
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/NewProductDto'
- "400":
- description: "Client side error, invalid request"
- "500": {}
- /products/criteriaApi:
- get:
- parameters:
- - name: page
- in: query
- schema:
- format: int32
- default: 0
- type: integer
- - name: price
- in: query
- schema:
- type: number
- - name: priceMax
- in: query
- schema:
- type: number
- - name: priceMin
- in: query
- schema:
- type: number
- - name: size
- in: query
- schema:
- format: int32
- default: 10
- type: integer
- - name: title
- in: query
- schema:
- type: string
+ $ref: '#/components/schemas/ProductDto'
responses:
"200":
description: OK
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/PageImplProductDto'
- /products/nativeQuery:
- get:
- parameters:
- - name: page
- in: query
- schema:
- format: int32
- default: 0
- type: integer
- - name: price
- in: query
- schema:
- type: number
- - name: priceMax
- in: query
- schema:
- type: number
- - name: priceMin
- in: query
- schema:
- type: number
- - name: size
- in: query
- schema:
- format: int32
- default: 10
- type: integer
- - name: title
- in: query
- schema:
- type: string
- responses:
- "200":
- description: OK
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/PageImplProductDto'
- /products/ordered:
- get:
- responses:
- "200":
- description: OK
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/PageImplProductDto'
- /products/query:
- get:
- parameters:
- - name: page
- in: query
- schema:
- format: int32
- default: 0
- type: integer
- - name: price
- in: query
- schema:
- type: number
- - name: priceMax
- in: query
- schema:
- type: number
- - name: priceMin
- in: query
- schema:
- type: number
- - name: size
- in: query
- schema:
- format: int32
- default: 10
- type: integer
- - name: title
- in: query
- schema:
- type: string
- responses:
- "200":
- description: OK
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/PageImplProductDto'
- /products/queryDsl:
- get:
- parameters:
- - name: page
- in: query
- schema:
- format: int32
- default: 0
- type: integer
- - name: price
- in: query
- schema:
- type: number
- - name: priceMax
- in: query
- schema:
- type: number
- - name: priceMin
- in: query
- schema:
- type: number
- - name: size
- in: query
- schema:
- format: int32
- default: 10
- type: integer
- - name: title
- in: query
- schema:
- type: string
+ /product/v1/search:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ProductSearchCriteriaDto'
responses:
"200":
description: OK
content:
application/json:
schema:
- $ref: '#/components/schemas/PageImplProductDto'
- /products/title/{title}:
+ $ref: '#/components/schemas/PageProductDto'
+ /product/v1/title/{title}:
get:
parameters:
- name: title
@@ -246,10 +58,8 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ProductDto'
- /products/{id}:
+ /product/v1/{id}:
get:
- description: Returns Product with given id
- operationId: getProductById
parameters:
- name: id
in: path
@@ -264,12 +74,7 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ProductDto'
- "404":
- description: Product not found
- "500": {}
delete:
- description: Deletes the Product with given id
- operationId: deleteProductById
parameters:
- name: id
in: path
@@ -280,18 +85,21 @@ paths:
responses:
"200":
description: OK
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/ProductDto'
- "404":
- description: Product not found
- "500": {}
components:
schemas:
- NewProductDto:
+ PageProductDto:
+ type: array
+ items:
+ $ref: '#/components/schemas/ProductDto'
+ ProductDto:
type: object
properties:
+ id:
+ format: int64
+ type: integer
+ modificationCounter:
+ format: int32
+ type: integer
description:
description: Product description
maxLength: 500
@@ -306,38 +114,31 @@ components:
minLength: 3
type: string
nullable: false
- PageImplProductDto:
- type: array
- items:
- $ref: '#/components/schemas/ProductDto'
- PagedProductResponse:
+ ProductSearchCriteriaDto:
type: object
properties:
- number:
+ determineTotal:
+ description: determine total
+ type: boolean
+ pageNumber:
format: int32
+ description: Page Number
+ default: "0"
type: integer
- size:
+ pageSize:
format: int32
- type: integer
- stream:
- type: array
- items:
- $ref: '#/components/schemas/ProductDto'
- totalElements:
- format: int64
- type: integer
- totalPages:
- format: int64
- type: integer
- ProductDto:
- type: object
- properties:
- description:
- type: string
- id:
- format: int64
+ description: Page Size
+ default: "10"
type: integer
price:
+ description: Product price
+ type: number
+ priceMax:
+ description: Product Max price
+ type: number
+ priceMin:
+ description: Product Min price
type: number
title:
+ description: Product title
type: string
\ No newline at end of file
diff --git a/src/test/java/com/devonfw/quarkus/ordermanagement/rest/v1/OrderRestServiceTest.java b/src/test/java/com/devonfw/quarkus/ordermanagement/rest/v1/OrderRestServiceTest.java
index 31ea83d..8da2998 100644
--- a/src/test/java/com/devonfw/quarkus/ordermanagement/rest/v1/OrderRestServiceTest.java
+++ b/src/test/java/com/devonfw/quarkus/ordermanagement/rest/v1/OrderRestServiceTest.java
@@ -11,40 +11,67 @@
import java.util.List;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.inject.RestClient;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestInstance.Lifecycle;
+import org.junit.jupiter.api.TestMethodOrder;
import org.mockito.Mockito;
import org.springframework.data.domain.PageRequest;
-import org.tkit.quarkus.test.WithDBData;
-import org.tkit.quarkus.test.docker.DockerComposeTestResource;
-import com.devonfw.quarkus.general.restclient.product.ProductsRestClient;
-import com.devonfw.quarkus.general.restclient.product.models.ProductDto;
import com.devonfw.quarkus.ordermanagement.rest.v1.model.NewOrderDto;
import com.devonfw.quarkus.ordermanagement.rest.v1.model.OrderSearchCriteriaDto;
+import com.devonfw.quarkus.ordermanagement.restclient.product.ProductRestClient;
+import com.devonfw.quarkus.ordermanagement.restclient.product.models.ProductDto;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectMock;
+import io.restassured.response.Response;
-/**
- * Before you run this test, tkit-test extension starts docker containers from resources/docker-compose.yaml. We get a
- * real postgresdb for our tests which will be stopped after tests. No manual test setup is needed.
- */
@QuarkusTest
-@QuarkusTestResource(DockerComposeTestResource.class)
+@QuarkusTestResource(PostgresResource.class)
+@TestMethodOrder(OrderAnnotation.class)
+@TestInstance(Lifecycle.PER_CLASS)
public class OrderRestServiceTest {
private static String BASE_PATH = "/ordermanagement/v1/order";
@InjectMock
@RestClient
- private ProductsRestClient productsRestClient;
+ private ProductRestClient productRestClient;
+
+ @BeforeAll
+ private void setup() {
+
+ mockRestClient();
+ }
+
+ @Test
+ @Order(1)
+ public void createNewOrder() {
+
+ NewOrderDto order = new NewOrderDto();
+ order.setPaymentDate(Instant.now());
+ order.setOrderedProductIds(Arrays.asList(10L, 20L));
+
+ given().when().body(order).contentType(MediaType.APPLICATION_JSON).post(BASE_PATH).then().statusCode(204);
+
+ // get items of created order
+ Response response_items = given().when().contentType(MediaType.APPLICATION_JSON).get(BASE_PATH + "/item/1").then()
+ .statusCode(200).extract().response();
+ List> items = response_items.jsonPath().getList("content");
+ assertEquals(items.size(), 2);
+ assertEquals(items.get(0).get("title"), "new product 1");
+ assertEquals(items.get(1).get("title"), "new product 2");
+ }
@Test
- @WithDBData(value = { "data/order.xls" }, deleteBeforeInsert = true, deleteAfterTest = true)
+ @Order(2)
public void getOrderByCriteria() {
OrderSearchCriteriaDto cto = new OrderSearchCriteriaDto();
@@ -52,27 +79,28 @@ public void getOrderByCriteria() {
cto.setPriceMax(BigDecimal.valueOf(100));
cto.setPageable(PageRequest.of(0, 10));
- given().when().contentType(MediaType.APPLICATION_JSON).body(cto).post(BASE_PATH + "/search").then().statusCode(200)
- .body("totalElements", equalTo(2));
+ io.restassured.response.Response r = given().when().contentType(MediaType.APPLICATION_JSON).body(cto)
+ .post(BASE_PATH + "/search");
+
+ r.then().statusCode(200).body("totalElements", equalTo(1));
cto.setPriceMax(BigDecimal.valueOf(20));
given().when().contentType(MediaType.APPLICATION_JSON).body(cto).post(BASE_PATH + "/search").then().statusCode(200)
- .body("totalElements", equalTo(1));
+ .body("totalElements", equalTo(0));
}
@Test
- @WithDBData(value = { "data/order.xls" }, deleteBeforeInsert = true, deleteAfterTest = true)
+ @Order(3)
public void getOrderById() {
given().when().contentType(MediaType.APPLICATION_JSON).get(BASE_PATH + "/1").then().statusCode(200)
- .body("price", equalTo(38.5F)).body("status", equalTo("OPEN"));
+ .body("price", equalTo(28.5F)).body("status", equalTo("OPEN"));
- given().when().contentType(MediaType.APPLICATION_JSON).get(BASE_PATH + "/2").then().statusCode(200)
- .body("price", equalTo(10.0F)).body("status", equalTo("OPEN"));
+ given().when().contentType(MediaType.APPLICATION_JSON).get(BASE_PATH + "/2").then().statusCode(204);
}
@Test
- @WithDBData(value = { "data/order.xls" }, deleteBeforeInsert = true, deleteAfterTest = true)
+ @Order(4)
public void editOrder() {
given().when().contentType(MediaType.APPLICATION_JSON).put(BASE_PATH + "/edit-status/1/paid").then()
@@ -86,30 +114,12 @@ public void editOrder() {
}
@Test
- public void createNewOrder() {
-
- mockRestClient();
+ @Order(5)
+ public void deleteOrder() {
- NewOrderDto order = new NewOrderDto();
- order.setPaymentDate(Instant.now());
- order.setOrderedProductIds(Arrays.asList(10L, 20L));
-
- given().when().body(order).contentType(MediaType.APPLICATION_JSON).post(BASE_PATH).then().statusCode(204);
-
- // re-get the created order
- given().when().contentType(MediaType.APPLICATION_JSON).get(BASE_PATH + "/1").then().statusCode(200).body("price",
- equalTo(28.5F));
-
- // get items of created order
- io.restassured.response.Response response_items = given().when().contentType(MediaType.APPLICATION_JSON)
- .get(BASE_PATH + "/item/1").then().statusCode(200).extract().response();
- List> items = response_items.jsonPath().getList("content");
- assertEquals(items.size(), 2);
- assertEquals(items.get(0).get("title"), "new product 1");
- assertEquals(items.get(1).get("title"), "new product 2");
-
- // deleting created order to reset db state
given().when().contentType(MediaType.APPLICATION_JSON).delete(BASE_PATH + "/1").then().statusCode(204);
+
+ given().when().contentType(MediaType.APPLICATION_JSON).get(BASE_PATH + "/1").then().statusCode(204);
}
private void mockRestClient() {
@@ -126,7 +136,7 @@ private void mockRestClient() {
product_2.setTitle("new product 2");
product_2.setDescription("description of product 2");
- Mockito.when(this.productsRestClient.getProductById("10")).thenReturn(Response.ok().entity(product_1).build());
- Mockito.when(this.productsRestClient.getProductById("20")).thenReturn(Response.ok().entity(product_2).build());
+ Mockito.when(this.productRestClient.productV1IdGet("10")).thenReturn(product_1);
+ Mockito.when(this.productRestClient.productV1IdGet("20")).thenReturn(product_2);
}
}
diff --git a/src/test/java/com/devonfw/quarkus/ordermanagement/rest/v1/PostgresResource.java b/src/test/java/com/devonfw/quarkus/ordermanagement/rest/v1/PostgresResource.java
new file mode 100644
index 0000000..20853a5
--- /dev/null
+++ b/src/test/java/com/devonfw/quarkus/ordermanagement/rest/v1/PostgresResource.java
@@ -0,0 +1,27 @@
+package com.devonfw.quarkus.ordermanagement.rest.v1;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.testcontainers.containers.PostgreSQLContainer;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+
+public class PostgresResource implements QuarkusTestResourceLifecycleManager {
+
+ static PostgreSQLContainer> database = new PostgreSQLContainer<>("postgres:11.5").withDatabaseName("demo_db")
+ .withUsername("demo").withPassword("demo");
+
+ @Override
+ public Map start() {
+
+ database.start();
+ return Collections.singletonMap("quarkus.datasource.url", database.getJdbcUrl());
+ }
+
+ @Override
+ public void stop() {
+
+ database.stop();
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/data/order.xls b/src/test/resources/data/order.xls
deleted file mode 100644
index 229536f..0000000
Binary files a/src/test/resources/data/order.xls and /dev/null differ
diff --git a/src/test/resources/docker-compose.yml b/src/test/resources/docker-compose.yml
deleted file mode 100644
index f6c41fc..0000000
--- a/src/test/resources/docker-compose.yml
+++ /dev/null
@@ -1,31 +0,0 @@
-version: '3.9'
-services:
- demo-db:
- container_name: demo-db
- image: postgres:latest
- environment:
- POSTGRES_DB: "demo"
- POSTGRES_USER: "demo"
- POSTGRES_PASSWORD: "demo"
- POSTGRES_HOST_AUTH_METHOD: trust
- labels:
- - "test.priority=90"
- - "test.Wait.forLogMessage.regex=.*database system is ready to accept connections.*\\s"
- - "test.Wait.forLogMessage.times=2"
- - "test.log=true"
- # we can modify Quarkus test profile apps using labels in form `test.property.`
- - "test.property.quarkus.datasource.jdbc.url=jdbc:postgresql://$${host:demo-db}:$${port:demo-db:5432}/demo?sslmode=disable"
- # simple DB import app, that allows import of data from Excel files
- dbimport:
- container_name: dbimport
- image: quay.io/tkit/dbimport:master
- environment:
- DB_URL: "jdbc:postgresql://demo-db:5432/demo?sslmode=disable"
- DB_USERNAME: "demo"
- DB_PASSWORD: "demo"
- labels:
- - "test.Wait.forLogMessage.regex=.*Installed features:.*"
- - "test.Wait.forLogMessage.times=1"
- - "test.log=true"
- - "test.property.tkit.test.dbimport.url=$${url:dbimport:8080}"
-