From 4e3564329a008cd5807661edd7b5e8fec3d39934 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Thu, 19 Dec 2024 23:58:51 +0530 Subject: [PATCH] feat : adds IntegrationTest for JobInvoker (#1585) * feat : adds IntegrationTest for JobInvoker * adds more tests --- batch-boot-jpa-sample/pom.xml | 2 +- .../common/AbstractIntegrationTest.java | 3 ++ .../web/controllers/CustomerControllerIT.java | 2 +- .../controllers/JobInvokerControllerIT.java | 30 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/JobInvokerControllerIT.java diff --git a/batch-boot-jpa-sample/pom.xml b/batch-boot-jpa-sample/pom.xml index 1f7bb3eae..61ec4c20a 100644 --- a/batch-boot-jpa-sample/pom.xml +++ b/batch-boot-jpa-sample/pom.xml @@ -243,7 +243,7 @@ - 1.25.0 + 1.25.2 diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/common/AbstractIntegrationTest.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/common/AbstractIntegrationTest.java index e6e8eafd6..474a6c5d2 100644 --- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/common/AbstractIntegrationTest.java +++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/common/AbstractIntegrationTest.java @@ -9,6 +9,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.assertj.MockMvcTester; @ActiveProfiles({PROFILE_TEST}) @SpringBootTest( @@ -19,5 +20,7 @@ public abstract class AbstractIntegrationTest { @Autowired protected MockMvc mockMvc; + @Autowired protected MockMvcTester mockMvcTester; + @Autowired protected ObjectMapper objectMapper; } diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerIT.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerIT.java index 4d90dfb0d..fd0b6c982 100644 --- a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerIT.java +++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/CustomerControllerIT.java @@ -85,7 +85,7 @@ void shouldCreateNewCustomer() throws Exception { } @Test - void shouldReturn400WhenCreateNewCustomerWithoutText() throws Exception { + void shouldReturn400WhenCreateNewCustomerWithoutName() throws Exception { Customer customer = new Customer(null, null, null, null); this.mockMvc diff --git a/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/JobInvokerControllerIT.java b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/JobInvokerControllerIT.java new file mode 100644 index 000000000..4c9242e9f --- /dev/null +++ b/batch-boot-jpa-sample/src/test/java/com/example/bootbatchjpa/web/controllers/JobInvokerControllerIT.java @@ -0,0 +1,30 @@ +package com.example.bootbatchjpa.web.controllers; + +import com.example.bootbatchjpa.common.AbstractIntegrationTest; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; + +class JobInvokerControllerIT extends AbstractIntegrationTest { + + @Test + void shouldInvokeAllCustomersJob() { + mockMvcTester + .get() + .uri("/api/job/customers") + .param("minId", "0") + .param("maxId", "100") + .assertThat() + .hasStatusOk() + .hasContentType("text/plain;charset=UTF-8") + .hasBodyTextEqualTo("Batch job has been invoked as 1"); + } + + @Test + void shouldReturnBadRequestForMissingParameters() { + mockMvcTester + .get() + .uri("/api/job/customers") + .assertThat() + .hasStatus(HttpStatus.BAD_REQUEST); + } +}