generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DTSSTCI-979: Added integration tests for Caseworker edit cases (#1888)
- Loading branch information
1 parent
f864b85
commit e1b4b4f
Showing
6 changed files
with
318 additions
and
22 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/event/CaseworkerEditCaseIT.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,123 @@ | ||
package uk.gov.hmcts.sptribs.caseworker.event; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import uk.gov.hmcts.sptribs.ciccase.model.CaseData; | ||
import uk.gov.hmcts.sptribs.ciccase.model.CicCase; | ||
import uk.gov.hmcts.sptribs.common.config.WebMvcConfig; | ||
import uk.gov.hmcts.sptribs.testutil.IdamWireMock; | ||
|
||
import java.util.HashSet; | ||
|
||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; | ||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; | ||
import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
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.sptribs.caseworker.util.EventConstants.CASEWORKER_EDIT_CASE; | ||
import static uk.gov.hmcts.sptribs.ciccase.model.State.DSS_Submitted; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.ABOUT_TO_SUBMIT_URL; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.AUTHORIZATION; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.SERVICE_AUTHORIZATION; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.SUBMITTED_URL; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_AUTHORIZATION_TOKEN; | ||
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.callbackRequest; | ||
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.caseData; | ||
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.cicCase; | ||
import static uk.gov.hmcts.sptribs.testutil.TestResourceUtil.expectedResponse; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@AutoConfigureMockMvc | ||
@ContextConfiguration(initializers = {IdamWireMock.PropertiesInitializer.class}) | ||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) | ||
public class CaseworkerEditCaseIT { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@MockBean | ||
private WebMvcConfig webMvcConfig; | ||
|
||
private static final String CASEWORKER_EDIT_CASE_ABOUT_TO_SUBMIT_RESPONSE = | ||
"classpath:responses/caseworker-edit-case-about-to-submit-response.json"; | ||
|
||
private static final String CONFIRMATION_HEADER = "$.confirmation_header"; | ||
|
||
@BeforeAll | ||
static void setUp() { | ||
IdamWireMock.start(); | ||
} | ||
|
||
@AfterAll | ||
static void tearDown() { | ||
IdamWireMock.stopAndReset(); | ||
} | ||
|
||
@Test | ||
void shouldEditCaseOnAboutToSubmit() throws Exception { | ||
final CaseData caseData = caseData(); | ||
caseData.setCaseStatus(DSS_Submitted); | ||
|
||
final CicCase cicCase = cicCase(); | ||
cicCase.setPartiesCIC(new HashSet<>()); | ||
caseData.setCicCase(cicCase); | ||
|
||
String response = mockMvc.perform(post(ABOUT_TO_SUBMIT_URL) | ||
.contentType(APPLICATION_JSON) | ||
.header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) | ||
.header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) | ||
.content(objectMapper.writeValueAsString( | ||
callbackRequest( | ||
caseData, | ||
CASEWORKER_EDIT_CASE))) | ||
.accept(APPLICATION_JSON)) | ||
.andExpect( | ||
status().isOk()) | ||
.andReturn() | ||
.getResponse() | ||
.getContentAsString(); | ||
|
||
assertThatJson(response) | ||
.when(IGNORING_EXTRA_FIELDS) | ||
.isEqualTo(json(expectedResponse(CASEWORKER_EDIT_CASE_ABOUT_TO_SUBMIT_RESPONSE))); | ||
} | ||
|
||
@Test | ||
void shouldReturnConfirmationMessageOnSubmitted() throws Exception { | ||
String response = mockMvc.perform(post(SUBMITTED_URL) | ||
.contentType(APPLICATION_JSON) | ||
.header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) | ||
.header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) | ||
.content(objectMapper.writeValueAsString( | ||
callbackRequest( | ||
caseData(), | ||
CASEWORKER_EDIT_CASE))) | ||
.accept(APPLICATION_JSON)) | ||
.andExpect( | ||
status().isOk()) | ||
.andReturn() | ||
.getResponse() | ||
.getContentAsString(); | ||
|
||
assertThatJson(response) | ||
.inPath(CONFIRMATION_HEADER) | ||
.isString() | ||
.contains("# Case Updated"); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...ationTest/java/uk/gov/hmcts/sptribs/caseworker/event/CaseworkerEditCicaCaseDetailsIT.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,113 @@ | ||
package uk.gov.hmcts.sptribs.caseworker.event; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import uk.gov.hmcts.sptribs.ciccase.model.CaseData; | ||
import uk.gov.hmcts.sptribs.common.config.WebMvcConfig; | ||
import uk.gov.hmcts.sptribs.testutil.IdamWireMock; | ||
|
||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; | ||
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; | ||
import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
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.sptribs.caseworker.util.EventConstants.CASEWORKER_EDIT_CICA_CASE_DETAILS; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.ABOUT_TO_SUBMIT_URL; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.AUTHORIZATION; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.SERVICE_AUTHORIZATION; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.SUBMITTED_URL; | ||
import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_AUTHORIZATION_TOKEN; | ||
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.callbackRequest; | ||
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.caseData; | ||
import static uk.gov.hmcts.sptribs.testutil.TestResourceUtil.expectedResponse; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@AutoConfigureMockMvc | ||
@ContextConfiguration(initializers = {IdamWireMock.PropertiesInitializer.class}) | ||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) | ||
public class CaseworkerEditCicaCaseDetailsIT { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@MockBean | ||
private WebMvcConfig webMvcConfig; | ||
|
||
private static final String CASEWORKER_EDIT_CICA_CASE_DETAILS_ABOUT_TO_SUBMIT_RESPONSE = | ||
"classpath:responses/caseworker-edit-cica-case-details-about-to-submit-response.json"; | ||
|
||
private static final String CONFIRMATION_HEADER = "$.confirmation_header"; | ||
|
||
@BeforeAll | ||
static void setUp() { | ||
IdamWireMock.start(); | ||
} | ||
|
||
@AfterAll | ||
static void tearDown() { | ||
IdamWireMock.stopAndReset(); | ||
} | ||
|
||
@Test | ||
void shouldEditCicaCaseDetailsOnAboutToSubmit() throws Exception { | ||
final CaseData caseData = caseData(); | ||
|
||
String response = mockMvc.perform(post(ABOUT_TO_SUBMIT_URL) | ||
.contentType(APPLICATION_JSON) | ||
.header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) | ||
.header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) | ||
.content(objectMapper.writeValueAsString( | ||
callbackRequest( | ||
caseData, | ||
CASEWORKER_EDIT_CICA_CASE_DETAILS))) | ||
.accept(APPLICATION_JSON)) | ||
.andExpect( | ||
status().isOk()) | ||
.andReturn() | ||
.getResponse() | ||
.getContentAsString(); | ||
|
||
assertThatJson(response) | ||
.when(IGNORING_EXTRA_FIELDS) | ||
.isEqualTo(json(expectedResponse(CASEWORKER_EDIT_CICA_CASE_DETAILS_ABOUT_TO_SUBMIT_RESPONSE))); | ||
} | ||
|
||
@Test | ||
void shouldReturnConfirmationMessageOnSubmitted() throws Exception { | ||
String response = mockMvc.perform(post(SUBMITTED_URL) | ||
.contentType(APPLICATION_JSON) | ||
.header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) | ||
.header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) | ||
.content(objectMapper.writeValueAsString( | ||
callbackRequest( | ||
caseData(), | ||
CASEWORKER_EDIT_CICA_CASE_DETAILS))) | ||
.accept(APPLICATION_JSON)) | ||
.andExpect( | ||
status().isOk()) | ||
.andReturn() | ||
.getResponse() | ||
.getContentAsString(); | ||
|
||
assertThatJson(response) | ||
.inPath(CONFIRMATION_HEADER) | ||
.isString() | ||
.contains("# Case details updated. "); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/integrationTest/resources/responses/caseworker-edit-case-about-to-submit-response.json
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,32 @@ | ||
{ | ||
"data": { | ||
"caseLinks": [], | ||
"caseFlags": { | ||
"details": [] | ||
}, | ||
"subjectFlags": { | ||
"roleOnCase": "subject", | ||
"details": [] | ||
}, | ||
"allCaseworkerCICDocument": [], | ||
"allCaseworkerCICDocumentUpload": [], | ||
"newCaseworkerCICDocument": [], | ||
"newCaseworkerCICDocumentUpload": [], | ||
"editCicaCaseDetails": {}, | ||
"contactParties": {}, | ||
"caseBundles": [], | ||
"cicCasePartiesCIC": [], | ||
"cicCaseRespondentName": "Appeals team", | ||
"cicCaseRespondentOrganisation": "CICA", | ||
"cicCaseRespondentEmail": "appeals.team@cica.gov.uk", | ||
"cicCaseFirstDueDate": "", | ||
"caseStatus": "DSS_Submitted", | ||
"stayIsCaseStayed": "No", | ||
"hearingList": [], | ||
"hyphenatedCaseRef": "1616-5914-0147-3378", | ||
"closedDayCount": "", | ||
"firstHearingDate": "", | ||
"dataVersion": 0, | ||
"cicCaseSelectedDocument": {} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...nTest/resources/responses/caseworker-edit-cica-case-details-about-to-submit-response.json
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,22 @@ | ||
{ | ||
"data": { | ||
"caseLinks": [], | ||
"allCaseworkerCICDocument": [], | ||
"allCaseworkerCICDocumentUpload": [], | ||
"newCaseworkerCICDocument": [], | ||
"newCaseworkerCICDocumentUpload": [], | ||
"editCicaCaseDetails": {}, | ||
"contactParties": {}, | ||
"caseBundles": [], | ||
"cicCaseRespondentName": "Appeals team", | ||
"cicCaseRespondentOrganisation": "CICA", | ||
"cicCaseRespondentEmail": "appeals.team@cica.gov.uk", | ||
"cicCaseFirstDueDate": "", | ||
"stayIsCaseStayed": "No", | ||
"hearingList": [], | ||
"closedDayCount": "", | ||
"firstHearingDate": "", | ||
"dataVersion": 0, | ||
"cicCaseSelectedDocument": {} | ||
} | ||
} |
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