From 0f55f7a7a99585daff57e9db9aab1c598c1f61df Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Thu, 12 Dec 2024 12:01:45 +0000 Subject: [PATCH] Upgrade to spring boot 3.4.0 and polish --- boot-togglz-sample/pom.xml | 6 +++--- .../{Application.java => TogglzApplication.java} | 4 ++-- .../featuretoggle/ApplicationIntegrationTest.java | 2 +- .../example/featuretoggle/TestTogglzApplication.java | 11 +++++++++++ .../featuretoggle/common/AbstractIntegrationTest.java | 3 +-- .../ContainerConfig.java} | 11 +++-------- .../web/controllers/CustomerControllerTest.java | 4 ++-- 7 files changed, 23 insertions(+), 18 deletions(-) rename boot-togglz-sample/src/main/java/com/example/featuretoggle/{Application.java => TogglzApplication.java} (82%) create mode 100644 boot-togglz-sample/src/test/java/com/example/featuretoggle/TestTogglzApplication.java rename boot-togglz-sample/src/test/java/com/example/featuretoggle/{TestApplication.java => common/ContainerConfig.java} (68%) diff --git a/boot-togglz-sample/pom.xml b/boot-togglz-sample/pom.xml index 47dcbb067..f308ae5c8 100644 --- a/boot-togglz-sample/pom.xml +++ b/boot-togglz-sample/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.6 + 3.4.0 com.example.featuretoggle @@ -19,7 +19,7 @@ UTF-8 21 - 2.6.0 + 2.7.0 4.4.0 ${project.build.directory}/test-results @@ -234,7 +234,7 @@ - 1.22.0 + 1.25.0 diff --git a/boot-togglz-sample/src/main/java/com/example/featuretoggle/Application.java b/boot-togglz-sample/src/main/java/com/example/featuretoggle/TogglzApplication.java similarity index 82% rename from boot-togglz-sample/src/main/java/com/example/featuretoggle/Application.java rename to boot-togglz-sample/src/main/java/com/example/featuretoggle/TogglzApplication.java index 36cc21ae6..9880c05ce 100644 --- a/boot-togglz-sample/src/main/java/com/example/featuretoggle/Application.java +++ b/boot-togglz-sample/src/main/java/com/example/featuretoggle/TogglzApplication.java @@ -7,9 +7,9 @@ @SpringBootApplication @EnableConfigurationProperties({ApplicationProperties.class}) -public class Application { +public class TogglzApplication { public static void main(String[] args) { - SpringApplication.run(Application.class, args); + SpringApplication.run(TogglzApplication.class, args); } } diff --git a/boot-togglz-sample/src/test/java/com/example/featuretoggle/ApplicationIntegrationTest.java b/boot-togglz-sample/src/test/java/com/example/featuretoggle/ApplicationIntegrationTest.java index 85e6d43f4..24193b803 100644 --- a/boot-togglz-sample/src/test/java/com/example/featuretoggle/ApplicationIntegrationTest.java +++ b/boot-togglz-sample/src/test/java/com/example/featuretoggle/ApplicationIntegrationTest.java @@ -22,7 +22,7 @@ class ApplicationIntegrationTest extends AbstractIntegrationTest { @Test void shouldFindCustomerByIdWithEmptyData() throws Exception { - Customer customer = new Customer(101L, "New Customer", "name 1", 1); + Customer customer = new Customer(null, "New Customer", "name 1", 1); this.mockMvc .perform( post("/api/customers") diff --git a/boot-togglz-sample/src/test/java/com/example/featuretoggle/TestTogglzApplication.java b/boot-togglz-sample/src/test/java/com/example/featuretoggle/TestTogglzApplication.java new file mode 100644 index 000000000..79adbd327 --- /dev/null +++ b/boot-togglz-sample/src/test/java/com/example/featuretoggle/TestTogglzApplication.java @@ -0,0 +1,11 @@ +package com.example.featuretoggle; + +import com.example.featuretoggle.common.ContainerConfig; +import org.springframework.boot.SpringApplication; + +public class TestTogglzApplication { + + public static void main(String[] args) { + SpringApplication.from(TogglzApplication::main).with(ContainerConfig.class).run(args); + } +} diff --git a/boot-togglz-sample/src/test/java/com/example/featuretoggle/common/AbstractIntegrationTest.java b/boot-togglz-sample/src/test/java/com/example/featuretoggle/common/AbstractIntegrationTest.java index 407c040cd..a5149f861 100644 --- a/boot-togglz-sample/src/test/java/com/example/featuretoggle/common/AbstractIntegrationTest.java +++ b/boot-togglz-sample/src/test/java/com/example/featuretoggle/common/AbstractIntegrationTest.java @@ -3,7 +3,6 @@ import static com.example.featuretoggle.utils.AppConstants.PROFILE_TEST; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -import com.example.featuretoggle.TestApplication; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -12,7 +11,7 @@ import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({PROFILE_TEST}) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = TestApplication.class) +@SpringBootTest(webEnvironment = RANDOM_PORT, classes = ContainerConfig.class) @AutoConfigureMockMvc public abstract class AbstractIntegrationTest { diff --git a/boot-togglz-sample/src/test/java/com/example/featuretoggle/TestApplication.java b/boot-togglz-sample/src/test/java/com/example/featuretoggle/common/ContainerConfig.java similarity index 68% rename from boot-togglz-sample/src/test/java/com/example/featuretoggle/TestApplication.java rename to boot-togglz-sample/src/test/java/com/example/featuretoggle/common/ContainerConfig.java index 170a61833..82cb627d2 100644 --- a/boot-togglz-sample/src/test/java/com/example/featuretoggle/TestApplication.java +++ b/boot-togglz-sample/src/test/java/com/example/featuretoggle/common/ContainerConfig.java @@ -1,6 +1,5 @@ -package com.example.featuretoggle; +package com.example.featuretoggle.common; -import org.springframework.boot.SpringApplication; import org.springframework.boot.devtools.restart.RestartScope; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; @@ -9,16 +8,12 @@ import org.testcontainers.utility.DockerImageName; @TestConfiguration(proxyBeanMethods = false) -public class TestApplication { +public class ContainerConfig { @Bean @ServiceConnection @RestartScope MySQLContainer sqlContainer() { - return new MySQLContainer<>(DockerImageName.parse("mysql:9.0")); - } - - public static void main(String[] args) { - SpringApplication.from(Application::main).with(TestApplication.class).run(args); + return new MySQLContainer<>(DockerImageName.parse("mysql:9.1")); } } diff --git a/boot-togglz-sample/src/test/java/com/example/featuretoggle/web/controllers/CustomerControllerTest.java b/boot-togglz-sample/src/test/java/com/example/featuretoggle/web/controllers/CustomerControllerTest.java index 8eb039dd6..0d5516d16 100644 --- a/boot-togglz-sample/src/test/java/com/example/featuretoggle/web/controllers/CustomerControllerTest.java +++ b/boot-togglz-sample/src/test/java/com/example/featuretoggle/web/controllers/CustomerControllerTest.java @@ -25,9 +25,9 @@ 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.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; @WebMvcTest(controllers = CustomerController.class) @@ -36,7 +36,7 @@ class CustomerControllerTest { @Autowired private MockMvc mockMvc; - @MockBean private CustomerService customerService; + @MockitoBean private CustomerService customerService; @Autowired private ObjectMapper objectMapper;