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..d80e0b00e --- /dev/null +++ b/src/main/java/org/folio/fqm/resource/MigrationController.java @@ -0,0 +1,18 @@ +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; + + @Override + public ResponseEntity getQueryVersion() { + return new ResponseEntity<>(migrationService.getLatestVersion(), HttpStatus.OK); + } +} diff --git a/src/main/java/org/folio/fqm/service/MigrationService.java b/src/main/java/org/folio/fqm/service/MigrationService.java index 0c7e5238f..02176d48c 100644 --- a/src/main/java/org/folio/fqm/service/MigrationService.java +++ b/src/main/java/org/folio/fqm/service/MigrationService.java @@ -1,11 +1,16 @@ package org.folio.fqm.service; import java.util.List; + +import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.NotImplementedException; +import org.springframework.stereotype.Service; +@Service +@RequiredArgsConstructor public class MigrationService { - public int getLatestVersion() { + public String getLatestVersion() { // return 1; throw new NotImplementedException(); } diff --git a/src/main/resources/swagger.api/mod-fqm-manager.yaml b/src/main/resources/swagger.api/mod-fqm-manager.yaml index b4a00e6fe..682f67c49 100644 --- a/src/main/resources/swagger.api/mod-fqm-manager.yaml +++ b/src/main/resources/swagger.api/mod-fqm-manager.yaml @@ -62,7 +62,23 @@ paths: $ref: '#/components/responses/badRequestResponse' '500': $ref: '#/components/responses/internalServerErrorResponse' - + /fqm/version: + get: + operationId: getQueryVersion + tags: + - queryVersion + description: Get the version of the fqm query. + responses: + '200': + description: 'Version of the fqm query' + content: + application/json: + schema: + type: string + '400': + $ref: '#/components/responses/badRequestResponse' + '500': + $ref: '#/components/responses/internalServerErrorResponse' components: parameters: 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..08fea91c4 --- /dev/null +++ b/src/test/java/org/folio/fqm/controller/MigrationControllerTest.java @@ -0,0 +1,44 @@ +package org.folio.fqm.controller; + +import org.folio.fqm.resource.MigrationController; +import org.folio.fqm.service.MigrationService; +import org.folio.spring.FolioExecutionContext; +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) +class MigrationControllerTest { + private static final String GET_VERSION_URL = "/fqm/version"; + @Autowired + private MockMvc mockMvc; + + @MockBean + private MigrationService migrationService; + + @MockBean + private FolioExecutionContext executionContext; + + @Test + void shouldReturnQueryVersion() throws Exception { + String tenantId = "tenant_01"; + when(executionContext.getTenantId()).thenReturn(tenantId); + 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("1")); + } +}