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

Feature branch Cafcass APIs #5494

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c7111f2
DFPL-2427 POC controllers for FPL API gateway (#5481)
chak-shing-lo-justice Jul 9, 2024
99bd7f2
Merge branch 'master' into cafcass-api
chak-shing-lo-justice Jul 9, 2024
9dbfd58
Merge branch 'master' into cafcass-api
chak-shing-lo-justice Jul 11, 2024
8ee8cec
Merge branch 'master' into cafcass-api
chak-shing-lo-justice Jul 29, 2024
04f551e
DFPL-1761 Build GET /searchCases endpoint (#5495)
chak-shing-lo-justice Aug 1, 2024
531a004
Merge branch 'master' into cafcass-api
chak-shing-lo-justice Aug 1, 2024
90b65d1
update CAFCASS_SYSTEM_UPDATE value (#5523)
chak-shing-lo-justice Aug 1, 2024
cdbcbe7
fix code style
chak-shing-lo-justice Aug 1, 2024
50e3c3f
Dfpl 1761 ES query fix (#5524)
chak-shing-lo-justice Aug 2, 2024
8d404e7
DFPL 1760 (#5525)
chak-shing-lo-justice Aug 8, 2024
d4b16fc
Cafcass api fix conflict (#5538)
chak-shing-lo-justice Aug 14, 2024
9c49c45
Merge branch 'master' into cafcass-api
chak-shing-lo-justice Aug 19, 2024
b6ea883
DFPL-1791: Add List for Guardian Report API call (#5531)
AlistairEdwinOsborne Aug 19, 2024
17255c7
Dfpl 1790 (#5541)
chak-shing-lo-justice Aug 20, 2024
680da71
Update system-update.json (#5544)
chak-shing-lo-justice Aug 20, 2024
a958078
add genderIdentification to response (#5546)
chak-shing-lo-justice Aug 21, 2024
9caf2d6
DFPL-1762 (#5540)
chak-shing-lo-justice Aug 21, 2024
18b5f9f
fix gender value in API response (#5548)
chak-shing-lo-justice Aug 23, 2024
3515ecf
Push Master changes to cafcass api feature branch (#5554)
AlistairEdwinOsborne Aug 28, 2024
35aa223
Revert "Push Master changes to cafcass api feature branch (#5554)"
chak-shing-lo-justice Aug 28, 2024
d9f9dd8
Merge branch 'master' into cafcass-api
chak-shing-lo-justice Aug 28, 2024
42ecb35
Merge branch 'master' into 20240904-merge
chak-shing-lo-justice Sep 4, 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;

@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;

@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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package uk.gov.hmcts.reform.fpl.controllers.cafcass;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import uk.gov.hmcts.reform.fpl.controllers.AbstractTest;
import uk.gov.hmcts.reform.idam.client.models.UserInfo;

import java.util.List;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
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;

@Deprecated
@WebMvcTest(CafcassCasesController.class)
@OverrideAutoConfiguration(enabled = true)
public class CafcassCasesControllerTest extends AbstractTest {
private static final UserInfo CAFCASS_SYSTEM_UPDATE_USER_INFO = UserInfo.builder()
.roles(List.of(CAFCASS_SYSTEM_UPDATE.getRoleName()))
.build();
private static final UUID CASE_ID = UUID.randomUUID();
private static final byte[] FILE_BYTES = "This is a file. Trust me!".getBytes();
private static final MockMultipartFile FILE = new MockMultipartFile(
"file", "MOCK_FILE.pdf", MediaType.TEXT_PLAIN_VALUE, FILE_BYTES);

@Autowired
private MockMvc mockMvc;

@BeforeEach
void setUp() {
givenCurrentUser(CAFCASS_SYSTEM_UPDATE_USER_INFO);
}

@Test
void uploadDocument() throws Exception {

MvcResult response = mockMvc
.perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(CASE_ID))
.file(FILE)
.param("typeOfDocument", "type Of Document")
.header("authorization", USER_AUTH_TOKEN))
.andExpect(status().is(200))
.andReturn();

assertEquals("uploadDocument - caseId: [%s], file length: [%s], typeOfDocument: [%s]"
.formatted(CASE_ID, FILE_BYTES.length, "type Of Document"),
response.getResponse().getContentAsString());
}

@Test
void uploadDocument400() throws Exception {
UUID caseId = UUID.randomUUID();

MvcResult response = mockMvc
.perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(caseId))
.param("typeOfDocument", "type Of Document")
.header("authorization", USER_AUTH_TOKEN))
.andExpect(status().is(400))
.andReturn();

assertEquals(response.getResponse().getStatus(), 400);


byte[] fileBytes = "This is a file. Trust me!".getBytes();
MockMultipartFile file = new MockMultipartFile(
"file", "MOCK_FILE.pdf", MediaType.TEXT_PLAIN_VALUE, fileBytes);

response = mockMvc
.perform(MockMvcRequestBuilders.multipart("/cases/%s/document".formatted(caseId))
.file(file)
.header("authorization", USER_AUTH_TOKEN))
.andExpect(status().is(400))
.andReturn();

assertEquals(response.getResponse().getStatus(), 400);
}

@Test
void uploadGuardians() throws Exception {
UUID caseId = UUID.randomUUID();

MvcResult response = mockMvc.perform(post("/cases/%s/guardians".formatted(caseId))
.content("[\n"
+ " {\n"
+ " \"guardianName\": \"John Smith\",\n"
+ " \"telephoneNumber\": \"01234567890\",\n"
+ " \"email\": \"[email protected]\",\n"
+ " \"children\": [\n"
+ " \"Joe Bloggs\"\n"
+ " ]\n"
+ " }\n"
+ "]")
.contentType(MediaType.APPLICATION_JSON)
.header("authorization", USER_AUTH_TOKEN))
.andExpect(status().is(200))
.andReturn();

assertEquals("uploadGuardians - caseId: [%s], no of guardians: [%s]\nguardianName: [%s], children: [%s]\n"
.formatted(caseId, 1, "John Smith", "Joe Bloggs"),
response.getResponse().getContentAsString());
}

@Test
void uploadGuardians400() throws Exception {
UUID caseId = UUID.randomUUID();

MvcResult response = mockMvc.perform(post("/cases/%s/guardians".formatted(caseId))
.content("[]")
.contentType(MediaType.APPLICATION_JSON)
.header("authorization", USER_AUTH_TOKEN))
.andExpect(status().is(400))
.andReturn();

assertEquals(response.getResponse().getStatus(), 400);

response = mockMvc.perform(post("/cases/%s/guardians".formatted(" "))
.content("[\n"
+ " {\n"
+ " \"guardianName\": \"John Smith\",\n"
+ " \"telephoneNumber\": \"01234567890\",\n"
+ " \"email\": \"[email protected]\",\n"
+ " \"children\": [\n"
+ " \"Joe Bloggs\"\n"
+ " ]\n"
+ " }\n"
+ "]")
.contentType(MediaType.APPLICATION_JSON)
.header("authorization", USER_AUTH_TOKEN))
.andExpect(status().is(400))
.andReturn();

assertEquals(response.getResponse().getStatus(), 400);
}

@Test
void uploadGuardians500() throws Exception {
UUID caseId = UUID.randomUUID();

MvcResult response = mockMvc.perform(post("/cases/%s/guardians".formatted(caseId))
.content("[\n"
+ " {\n"
+ " \"guardianName\": \"John Smith\",\n"
+ " \"telephoneNumber\": \"01234567890\",\n"
+ " \"email\": \"[email protected]\",\n"
+ " \"children\": \"12313\""
+ " }\n"
+ "]")
.contentType(MediaType.APPLICATION_JSON)
.header("authorization", USER_AUTH_TOKEN))
.andExpect(status().is(500))
.andReturn();

assertEquals(response.getResponse().getStatus(), 500);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.gov.hmcts.reform.fpl.config.cafcass;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import uk.gov.hmcts.reform.fpl.interceptors.CafcassApiInterceptor;

@Configuration
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CafcassApiConfiguration implements WebMvcConfigurer {
private final CafcassApiInterceptor cafcassApiInterceptor;

public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(cafcassApiInterceptor).addPathPatterns("/cases");
}
}
Loading
Loading