From a5cc2beda5a8ff8e4b7b8a24d6a8f2d35106e108 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Fri, 15 Nov 2024 14:29:34 +0000 Subject: [PATCH 1/2] feat : upgrade to spring boot 3.4.0-RC1 --- catalog-service/pom.xml | 15 +++---- .../TestCatalogServiceApplication.java | 42 +++--------------- .../common/AbstractIntegrationTest.java | 5 +-- .../common/ContainersConfig.java | 44 +++++++++++++++++++ .../common/SQLContainerConfig.java | 25 +++++++++++ .../controllers/ProductControllerTest.java | 6 +-- 6 files changed, 85 insertions(+), 52 deletions(-) create mode 100644 catalog-service/src/test/java/com/example/catalogservice/common/ContainersConfig.java create mode 100644 catalog-service/src/test/java/com/example/catalogservice/common/SQLContainerConfig.java diff --git a/catalog-service/pom.xml b/catalog-service/pom.xml index fe4e4c39..c13f91c0 100644 --- a/catalog-service/pom.xml +++ b/catalog-service/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.5 + 3.4.0-RC1 com.example.catalogservice @@ -20,8 +20,8 @@ UTF-8 21 - 2023.0.3 - 2.6.0 + 2024.0.0-RC1 + 2.7.0-RC1 1.6.3 @@ -90,11 +90,6 @@ - - org.glassfish.jaxb - jaxb-runtime - provided - diff --git a/catalog-service/src/test/java/com/example/catalogservice/TestCatalogServiceApplication.java b/catalog-service/src/test/java/com/example/catalogservice/TestCatalogServiceApplication.java index 21186421..270073d7 100644 --- a/catalog-service/src/test/java/com/example/catalogservice/TestCatalogServiceApplication.java +++ b/catalog-service/src/test/java/com/example/catalogservice/TestCatalogServiceApplication.java @@ -6,49 +6,17 @@ Licensed under MIT License Copyright (c) 2023-2024 Raja Kolli. package com.example.catalogservice; +import com.example.catalogservice.common.ContainersConfig; +import com.example.catalogservice.common.SQLContainerConfig; +import com.example.catalogservice.utils.AppConstants; 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.test.context.DynamicPropertyRegistry; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.KafkaContainer; -import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.utility.DockerImageName; -@TestConfiguration(proxyBeanMethods = false) public class TestCatalogServiceApplication { - @Bean - @ServiceConnection(name = "openzipkin/zipkin") - GenericContainer zipkinContainer() { - return new GenericContainer<>(DockerImageName.parse("openzipkin/zipkin:latest")) - .withExposedPorts(9411) - .withReuse(true); - } - - @Bean - @ServiceConnection - PostgreSQLContainer postgreSqlContainer() { - return new PostgreSQLContainer<>("postgres:17-alpine").withReuse(true); - } - - @Bean - @ServiceConnection - KafkaContainer kafkaContainer(DynamicPropertyRegistry dynamicPropertyRegistry) { - KafkaContainer kafkaContainer = - new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag("7.6.2")) - .withKraft() - .withReuse(true); - dynamicPropertyRegistry.add( - "spring.cloud.stream.kafka.binder.brokers", kafkaContainer::getBootstrapServers); - return kafkaContainer; - } - public static void main(String[] args) { - System.setProperty("spring.profiles.active", "test"); SpringApplication.from(CatalogServiceApplication::main) - .with(TestCatalogServiceApplication.class) + .with(ContainersConfig.class, SQLContainerConfig.class) + .withAdditionalProfiles(AppConstants.PROFILE_TEST) .run(args); } } diff --git a/catalog-service/src/test/java/com/example/catalogservice/common/AbstractIntegrationTest.java b/catalog-service/src/test/java/com/example/catalogservice/common/AbstractIntegrationTest.java index a452d3f1..29e241ff 100644 --- a/catalog-service/src/test/java/com/example/catalogservice/common/AbstractIntegrationTest.java +++ b/catalog-service/src/test/java/com/example/catalogservice/common/AbstractIntegrationTest.java @@ -1,6 +1,6 @@ /***

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

***/ @@ -9,7 +9,6 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. import static com.example.catalogservice.utils.AppConstants.PROFILE_TEST; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -import com.example.catalogservice.TestCatalogServiceApplication; import com.example.catalogservice.config.TestKafkaListenerConfig; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; @@ -24,7 +23,7 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. @SpringBootTest( webEnvironment = RANDOM_PORT, properties = {"spring.cloud.config.enabled=false"}, - classes = {TestCatalogServiceApplication.class, TestKafkaListenerConfig.class}) + classes = {SQLContainerConfig.class, TestKafkaListenerConfig.class, ContainersConfig.class}) @AutoConfigureWebTestClient @AutoConfigureObservability(tracing = false) public abstract class AbstractIntegrationTest { diff --git a/catalog-service/src/test/java/com/example/catalogservice/common/ContainersConfig.java b/catalog-service/src/test/java/com/example/catalogservice/common/ContainersConfig.java new file mode 100644 index 00000000..8bc057fe --- /dev/null +++ b/catalog-service/src/test/java/com/example/catalogservice/common/ContainersConfig.java @@ -0,0 +1,44 @@ +/*** +

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

+***/ + +package com.example.catalogservice.common; + +import org.springframework.boot.devtools.restart.RestartScope; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.DynamicPropertyRegistrar; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.kafka.KafkaContainer; +import org.testcontainers.utility.DockerImageName; + +@TestConfiguration(proxyBeanMethods = false) +public class ContainersConfig { + + @Bean + @ServiceConnection + @RestartScope + KafkaContainer kafkaContainer() { + return new KafkaContainer(DockerImageName.parse("apache/kafka-native").withTag("3.9.0")) + .withReuse(true); + } + + @Bean + @ServiceConnection(name = "openzipkin/zipkin") + GenericContainer zipkinContainer() { + return new GenericContainer<>(DockerImageName.parse("openzipkin/zipkin:latest")) + .withExposedPorts(9411) + .withReuse(true); + } + + @Bean + DynamicPropertyRegistrar kafkaProperties(KafkaContainer kafkaContainer) { + return props -> + props.add( + "spring.cloud.stream.kafka.binder.brokers", + kafkaContainer::getBootstrapServers); + } +} diff --git a/catalog-service/src/test/java/com/example/catalogservice/common/SQLContainerConfig.java b/catalog-service/src/test/java/com/example/catalogservice/common/SQLContainerConfig.java new file mode 100644 index 00000000..4ca63284 --- /dev/null +++ b/catalog-service/src/test/java/com/example/catalogservice/common/SQLContainerConfig.java @@ -0,0 +1,25 @@ +/*** +

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

+***/ + +package com.example.catalogservice.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 SQLContainerConfig { + + @Bean + @ServiceConnection + PostgreSQLContainer postgreSQLContainer() { + return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.1-alpine")) + .withDatabaseName("catalog-service") + .withReuse(true); + } +} diff --git a/catalog-service/src/test/java/com/example/catalogservice/web/controllers/ProductControllerTest.java b/catalog-service/src/test/java/com/example/catalogservice/web/controllers/ProductControllerTest.java index ceb7e90f..4bc81dd3 100644 --- a/catalog-service/src/test/java/com/example/catalogservice/web/controllers/ProductControllerTest.java +++ b/catalog-service/src/test/java/com/example/catalogservice/web/controllers/ProductControllerTest.java @@ -1,6 +1,6 @@ /***

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

***/ @@ -25,11 +25,11 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli. import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.reactive.server.WebTestClient; import reactor.core.publisher.Mono; @@ -39,7 +39,7 @@ class ProductControllerTest { @Autowired private WebTestClient webTestClient; - @MockBean private ProductService productService; + @MockitoBean private ProductService productService; private List productResponseList; From a3560994644c18b2f51abde8afdba793fe35d607 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Fri, 15 Nov 2024 14:31:01 +0000 Subject: [PATCH 2/2] downgrade kafka as there is an issue --- .../com/example/catalogservice/common/ContainersConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catalog-service/src/test/java/com/example/catalogservice/common/ContainersConfig.java b/catalog-service/src/test/java/com/example/catalogservice/common/ContainersConfig.java index 8bc057fe..b5043b5e 100644 --- a/catalog-service/src/test/java/com/example/catalogservice/common/ContainersConfig.java +++ b/catalog-service/src/test/java/com/example/catalogservice/common/ContainersConfig.java @@ -22,7 +22,7 @@ public class ContainersConfig { @ServiceConnection @RestartScope KafkaContainer kafkaContainer() { - return new KafkaContainer(DockerImageName.parse("apache/kafka-native").withTag("3.9.0")) + return new KafkaContainer(DockerImageName.parse("apache/kafka-native").withTag("3.8.1")) .withReuse(true); }