Skip to content

Commit

Permalink
Merge branch 'master' into SSCSSI-147_TyanToTribs
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayparekh-hmcts committed Sep 5, 2024
2 parents ff14019 + 739b4c7 commit 1008dd4
Show file tree
Hide file tree
Showing 12 changed files with 3,487 additions and 27 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ dependencies {
implementation group: 'com.github.hmcts', name: 'document-management-client', version: '7.0.0'
implementation group: 'com.github.hmcts', name: 'cmc-pdf-service-client', version: '7.0.1'

implementation group: 'com.github.hmcts', name: 'sscs-common', version: '5.11.5'
implementation group: 'com.github.hmcts', name: 'sscs-pdf-email-common', version: '5.2.10'
implementation group: 'com.mchange', name: 'c3p0', version: '0.9.5.5'
implementation group: 'org.flywaydb', name: 'flyway-core', version: '9.22.3'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.6.0'
implementation group: 'com.github.hmcts', name: 'sscs-common', version: '5.11.6'
implementation group: 'com.github.hmcts', name: 'sscs-pdf-email-common', version: '5.2.12'

implementation group: 'com.azure', name: 'azure-core', version: '1.46.0'
implementation group: 'com.azure', name: 'azure-messaging-servicebus', version: '7.15.1'
Expand Down Expand Up @@ -608,6 +608,8 @@ bootWithCCD {
// Features
environment 'GAPS_SWITCHOVER_FEATURE', 'true'
environment 'CASE_ACCESS_MANAGEMENT_FEATURE', 'true'
environment 'HANDLE_CCD_CALLBACKMAP_V2', 'true'
environment 'POST_HEARINGS_B_FEATURE', 'true'

// Local Queue
environment 'JMS_NAMESPACE', 'localhost:5672'
Expand Down
4 changes: 3 additions & 1 deletion charts/sscs-tribunals-api/values.aat.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ java:
WORK_ALLOCATION_FEATURE: true
CASE_ACCESS_MANAGEMENT_FEATURE: true
SCHEDULE_LISTING_FEATURE: true
TESTING_SUPPORT_ENABLED: true
TESTING_SUPPORT_ENABLED: true
HANDLE_CCD_CALLBACKMAP_V2: true
POST_HEARINGS_B_FEATURE: true
2 changes: 1 addition & 1 deletion config/owasp/suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
<suppress until = "2024-09-01">
<suppress until = "2024-10-09">
<cve>CVE-2023-35116</cve>
<cve>CVE-2023-36052</cve>
<cve>CVE-2024-1597</cve>
Expand Down
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());
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void givenAboutToSubmitCallbackForEvent_shouldSetFields() throws Exceptio
.assertThat().body("writeFinalDecisionAnythingElse", equalTo("Something else."))
.assertThat().body("writeFinalDecisionStartDate", equalTo("2019-10-10"))
.assertThat().body("writeFinalDecisionTypeOfHearing", equalTo("telephone"))
.assertThat().body("writeFinalDecisionPreviewDocument.document_url", notNullValue());
.assertThat().body("writeFinalDecisionPreviewDocument.document_url", notNullValue())
.assertThat().body("finalDecisionHeldAt", equalTo("Chester"))
.assertThat().body("finalDecisionIdamSurname", equalTo("Service Account"))
.assertThat().body("finalDecisionJudge", equalTo("Judge Ed"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
"document_binary_url": "http://dm-store:5005/documents/7539160a-b124-4539-b7c1-f3dcfbcea94c/binary",
"document_filename": "decisionIssued.pdf"
},
"finalDecisionHeldAt": "Chester",
"finalDecisionJudge": "Judge Ed",
"finalDecisionIdamSurname": "Service Account",
"subscriptions": {
"appellantSubscription": {},
"appointeeSubscription": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Objects.requireNonNull;

import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -47,14 +46,13 @@ public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType,
SscsCaseData caseData = callback.getCaseDetails().getCaseData();

if (isHandleCcdCallbackMapV2Enabled) {
Optional<SscsCaseData> sscsCaseDataOptional = ccdCallbackMapService.handleCcdCallbackMapV2(
caseData = ccdCallbackMapService.handleCcdCallbackMapV2(
caseData.getPostHearing().getSendToFirstTier().getAction(),
callback.getCaseDetails().getId()
);
return new PreSubmitCallbackResponse<>(sscsCaseDataOptional.orElse(caseData));
} else {
caseData = ccdCallbackMapService.handleCcdCallbackMap(caseData.getPostHearing().getSendToFirstTier().getAction(), caseData);
return new PreSubmitCallbackResponse<>(caseData);
}
return new PreSubmitCallbackResponse<>(caseData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected NoticeIssuedTemplateBody createPayload(PreSubmitCallbackResponse<SscsC
builder.dateIssued(finalDecisionCaseData.getFinalDecisionIssuedDate());
builder.correctedJudgeName(buildSignedInJudgeName(userAuthorisation));
builder.correctedDateIssued(showIssueDate ? LocalDate.now() : null);
builder.idamSurname(finalDecisionCaseData.getFinalDecisionIdamSurname());
builder.idamSurname(buildSignedInJudgeSurname(userAuthorisation));
} else {
builder.userName(buildSignedInJudgeName(userAuthorisation));
builder.idamSurname(buildSignedInJudgeSurname(userAuthorisation));
Expand All @@ -100,10 +100,11 @@ protected NoticeIssuedTemplateBody createPayload(PreSubmitCallbackResponse<SscsC

setHearings(writeFinalDecisionBuilder, caseData);

String heldAt = writeFinalDecisionBuilder.build().getHeldAt();
String heldBefore = buildHeldBefore(caseData, userAuthorisation);
String heldAt = SscsUtil.buildWriteFinalDecisionHeldAt(caseData, venueDataLoader);
String heldBefore = buildHeldBefore(caseData, userAuthorisation, isPostHearingsEnabled);

if (isPostHearingsEnabled && nonNull(finalDecisionCaseData.getFinalDecisionHeldAt())) {
if (isPostHearingsEnabled && nonNull(finalDecisionCaseData.getFinalDecisionHeldAt())
&& SscsUtil.isCorrectionInProgress(caseData, isPostHearingsEnabled)) {
heldAt = finalDecisionCaseData.getFinalDecisionHeldAt();
}

Expand Down Expand Up @@ -262,10 +263,12 @@ private void validateRequiredProperties(WriteFinalDecisionTemplateBody payload)
}
}

protected String buildHeldBefore(SscsCaseData caseData, String userAuthorisation) {
String judgeName = caseData.getSscsFinalDecisionCaseData().getFinalDecisionJudge();

if (isNull(judgeName)) {
protected String buildHeldBefore(SscsCaseData caseData, String userAuthorisation, boolean isPostHearingsEnabled) {
String judgeName = null;
String originalJudgeName = caseData.getSscsFinalDecisionCaseData().getFinalDecisionJudge();
if (SscsUtil.isCorrectionInProgress(caseData, isPostHearingsEnabled) && !isNull(originalJudgeName)) {
judgeName = originalJudgeName;
} else {
judgeName = buildSignedInJudgeName(userAuthorisation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType.*;
import static uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType.MID_EVENT;
import static uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.sscs.ccd.domain.EventType.SEND_TO_FIRST_TIER;
import static uk.gov.hmcts.reform.sscs.ccd.domain.EventType.UPPER_TRIBUNAL_DECISION;

import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -21,7 +21,11 @@
import org.springframework.test.util.ReflectionTestUtils;
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.domain.*;
import uk.gov.hmcts.reform.sscs.ccd.domain.CaseDetails;
import uk.gov.hmcts.reform.sscs.ccd.domain.PostHearing;
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.service.CcdCallbackMapService;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -93,7 +97,7 @@ void givenRequestPostHearingTypes_shouldReturnCallCorrectCallback_whenCcdCallbac
when(callback.getCaseDetails()).thenReturn(caseDetails);
when(caseDetails.getCaseData()).thenReturn(caseData);
when(ccdCallbackMapService.handleCcdCallbackMapV2(value, CASE_ID))
.thenReturn(Optional.of(SscsCaseData.builder().build()));
.thenReturn(SscsCaseData.builder().build());

PreSubmitCallbackResponse<SscsCaseData> response =
handler.handle(SUBMITTED, callback, USER_AUTHORISATION);
Expand Down
Loading

0 comments on commit 1008dd4

Please sign in to comment.