Skip to content
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 67 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
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 Jun 28, 2024
019df0d
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice Jul 2, 2024
6026a6f
update CafcassCasesController for POC
chak-shing-lo-justice Jul 2, 2024
1eb519d
update CafcassCasesController for POC
chak-shing-lo-justice Jul 2, 2024
3f639b7
Update CafcassCasesController.java
chak-shing-lo-justice Jul 2, 2024
b308de6
Update CafcassCasesControllerTest.java
chak-shing-lo-justice Jul 2, 2024
680242d
Update CafcassCasesController.java
chak-shing-lo-justice Jul 2, 2024
86b59a3
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice Jul 3, 2024
9c6b654
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice Jul 3, 2024
1a46c87
add all endpoint for POC
chak-shing-lo-justice Jul 3, 2024
8aecb85
remove unused import
chak-shing-lo-justice Jul 3, 2024
9b7784c
Update CafcassCasesControllerTest.java
chak-shing-lo-justice Jul 3, 2024
6fb7d74
Update CafcassCasesController.java
chak-shing-lo-justice Jul 3, 2024
cf02f56
Update CafcassCasesController.java
chak-shing-lo-justice Jul 3, 2024
23c3f27
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice Jul 3, 2024
ab5edab
Merge branch 'master' into DFPL-2427
chak-shing-lo-justice Jul 4, 2024
2b2e78d
update CafcassCasesController
chak-shing-lo-justice Jul 4, 2024
9008cc1
Merge branch 'DFPL-2427' of https://github.com/hmcts/fpl-ccd-configur…
chak-shing-lo-justice Jul 4, 2024
98ac6c9
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice Jul 8, 2024
80db602
DFPL-2449 Add interceptor and exception handling for Cafcass API (#5493)
chak-shing-lo-justice Jul 9, 2024
cadff7c
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice Jul 9, 2024
dc38342
fix unit test
chak-shing-lo-justice Jul 9, 2024
93844c5
Merge branch 'DFPL-1761' of https://github.com/hmcts/fpl-ccd-configur…
chak-shing-lo-justice Jul 9, 2024
1662143
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice Jul 9, 2024
d22da94
implement es search
chak-shing-lo-justice Jul 9, 2024
b252e5f
search case response object
chak-shing-lo-justice Jul 15, 2024
b1e7629
response field child and other
chak-shing-lo-justice Jul 15, 2024
35c88ec
remove converters chain
chak-shing-lo-justice Jul 16, 2024
4d0765f
other application details
chak-shing-lo-justice Jul 16, 2024
301e43b
refactor to chain pattern
chak-shing-lo-justice Jul 17, 2024
a8dfe59
orders document and manage document
chak-shing-lo-justice Jul 22, 2024
cab24c8
case documents
chak-shing-lo-justice Jul 23, 2024
fee3ae2
fix category
chak-shing-lo-justice Jul 24, 2024
6ad0f96
CafcassApiHelperTest and CafcassApiCaseServiceTest
chak-shing-lo-justice Jul 24, 2024
bbe80e0
applicantConverter test
chak-shing-lo-justice Jul 24, 2024
3d75c95
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice Jul 25, 2024
bab3ad0
CafcassApiChildrenConverterTest
chak-shing-lo-justice Jul 25, 2024
3bc5d2e
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice Jul 25, 2024
b412da4
refactor CafcassApiCaseDocumentsConverter to more FP style
chak-shing-lo-justice Jul 25, 2024
dada3b2
Create CafcassApiFactorsParentingConverterTest.java
chak-shing-lo-justice Jul 25, 2024
fdadce2
Merge branch 'DFPL-1761' of https://github.com/hmcts/fpl-ccd-configur…
chak-shing-lo-justice Jul 25, 2024
555ddbf
Create CafcassApiHearingDetailsConverterTest.java
chak-shing-lo-justice Jul 25, 2024
fb8cf50
add CafcassApiInternationalElementConverterTest
chak-shing-lo-justice Jul 25, 2024
1f5d3c6
Create CafcassApiMetaDataConverterTest.java
chak-shing-lo-justice Jul 25, 2024
a6b38ee
Create CafcassApiOthersConverterTest.java
chak-shing-lo-justice Jul 25, 2024
10b59c4
add CafcassApiPreviousProceedingsConverterTest
chak-shing-lo-justice Jul 25, 2024
f47773d
refactor and add CafcassApiRespondentsConverterTest
chak-shing-lo-justice Jul 25, 2024
a6312ab
Create CafcassApiRisksConverterTest.java
chak-shing-lo-justice Jul 25, 2024
9a564a2
add sdo and udo converter test
chak-shing-lo-justice Jul 25, 2024
09e26b8
add draft oder converting test
chak-shing-lo-justice Jul 26, 2024
392a1b2
refactor to service
chak-shing-lo-justice Jul 26, 2024
d633668
original application test
chak-shing-lo-justice Jul 26, 2024
e056be4
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice Jul 29, 2024
4651373
add managed doc test
chak-shing-lo-justice Jul 29, 2024
f214c55
update controller test
chak-shing-lo-justice Jul 29, 2024
f54889b
fix style check
chak-shing-lo-justice Jul 29, 2024
7de11a8
Merge branch 'master' into DFPL-1761
chak-shing-lo-justice Jul 29, 2024
9ea0fe8
fix unit test
chak-shing-lo-justice Jul 29, 2024
ae9d4b6
Merge branch 'cafcass-api' into DFPL-1761
chak-shing-lo-justice Jul 29, 2024
a9c0bf6
fix code check
chak-shing-lo-justice Jul 29, 2024
971d01e
rename to CafcassApiSearchCaseService
chak-shing-lo-justice Jul 29, 2024
ecaa745
Update AmendOrderToDownloadPrePopulatorTest.java
chak-shing-lo-justice Jul 29, 2024
83e399a
Update CafcassApiInterceptor.java
chak-shing-lo-justice Jul 31, 2024
8dbdea8
use cafcass role until new role is set up
chak-shing-lo-justice Jul 31, 2024
95f6faa
Update CafcassApiInterceptor.java
chak-shing-lo-justice Jul 31, 2024
306b626
use object provider
chak-shing-lo-justice Jul 31, 2024
4c7548b
remove comment
chak-shing-lo-justice Jul 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
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.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import uk.gov.hmcts.reform.idam.client.IdamClient;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand All @@ -20,6 +22,9 @@ class RootControllerTest {
@Autowired
private MockMvc mockMvc;

@MockBean
private IdamClient idamClient;

Copy link
Contributor Author

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

@Test
void shouldWelcomeUponRootRequestWith200ResponseCode() throws Exception {
MvcResult response = mockMvc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,6 +94,9 @@ class TestingSupportControllerTest {
@MockBean
private DocumentUploadClientApi uploadClient;

@MockBean
private IdamClient idamClient;

Copy link
Contributor Author

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

@BeforeEach
void init() {
when(requestData.authorisation()).thenReturn(USER_AUTH_TOKEN);
Expand Down
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);
}
}
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);
}
}
Loading
Loading