Skip to content

Commit

Permalink
MODFQMMGR-391:Add endpoint to get latest query version
Browse files Browse the repository at this point in the history
  • Loading branch information
kjain110 committed Jul 17, 2024
1 parent 602e2ee commit e582890
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/main/java/org/folio/fqm/resource/MigrationController.java
Original file line number Diff line number Diff line change
@@ -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<String> getQueryVersion() {
return new ResponseEntity<>(migrationService.getLatestVersion(), HttpStatus.OK);
}
}
7 changes: 6 additions & 1 deletion src/main/java/org/folio/fqm/service/MigrationService.java
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down
18 changes: 17 additions & 1 deletion src/main/resources/swagger.api/mod-fqm-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit e582890

Please sign in to comment.