Skip to content

Commit

Permalink
feat : Upgrade to Spring Boot 3.4 (#871)
Browse files Browse the repository at this point in the history
* feat : Upgrade to Spring Boot 3.4

* improvise

* polish test case

* feat : apply missing changes

* merge into main

* remove duplicate file

* fix order
  • Loading branch information
rajadilipkolli authored Nov 18, 2024
1 parent dd6378f commit 9b7191a
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 20 deletions.
8 changes: 4 additions & 4 deletions inventory-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0-RC1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.inventoryservice</groupId>
Expand All @@ -20,8 +20,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>21</java.version>
<spring-cloud.version>2023.0.3</spring-cloud.version>
<springdoc-openapi.version>2.6.0</springdoc-openapi.version>
<spring-cloud.version>2024.0.0-RC1</spring-cloud.version>
<springdoc-openapi.version>2.7.0-RC1</springdoc-openapi.version>

<org.mapstruct.version>1.6.3</org.mapstruct.version>
<testcontainers-jooq-codegen-maven-plugin.version>0.0.4</testcontainers-jooq-codegen-maven-plugin.version>
Expand Down Expand Up @@ -534,7 +534,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<version>1.24.0</version>
<style>AOSP</style>
</googleJavaFormat>
<licenseHeader> <!-- specify either content or file, but not both -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,5 @@ Licensed under MIT License Copyright (c) 2021-2024 Raja Kolli.

import com.example.inventoryservice.entities.Inventory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Transactional;

public interface InventoryRepository extends JpaRepository<Inventory, Long> {
@Modifying
@Transactional
void deleteByProductCode(String productCode);
}
public interface InventoryRepository extends JpaRepository<Inventory, Long> {}
5 changes: 5 additions & 0 deletions inventory-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ spring:
threads:
virtual:
enabled: true
http:
client:
factory: jdk
main:
web-application-type: servlet
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ Licensed under MIT License Copyright (c) 2023-2024 Raja Kolli.

import com.example.inventoryservice.common.SQLContainersConfig;
import com.example.inventoryservice.config.NonSQLContainersConfig;
import com.example.inventoryservice.utils.AppConstants;
import org.springframework.boot.SpringApplication;

public class TestInventoryApplication {

public static void main(String[] args) {
System.setProperty("spring.profiles.active", "test");
SpringApplication.from(InventoryServiceApplication::main)
.with(NonSQLContainersConfig.class, SQLContainersConfig.class)
.withAdditionalProfiles(AppConstants.PROFILE_TEST)
.run(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Licensed under MIT License Copyright (c) 2021-2024 Raja Kolli.

import com.example.inventoryservice.config.NonSQLContainersConfig;
import com.example.inventoryservice.config.TestStockOrderListenerConfig;
import com.example.inventoryservice.repositories.InventoryJOOQRepository;
import com.example.inventoryservice.repositories.InventoryRepository;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -37,6 +38,8 @@ public abstract class AbstractIntegrationTest {

@Autowired protected KafkaTemplate<Long, Object> kafkaTemplate;

@Autowired protected InventoryJOOQRepository inventoryJOOQRepository;

@Autowired protected InventoryRepository inventoryRepository;

@Autowired protected TestStockOrderListenerConfig stockOrderListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class KafkaListenerConfigIntTest extends AbstractIntegrationTest {

@Test
void onNewOrderEvent() {
inventoryRepository.deleteByProductCode("JUNIT_000");
inventoryJOOQRepository.deleteByProductCode("JUNIT_000");
// Create inventory ensuring quantity is available
Inventory inventory =
inventoryRepository.save(
Expand All @@ -34,7 +34,7 @@ void onNewOrderEvent() {
await().untilAsserted(
() -> {
Optional<Inventory> optionalInventory =
inventoryRepository.findById(inventory.getId());
inventoryJOOQRepository.findById(inventory.getId());
assertThat(optionalInventory).isPresent();
Inventory inventoryFromDB = optionalInventory.get();
assertThat(inventoryFromDB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ Licensed under MIT License Copyright (c) 2024 Raja Kolli.

package com.example.inventoryservice.config;

import java.time.Duration;
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.GenericContainer;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.kafka.KafkaContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
Expand All @@ -21,14 +23,16 @@ public class NonSQLContainersConfig {
GenericContainer<?> zipkContainer() {
return new GenericContainer<>(DockerImageName.parse("openzipkin/zipkin"))
.withExposedPorts(9411)
.withReuse(true);
.withReuse(true)
.waitingFor(Wait.forHttp("/health").forPort(9411))
.withStartupTimeout(Duration.ofMinutes(2))
.withStartupAttempts(3);
}

@Bean
@ServiceConnection
KafkaContainer kafkaContainer() {
return new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag("7.7.1"))
.withKraft()
return new KafkaContainer(DockerImageName.parse("apache/kafka-native").withTag("3.8.1"))
.withReuse(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ Licensed under MIT License Copyright (c) 2023 Raja Kolli.
import javax.sql.DataSource;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
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.cloud.config.enabled=false"
})
@Import(SQLContainersConfig.class)
@AutoConfigureTestDatabase
class InventoryRepositoryTest {

@Autowired private DataSource datasource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ Licensed under MIT License Copyright (c) 2023 Raja Kolli.
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.context.annotation.Import;

@JooqTest(properties = {"spring.test.database.replace=none", "spring.cloud.config.enabled=false"})
@JooqTest(properties = {"spring.cloud.config.enabled=false"})
@Import(SQLContainersConfig.class)
@AutoConfigureTestDatabase
class JOOQInventoryRepositoryTest {

@Autowired private DSLContext dslContext;
Expand Down

0 comments on commit 9b7191a

Please sign in to comment.