diff --git a/inventory-service/pom.xml b/inventory-service/pom.xml index b8b28787..38c2f845 100644 --- a/inventory-service/pom.xml +++ b/inventory-service/pom.xml @@ -20,7 +20,7 @@ UTF-8 21 - 2023.0.0-M2 + 2023.0.0-RC1 2.2.0 1.5.5.Final @@ -276,7 +276,7 @@ POSTGRES - postgres:16.0-alpine + postgres:16.1-alpine test test test diff --git a/inventory-service/src/main/java/com/example/inventoryservice/entities/Inventory.java b/inventory-service/src/main/java/com/example/inventoryservice/entities/Inventory.java index f7da0804..1ee07856 100644 --- a/inventory-service/src/main/java/com/example/inventoryservice/entities/Inventory.java +++ b/inventory-service/src/main/java/com/example/inventoryservice/entities/Inventory.java @@ -15,12 +15,10 @@ Licensed under MIT License Copyright (c) 2021-2022 Raja Kolli. import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Entity @Table(name = "inventory") @Getter -@Setter @NoArgsConstructor @AllArgsConstructor public class Inventory { @@ -37,4 +35,24 @@ public class Inventory { @Column(name = "reserved_items") private Integer reservedItems = 0; + + public Inventory setId(Long id) { + this.id = id; + return this; + } + + public Inventory setProductCode(String productCode) { + this.productCode = productCode; + return this; + } + + public Inventory setAvailableQuantity(Integer availableQuantity) { + this.availableQuantity = availableQuantity; + return this; + } + + public Inventory setReservedItems(Integer reservedItems) { + this.reservedItems = reservedItems; + return this; + } } diff --git a/inventory-service/src/test/java/com/example/inventoryservice/TestInventoryApplication.java b/inventory-service/src/test/java/com/example/inventoryservice/TestInventoryApplication.java index 1904a480..5e5841f4 100644 --- a/inventory-service/src/test/java/com/example/inventoryservice/TestInventoryApplication.java +++ b/inventory-service/src/test/java/com/example/inventoryservice/TestInventoryApplication.java @@ -6,25 +6,20 @@ Licensed under MIT License Copyright (c) 2023 Raja Kolli. package com.example.inventoryservice; +import com.example.inventoryservice.common.ContainersConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.KafkaContainer; -import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.utility.DockerImageName; @TestConfiguration(proxyBeanMethods = false) +@Import(ContainersConfig.class) public class TestInventoryApplication { - @Bean - @ServiceConnection - PostgreSQLContainer postgreSQLContainer() { - return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("16.0-alpine")) - .withReuse(true); - } - @Bean @ServiceConnection(name = "openzipkin/zipkin") GenericContainer zipkContainer() { @@ -36,7 +31,7 @@ GenericContainer zipkContainer() { @Bean @ServiceConnection KafkaContainer kafkaContainer() { - return new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag("7.5.1")) + return new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag("7.5.2")) .withKraft() .withReuse(true); } diff --git a/inventory-service/src/test/java/com/example/inventoryservice/common/ContainersConfig.java b/inventory-service/src/test/java/com/example/inventoryservice/common/ContainersConfig.java new file mode 100644 index 00000000..a3497916 --- /dev/null +++ b/inventory-service/src/test/java/com/example/inventoryservice/common/ContainersConfig.java @@ -0,0 +1,24 @@ +/*** +

+ Licensed under MIT License Copyright (c) 2023 Raja Kolli. +

+***/ + +package com.example.inventoryservice.common; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.utility.DockerImageName; + +@TestConfiguration(proxyBeanMethods = false) +public class ContainersConfig { + + @Bean + @ServiceConnection + PostgreSQLContainer postgreSQLContainer() { + return new PostgreSQLContainer<>(DockerImageName.parse("postgres:16.1-alpine")) + .withReuse(true); + } +} diff --git a/inventory-service/src/test/java/com/example/inventoryservice/repositories/InventoryRepositoryTest.java b/inventory-service/src/test/java/com/example/inventoryservice/repositories/InventoryRepositoryTest.java index c71aa8cb..9d297177 100644 --- a/inventory-service/src/test/java/com/example/inventoryservice/repositories/InventoryRepositoryTest.java +++ b/inventory-service/src/test/java/com/example/inventoryservice/repositories/InventoryRepositoryTest.java @@ -8,18 +8,20 @@ Licensed under MIT License Copyright (c) 2023 Raja Kolli. import static org.assertj.core.api.Assertions.assertThat; +import com.example.inventoryservice.common.ContainersConfig; import com.zaxxer.hikari.HikariDataSource; import javax.sql.DataSource; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; @DataJpaTest( properties = { "spring.jpa.hibernate.ddl-auto=validate", - "spring.test.database.replace=none", - "spring.datasource.url=jdbc:tc:postgresql:16.0-alpine:///databasename" + "spring.test.database.replace=none" }) +@Import(ContainersConfig.class) class InventoryRepositoryTest { @Autowired private DataSource datasource;