-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DFPL-1761 Build GET /searchCases endpoint #5495
Merged
Merged
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
64bb990
add dummy controller for API gateway POC
chak-shing-lo-justice 019df0d
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice 6026a6f
update CafcassCasesController for POC
chak-shing-lo-justice 1eb519d
update CafcassCasesController for POC
chak-shing-lo-justice 3f639b7
Update CafcassCasesController.java
chak-shing-lo-justice b308de6
Update CafcassCasesControllerTest.java
chak-shing-lo-justice 680242d
Update CafcassCasesController.java
chak-shing-lo-justice 86b59a3
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice 9c6b654
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice 1a46c87
add all endpoint for POC
chak-shing-lo-justice 8aecb85
remove unused import
chak-shing-lo-justice 9b7784c
Update CafcassCasesControllerTest.java
chak-shing-lo-justice 6fb7d74
Update CafcassCasesController.java
chak-shing-lo-justice cf02f56
Update CafcassCasesController.java
chak-shing-lo-justice 23c3f27
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice ab5edab
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice 2b2e78d
update CafcassCasesController
chak-shing-lo-justice 9008cc1
Merge branch 'DFPL-2427' of https://github.com/hmcts/fpl-ccd-configur…
chak-shing-lo-justice 98ac6c9
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice 80db602
DFPL-2449 Add interceptor and exception handling for Cafcass API (#5493)
chak-shing-lo-justice cadff7c
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice dc38342
fix unit test
chak-shing-lo-justice 93844c5
Merge branch 'DFPL-1761' of https://github.com/hmcts/fpl-ccd-configur…
chak-shing-lo-justice 1662143
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice d22da94
implement es search
chak-shing-lo-justice b252e5f
search case response object
chak-shing-lo-justice b1e7629
response field child and other
chak-shing-lo-justice 35c88ec
remove converters chain
chak-shing-lo-justice 4d0765f
other application details
chak-shing-lo-justice 301e43b
refactor to chain pattern
chak-shing-lo-justice a8dfe59
orders document and manage document
chak-shing-lo-justice cab24c8
case documents
chak-shing-lo-justice fee3ae2
fix category
chak-shing-lo-justice 6ad0f96
CafcassApiHelperTest and CafcassApiCaseServiceTest
chak-shing-lo-justice bbe80e0
applicantConverter test
chak-shing-lo-justice 3d75c95
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice bab3ad0
CafcassApiChildrenConverterTest
chak-shing-lo-justice 3bc5d2e
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice b412da4
refactor CafcassApiCaseDocumentsConverter to more FP style
chak-shing-lo-justice dada3b2
Create CafcassApiFactorsParentingConverterTest.java
chak-shing-lo-justice fdadce2
Merge branch 'DFPL-1761' of https://github.com/hmcts/fpl-ccd-configur…
chak-shing-lo-justice 555ddbf
Create CafcassApiHearingDetailsConverterTest.java
chak-shing-lo-justice fb8cf50
add CafcassApiInternationalElementConverterTest
chak-shing-lo-justice 1f5d3c6
Create CafcassApiMetaDataConverterTest.java
chak-shing-lo-justice a6b38ee
Create CafcassApiOthersConverterTest.java
chak-shing-lo-justice 10b59c4
add CafcassApiPreviousProceedingsConverterTest
chak-shing-lo-justice f47773d
refactor and add CafcassApiRespondentsConverterTest
chak-shing-lo-justice a6312ab
Create CafcassApiRisksConverterTest.java
chak-shing-lo-justice 9a564a2
add sdo and udo converter test
chak-shing-lo-justice 09e26b8
add draft oder converting test
chak-shing-lo-justice 392a1b2
refactor to service
chak-shing-lo-justice d633668
original application test
chak-shing-lo-justice e056be4
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice 4651373
add managed doc test
chak-shing-lo-justice f214c55
update controller test
chak-shing-lo-justice f54889b
fix style check
chak-shing-lo-justice 7de11a8
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice 9ea0fe8
fix unit test
chak-shing-lo-justice ae9d4b6
Merge branch 'cafcass-api' into DFPL-1761
chak-shing-lo-justice a9c0bf6
fix code check
chak-shing-lo-justice 971d01e
rename to CafcassApiSearchCaseService
chak-shing-lo-justice ecaa745
Update AmendOrderToDownloadPrePopulatorTest.java
chak-shing-lo-justice 83e399a
Update CafcassApiInterceptor.java
chak-shing-lo-justice 8dbdea8
use cafcass role until new role is set up
chak-shing-lo-justice 95f6faa
Update CafcassApiInterceptor.java
chak-shing-lo-justice 306b626
use object provider
chak-shing-lo-justice 4c7548b
remove comment
chak-shing-lo-justice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
import uk.gov.hmcts.reform.fpl.service.ccd.CoreCaseDataService; | ||
import uk.gov.hmcts.reform.fpl.testingsupport.controllers.TestingSupportController; | ||
import uk.gov.hmcts.reform.fpl.utils.ResourceReader; | ||
import uk.gov.hmcts.reform.idam.client.IdamClient; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -93,6 +94,9 @@ class TestingSupportControllerTest { | |
@MockBean | ||
private DocumentUploadClientApi uploadClient; | ||
|
||
@MockBean | ||
private IdamClient idamClient; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added this mock bean to resolve bean not found when initialising mockMVC |
||
@BeforeEach | ||
void init() { | ||
when(requestData.authorisation()).thenReturn(USER_AUTH_TOKEN); | ||
|
62 changes: 62 additions & 0 deletions
62
...onTest/java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiControllerBaseTest.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,62 @@ | ||
package uk.gov.hmcts.reform.fpl.controllers.cafcass; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.MvcResult; | ||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; | ||
import uk.gov.hmcts.reform.fpl.controllers.AbstractTest; | ||
import uk.gov.hmcts.reform.fpl.interceptors.CafcassApiInterceptor; | ||
import uk.gov.hmcts.reform.idam.client.models.UserInfo; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static uk.gov.hmcts.reform.fpl.enums.UserRole.CAFCASS_SYSTEM_UPDATE; | ||
|
||
@WebMvcTest(CafcassCasesController.class) | ||
@OverrideAutoConfiguration(enabled = true) | ||
public abstract class CafcassApiControllerBaseTest extends AbstractTest { | ||
private static final UserInfo CAFCASS_SYSTEM_UPDATE_USER_INFO = UserInfo.builder() | ||
.roles(List.of(CAFCASS_SYSTEM_UPDATE.getRoleName())) | ||
.build(); | ||
|
||
@Autowired | ||
protected MockMvc mockMvc; | ||
|
||
@MockBean | ||
private CafcassApiInterceptor cafcassApiInterceptor; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
givenCurrentUser(CAFCASS_SYSTEM_UPDATE_USER_INFO); | ||
when(cafcassApiInterceptor.preHandle(any(), any(), any())).thenReturn(true); | ||
} | ||
|
||
protected MvcResult sendRequest(MockHttpServletRequestBuilder request, int expectedStatus) throws Exception { | ||
MvcResult response = mockMvc.perform(request).andExpect(status().is(expectedStatus)).andReturn(); | ||
assertEquals(response.getResponse().getStatus(), expectedStatus); | ||
return response; | ||
} | ||
|
||
protected <T> T readResponseContent(MvcResult response, Class<T> responseType) throws IOException { | ||
return mapper.readValue(response.getResponse().getContentAsByteArray(), responseType); | ||
} | ||
|
||
protected MockHttpServletRequestBuilder buildGetRequest(String url) { | ||
return get(url).header("authorization", USER_AUTH_TOKEN); | ||
} | ||
|
||
protected MockHttpServletRequestBuilder buildPostRequest(String url) { | ||
return post(url).header("authorization", USER_AUTH_TOKEN); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
.../java/uk/gov/hmcts/reform/fpl/controllers/cafcass/CafcassApiSearchCaseControllerTest.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,82 @@ | ||
package uk.gov.hmcts.reform.fpl.controllers.cafcass; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MvcResult; | ||
import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCase; | ||
import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiCaseData; | ||
import uk.gov.hmcts.reform.fpl.model.cafcass.api.CafcassApiSearchCasesResponse; | ||
import uk.gov.hmcts.reform.fpl.service.cafcass.api.CafcassApiSearchCaseService; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class CafcassApiSearchCaseControllerTest extends CafcassApiControllerBaseTest { | ||
@MockBean | ||
private CafcassApiSearchCaseService cafcassApiSearchCaseService; | ||
|
||
@Test | ||
void searchCases() throws Exception { | ||
List<CafcassApiCase> responseCases = List.of( | ||
CafcassApiCase.builder() | ||
.caseId(1L).jurisdiction("jurisdiction").state("state").caseTypeId("caseTypeId") | ||
.createdDate(LocalDateTime.of(2023, 1, 1, 10, 0, 0)) | ||
.lastModified(LocalDateTime.of(2024, 3, 28, 12,32,0)) | ||
.caseData(CafcassApiCaseData.builder().build()) | ||
.build(), | ||
CafcassApiCase.builder() | ||
.caseId(2L).jurisdiction("jurisdiction").state("state").caseTypeId("caseTypeId") | ||
.createdDate(LocalDateTime.of(2024, 1, 1, 10, 0, 0)) | ||
.lastModified(LocalDateTime.of(2024, 3, 28, 12,40,0)) | ||
.caseData(CafcassApiCaseData.builder().build()) | ||
.build()); | ||
|
||
when(cafcassApiSearchCaseService.searchCaseByDateRange( | ||
LocalDateTime.of(2024, 3, 28, 12,30,1,541000000), | ||
LocalDateTime.of(2024, 3, 28, 12,45,1,540000000)) | ||
).thenReturn(responseCases); | ||
|
||
MvcResult response = sendRequest(buildGetRequest("/cases") | ||
.queryParam("startDate", "2024-03-28T12:30:01.541") | ||
.queryParam("endDate", "2024-03-28T12:45:01.540"), 200); | ||
|
||
assertEquals( | ||
CafcassApiSearchCasesResponse.builder().total(2).cases(responseCases).build(), | ||
readResponseContent(response, CafcassApiSearchCasesResponse.class)); | ||
} | ||
|
||
@Test | ||
void searchCasesInvalidFormat400() throws Exception { | ||
sendRequest(buildGetRequest("/cases") | ||
.queryParam("startDate", "123").queryParam("endDate", "321"), | ||
400); | ||
} | ||
|
||
@Test | ||
void shouldReturn400IfEmptyParam() throws Exception { | ||
sendRequest(buildGetRequest("/cases"), 400); | ||
|
||
sendRequest(buildGetRequest("/cases") | ||
.queryParam("startDate", "2023-03-28T12:32:54.541"), 400); | ||
|
||
sendRequest(buildGetRequest("/cases") | ||
.queryParam("endDate", "2024-03-27T12:32:54.542"), 400); | ||
} | ||
|
||
@Test | ||
void searchCasesInvalidTimeRange() throws Exception { | ||
sendRequest(buildGetRequest("/cases") | ||
.queryParam("startDate", "2024-03-28T12:32:54.541") | ||
.queryParam("endDate", "2023-03-27T12:32:54.542"), 400); | ||
} | ||
|
||
@Test | ||
void shouldReturn400IfSearchRangeMoreThan15Minutes() throws Exception { | ||
sendRequest(buildGetRequest("/cases") | ||
.queryParam("startDate", "2024-03-28T12:32:54.541") | ||
.queryParam("endDate", "2024-03-28T12:47:54.542"), 400); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this mock bean to resolve bean not found when initialising mockMVC