Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : upgrade to spring boot 3.4.0-RC1 #1481

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jpa/boot-data-multipledatasources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<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</groupId>
<artifactId>boot-data-multipledatasources</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>multipledatasources</name>
<name>boot-data-multipledatasources</name>
<description>Demo project for using multiple datasource's in a Spring Boot Application</description>

<properties>
Expand Down Expand Up @@ -220,7 +220,7 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.47.0</version>
<version>2.50.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.multipledatasources.bootstrap;

import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import com.example.multipledatasources.entities.member.Member;
import com.example.multipledatasources.repository.cardholder.CardHolderRepository;
import com.example.multipledatasources.repository.member.MemberRepository;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.multipledatasources.configuration;

import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import com.example.multipledatasources.repository.cardholder.CardHolderRepository;
import com.zaxxer.hikari.HikariDataSource;
import jakarta.persistence.EntityManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.multipledatasources.configuration;

import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.member.Member;
import com.example.multipledatasources.repository.member.MemberRepository;
import com.zaxxer.hikari.HikariDataSource;
import jakarta.persistence.EntityManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.multipledatasources.model.cardholder;
package com.example.multipledatasources.entities.cardholder;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.multipledatasources.model.member;
package com.example.multipledatasources.entities.member;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.multipledatasources.repository.cardholder;

import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.multipledatasources.repository.member;

import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.member.Member;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.multipledatasources.service.impl;

import com.example.multipledatasources.dto.ResponseDto;
import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import com.example.multipledatasources.entities.member.Member;
import com.example.multipledatasources.repository.cardholder.CardHolderRepository;
import com.example.multipledatasources.repository.member.MemberRepository;
import com.example.multipledatasources.service.DetailsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,18 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.example.multipledatasources.common.ContainersConfiguration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ContainersConfiguration.class)
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved
@AutoConfigureMockMvc
@Testcontainers(disabledWithoutDocker = true, parallel = true)
class ApplicationIntegrationTest {

@Container
private static final MySQLContainer<?> MY_SQL_CONTAINER = new MySQLContainer<>("mysql:9.0");

@Container
private static final PostgreSQLContainer<?> POSTGRE_SQL_CONTAINER =
new PostgreSQLContainer<>(DockerImageName.parse("postgres:16.3-alpine"));

@DynamicPropertySource
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add("app.datasource.cardholder.url", MY_SQL_CONTAINER::getJdbcUrl);
registry.add("app.datasource.cardholder.username", MY_SQL_CONTAINER::getUsername);
registry.add("app.datasource.cardholder.password", MY_SQL_CONTAINER::getPassword);
registry.add("app.datasource.member.url", POSTGRE_SQL_CONTAINER::getJdbcUrl);
registry.add("app.datasource.member.username", POSTGRE_SQL_CONTAINER::getUsername);
registry.add("app.datasource.member.password", POSTGRE_SQL_CONTAINER::getPassword);
}

@Autowired
private MockMvc mockMvc;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
package com.example.multipledatasources;

import com.example.multipledatasources.common.ContainersConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.TestConfiguration;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.lifecycle.Startables;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration
public class TestMultipleDataSourcesApplication {

private static final MySQLContainer<?> MY_SQL_CONTAINER =
new MySQLContainer<>(DockerImageName.parse("mysql").withTag("9.1"));

private static final PostgreSQLContainer<?> POSTGRE_SQL_CONTAINER =
new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.0-alpine"));

static {
Startables.deepStart(MY_SQL_CONTAINER, POSTGRE_SQL_CONTAINER).join();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
MY_SQL_CONTAINER.stop();
POSTGRE_SQL_CONTAINER.stop();
}));
}
class TestMultipleDataSourcesApplication {

public static void main(String[] args) {
System.setProperty("app.datasource.cardholder.url", MY_SQL_CONTAINER.getJdbcUrl());
System.setProperty("app.datasource.cardholder.username", MY_SQL_CONTAINER.getUsername());
System.setProperty("app.datasource.cardholder.password", MY_SQL_CONTAINER.getPassword());
System.setProperty("app.datasource.member.url", POSTGRE_SQL_CONTAINER.getJdbcUrl());
System.setProperty("app.datasource.member.username", POSTGRE_SQL_CONTAINER.getUsername());
System.setProperty("app.datasource.member.password", POSTGRE_SQL_CONTAINER.getPassword());
SpringApplication.from(MultipleDataSourcesApplication::main)
.with(TestMultipleDataSourcesApplication.class)
.with(ContainersConfiguration.class)
.run(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.example.multipledatasources.common;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistrar;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class ContainersConfiguration {

@Bean
MySQLContainer<?> mySQLContainer() {
MySQLContainer<?> mysql =
new MySQLContainer<>(DockerImageName.parse("mysql").withTag("9.1"));
mysql.start();
return mysql;
}
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved

@Bean
PostgreSQLContainer<?> postgreSQLContainer() {
PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.0-alpine"));
postgres.start();
return postgres;
}
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved

@Bean
public DynamicPropertyRegistrar kafkaProperties(
MySQLContainer<?> mySQLContainer, PostgreSQLContainer<?> postgreSQLContainer) {
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
mySQLContainer.stop();
postgreSQLContainer.stop();
}));
return (properties) -> {
// Connect our Spring application to our Testcontainers instances
properties.add("app.datasource.cardholder.url", mySQLContainer::getJdbcUrl);
properties.add("app.datasource.cardholder.username", mySQLContainer::getUsername);
properties.add("app.datasource.cardholder.password", mySQLContainer::getPassword);
properties.add("app.datasource.member.url", postgreSQLContainer::getJdbcUrl);
properties.add("app.datasource.member.username", postgreSQLContainer::getUsername);
properties.add("app.datasource.member.password", postgreSQLContainer::getPassword);
};
}
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(controllers = DetailsController.class)
Expand All @@ -20,7 +20,7 @@ class DetailsControllerTest {
@Autowired
private MockMvc mockMvc;

@MockBean
@MockitoBean
private DetailsService detailsService;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static org.mockito.BDDMockito.given;

import com.example.multipledatasources.dto.ResponseDto;
import com.example.multipledatasources.model.cardholder.CardHolder;
import com.example.multipledatasources.model.member.Member;
import com.example.multipledatasources.entities.cardholder.CardHolder;
import com.example.multipledatasources.entities.member.Member;
import com.example.multipledatasources.repository.cardholder.CardHolderRepository;
import com.example.multipledatasources.repository.member.MemberRepository;
import java.util.Optional;
Expand Down