-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into SSCSSI-147_TyanToTribs
- Loading branch information
Showing
12 changed files
with
3,487 additions
and
27 deletions.
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
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
139 changes: 139 additions & 0 deletions
139
src/IntegrationTests/java/uk/gov/hmcts/reform/sscs/callback/SendToFirstTierIt.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,139 @@ | ||
package uk.gov.hmcts.reform.sscs.callback; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.ArgumentMatchers.anyMap; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.ArgumentMatchers.isA; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import static uk.gov.hmcts.reform.sscs.helper.IntegrationTestHelper.assertHttpStatus; | ||
import static uk.gov.hmcts.reform.sscs.helper.IntegrationTestHelper.getRequestWithAuthHeader; | ||
|
||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
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.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.mock.web.MockHttpServletResponse; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import uk.gov.hmcts.reform.ccd.client.model.CaseDataContent; | ||
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; | ||
import uk.gov.hmcts.reform.ccd.client.model.StartEventResponse; | ||
import uk.gov.hmcts.reform.sscs.ccd.callback.Callback; | ||
import uk.gov.hmcts.reform.sscs.ccd.callback.PreSubmitCallbackResponse; | ||
import uk.gov.hmcts.reform.sscs.ccd.client.CcdClient; | ||
import uk.gov.hmcts.reform.sscs.ccd.deserialisation.SscsCaseCallbackDeserializer; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.DocumentGeneration; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.DocumentLink; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.DocumentStaging; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.SendToFirstTier; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.SendToFirstTierActions; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseDetails; | ||
import uk.gov.hmcts.reform.sscs.ccd.service.CcdCallbackMapService; | ||
import uk.gov.hmcts.reform.sscs.ccd.service.SscsCcdConvertService; | ||
import uk.gov.hmcts.reform.sscs.controller.CcdCallbackController; | ||
import uk.gov.hmcts.reform.sscs.idam.IdamService; | ||
import uk.gov.hmcts.reform.sscs.idam.IdamTokens; | ||
|
||
@SpringBootTest(properties = { | ||
"feature.postHearingsB.enabled=true", | ||
"feature.handle-ccd-callbackMap-v2.enabled=true" | ||
}) | ||
@AutoConfigureMockMvc | ||
public class SendToFirstTierIt extends AbstractEventIt { | ||
|
||
@SpyBean | ||
private CcdCallbackMapService ccdCallbackMapService; | ||
|
||
@SpyBean | ||
private SscsCaseCallbackDeserializer sscsCaseCallbackDeserializer; | ||
|
||
@MockBean | ||
private IdamService idamService; | ||
|
||
@MockBean | ||
private CcdClient ccdClient; | ||
|
||
@MockBean | ||
private SscsCcdConvertService sscsCcdConvertService; | ||
|
||
@BeforeEach | ||
public void setup() throws IOException { | ||
CcdCallbackController controller = new CcdCallbackController(authorisationService, deserializer, dispatcher); | ||
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); | ||
mapper.registerModule(new JavaTimeModule()); | ||
json = getJson("callback/sendToFirstTierRequest.json"); | ||
when(idamService.getIdamTokens()).thenReturn(IdamTokens.builder().build()); | ||
} | ||
|
||
@Test | ||
public void callToSubmittedHandler_SendToFirstTierSubmittedHandler() throws Exception { | ||
CaseDetails caseDetails = CaseDetails.builder().data(Collections.EMPTY_MAP).build(); | ||
|
||
Callback<SscsCaseData> callback = sscsCaseCallbackDeserializer.deserialize(json); | ||
SscsCaseData caseData = callback.getCaseDetails().getCaseData(); | ||
|
||
SscsCaseDetails sscsCaseDetails = SscsCaseDetails.builder().id(123L).data(caseData).build(); | ||
StartEventResponse startEventResponse = StartEventResponse.builder().caseDetails(caseDetails).build(); | ||
|
||
when(ccdClient.startEvent(any(), anyLong(), anyString())) | ||
.thenReturn(startEventResponse); | ||
when(ccdClient.submitEventForCaseworker(any(), any(), any())) | ||
.thenReturn(caseDetails); | ||
when(sscsCcdConvertService.getCaseData(anyMap())) | ||
.thenReturn(sscsCaseDetails.getData()); | ||
|
||
when(sscsCcdConvertService.getCaseDataContent( | ||
eq(sscsCaseDetails.getData()), | ||
any(), | ||
anyString(), | ||
anyString())) | ||
.thenReturn(CaseDataContent.builder() | ||
.data(sscsCaseDetails.getData()) | ||
.build()); | ||
when(sscsCcdConvertService.getCaseDetails(caseDetails)) | ||
.thenReturn(sscsCaseDetails); | ||
when(sscsCcdConvertService.getCaseDetails(isA(StartEventResponse.class))) | ||
.thenReturn(sscsCaseDetails); | ||
|
||
assertThat(sscsCaseDetails.getData().getPostHearing().getSetAside()) | ||
.isNotNull(); | ||
|
||
MockHttpServletResponse response = getResponse(getRequestWithAuthHeader(json, "/ccdSubmittedEvent")); | ||
|
||
assertHttpStatus(response, HttpStatus.OK); | ||
|
||
PreSubmitCallbackResponse<SscsCaseData> result = deserialize(response.getContentAsString()); | ||
|
||
SendToFirstTier sendToFirstTier = SendToFirstTier.builder() | ||
.action(SendToFirstTierActions.DECISION_REMITTED) | ||
.decisionDocument(DocumentLink.builder() | ||
.documentUrl("http://dm-store-aat.service.core-compute-aat.internal/documents/534405a9-f1d6-4b1f-aa6f-6cac5139da8d") | ||
.documentBinaryUrl("http://dm-store-aat.service.core-compute-aat.internal/documents/534405a9-f1d6-4b1f-aa6f-6cac5139da8d/binary") | ||
.documentFilename("hello.pdf") | ||
.build()) | ||
.build(); | ||
|
||
verify(ccdCallbackMapService).handleCcdCallbackMapV2(eq(sendToFirstTier.getAction()), anyLong()); | ||
|
||
assertThat(result.getErrors()) | ||
.isEmpty(); | ||
assertThat(result.getData()) | ||
.isNotNull(); | ||
assertThat(result.getData().getPostHearing().getSendToFirstTier()) | ||
.isEqualTo(sendToFirstTier); | ||
assertThat(result.getData().getDocumentGeneration()) | ||
.isEqualTo(DocumentGeneration.builder().build()); | ||
assertThat(result.getData().getDocumentStaging()) | ||
.isEqualTo(DocumentStaging.builder().build()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
.../reform/sscs/functional/handlers/sendtofirsttier/SendToFirstTierSubmittedHandlerTest.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,65 @@ | ||
package uk.gov.hmcts.reform.sscs.functional.handlers.sendtofirsttier; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.http.Header; | ||
import java.io.IOException; | ||
import org.apache.http.HttpStatus; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import uk.gov.hmcts.reform.sscs.ccd.callback.Callback; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseDetails; | ||
import uk.gov.hmcts.reform.sscs.functional.handlers.BaseHandler; | ||
|
||
@RunWith(SpringRunner.class) | ||
@TestPropertySource(locations = "classpath:config/application_functional.properties") | ||
@SpringBootTest | ||
public class SendToFirstTierSubmittedHandlerTest extends BaseHandler { | ||
protected static final String CASE_ID_TO_BE_REPLACED = "12345656789"; | ||
@Autowired | ||
private ObjectMapper mapper; | ||
|
||
@DisplayName("Given about to submit callback for send to first tier event, should set fields") | ||
@Test | ||
public void testSendToFirstTierSubmitted() throws IOException { | ||
String jsonCallback = getJsonCallbackForTest("callback/sendToFirstTierRequest.json"); | ||
Callback<SscsCaseData> callback = deserializer.deserialize(jsonCallback); | ||
|
||
SscsCaseDetails caseDetails = createCase(); | ||
callback = addCaseIdtoCallback(callback, caseDetails.getId().toString()); | ||
|
||
String response = RestAssured.given() | ||
.log().method().log().headers().log().uri().log().body(true) | ||
.contentType(ContentType.JSON) | ||
.header(new Header("ServiceAuthorization", idamTokens.getServiceAuthorization())) | ||
.header(new Header("Authorization", idamTokens.getIdamOauth2Token())) | ||
.body(callback) | ||
.post("/ccdSubmittedEvent") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.log().all(true).extract().body().asString(); | ||
|
||
JsonNode root = mapper.readTree(response); | ||
SscsCaseData result = mapper.readValue(root.path("data").toPrettyString(), new TypeReference<>(){}); | ||
assertThat(result.getDwpState()).isNull(); | ||
assertThat(result.getInterlocReferralReason()).isNull(); | ||
assertThat(result.getInterlocReviewState()).isNull(); | ||
} | ||
|
||
private Callback<SscsCaseData> addCaseIdtoCallback(Callback<SscsCaseData> sscsCaseDataCallback, String id) { | ||
String jsonCallback = serializeSscsCallback(sscsCaseDataCallback); | ||
jsonCallback = jsonCallback.replace(CASE_ID_TO_BE_REPLACED, id); | ||
return deserializer.deserialize(jsonCallback); | ||
} | ||
} |
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
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
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
Oops, something went wrong.