-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODFQMMGR-391:Add endpoint to get latest query version
- Loading branch information
Showing
3 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/java/org/folio/fqm/resource/MigrationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer> getQueryVersion() { | ||
return new ResponseEntity<>(migrationService.getLatestVersion(), HttpStatus.OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/test/java/org/folio/fqm/controller/MigrationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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))); | ||
} | ||
} |