From e868ef88202a988143e3b5d1d8f79db5c46b37fa Mon Sep 17 00:00:00 2001 From: Kriti Jain Date: Tue, 16 Jul 2024 14:44:27 -0400 Subject: [PATCH] re --- .../fqm/resource/MigrationController.java | 17 ++++++++ .../swagger.api/mod-fqm-manager.yaml | 2 +- .../controller/MigrationControllerTest.java | 39 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/folio/fqm/resource/MigrationController.java create mode 100644 src/test/java/org/folio/fqm/controller/MigrationControllerTest.java diff --git a/src/main/java/org/folio/fqm/resource/MigrationController.java b/src/main/java/org/folio/fqm/resource/MigrationController.java new file mode 100644 index 000000000..48b119491 --- /dev/null +++ b/src/main/java/org/folio/fqm/resource/MigrationController.java @@ -0,0 +1,17 @@ +package org.folio.fqm.resource; + +import lombok.RequiredArgsConstructor; +import org.folio.fqm.service.MigrationService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class MigrationController implements QueryVersionApi { + private final MigrationService migrationService; + + public ResponseEntity getQueryVersion() { + return new ResponseEntity<>(migrationService.getLatestVersion(), HttpStatus.OK); + } +} diff --git a/src/main/resources/swagger.api/mod-fqm-manager.yaml b/src/main/resources/swagger.api/mod-fqm-manager.yaml index dbda61fa3..41b46f603 100644 --- a/src/main/resources/swagger.api/mod-fqm-manager.yaml +++ b/src/main/resources/swagger.api/mod-fqm-manager.yaml @@ -70,6 +70,7 @@ paths: description: Get the version of the query. responses: '200': + description: 'Version of the query' content: application/json: schema: @@ -78,7 +79,6 @@ paths: $ref: '#/components/responses/badRequestResponse' '500': $ref: '#/components/responses/internalServerErrorResponse' - components: parameters: entity-type-id: diff --git a/src/test/java/org/folio/fqm/controller/MigrationControllerTest.java b/src/test/java/org/folio/fqm/controller/MigrationControllerTest.java new file mode 100644 index 000000000..c1eb08284 --- /dev/null +++ b/src/test/java/org/folio/fqm/controller/MigrationControllerTest.java @@ -0,0 +1,39 @@ +package org.folio.fqm.controller; + +import org.folio.fqm.resource.MigrationController; +import org.folio.fqm.service.MigrationService; +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.web.servlet.MockMvc; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + + +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; + +@WebMvcTest(MigrationController.class) +public class MigrationControllerTest { + private static final String GET_VERSION_URL = "/query/migrate/version"; + @Autowired + private MockMvc mockMvc; + + @MockBean + private MigrationService migrationService; + + @Test + void shouldReturnQueryVersion() throws Exception { + when(migrationService.getLatestVersion()).thenReturn(1); + RequestBuilder builder = MockMvcRequestBuilders + .get(GET_VERSION_URL) + .accept(MediaType.APPLICATION_JSON); + mockMvc + .perform(builder) + .andExpect(status().isOk()) + .andExpect(content().string(String.valueOf(1))); + } +}