diff --git a/hearing-integration-test/src/test/java/uk/gov/moj/cpp/hearing/it/CourtListRestrictionIT.java b/hearing-integration-test/src/test/java/uk/gov/moj/cpp/hearing/it/CourtListRestrictionIT.java index 3882ad7af..44ad0c3c2 100644 --- a/hearing-integration-test/src/test/java/uk/gov/moj/cpp/hearing/it/CourtListRestrictionIT.java +++ b/hearing-integration-test/src/test/java/uk/gov/moj/cpp/hearing/it/CourtListRestrictionIT.java @@ -1,5 +1,6 @@ package uk.gov.moj.cpp.hearing.it; +import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath; import static com.jayway.jsonpath.matchers.JsonPathMatchers.isJson; import static com.jayway.jsonpath.matchers.JsonPathMatchers.withJsonPath; import static java.util.Optional.of; @@ -11,6 +12,10 @@ import static org.hamcrest.Matchers.is; import static uk.gov.moj.cpp.hearing.it.PublishLatestCourtCentreHearingEventsIT.XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26; import static uk.gov.moj.cpp.hearing.steps.HearingEventStepDefinitions.OPEN_CASE_PROSECUTION_EVENT_DEFINITION_ID; +import static uk.gov.moj.cpp.hearing.utils.WebDavStub.awaitNewFile; +import static uk.gov.moj.cpp.hearing.utils.WebDavStub.awaitNewSentXmlForPubDisplay; +import static uk.gov.moj.cpp.hearing.utils.WebDavStub.countFilesAt; +import static uk.gov.moj.cpp.hearing.utils.WebDavStub.countSentXmlForPubDisplay; import static uk.gov.moj.cpp.hearing.utils.WebDavStub.getFileForPath; import static uk.gov.moj.cpp.hearing.utils.WebDavStub.getSentXmlForPubDisplay; @@ -106,9 +111,14 @@ public void shouldRequestToPublishCourtListWithCaseRestriction() throws Exceptio publishCourtListJsonObject = buildPublishCourtListJsonString(courtCentreId, "26"); + final int webPageCountBeforeSecondPublish = countFilesAt(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26); + final int pubDisplayCountBeforeSecondPublish = countSentXmlForPubDisplay(); + courtCentreId = sendPublishCourtListCommand(publishCourtListJsonObject, courtCentreId); publishCourtListSteps.verifyCourtListPublishStatusReturnedWhenQueryingFromAPI(courtCentreId); + awaitNewFile(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26, webPageCountBeforeSecondPublish); + awaitNewSentXmlForPubDisplay(pubDisplayCountBeforeSecondPublish); filePayload = getFileForPath(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26); filePayloadForPubDisplay = getSentXmlForPubDisplay(); @@ -171,8 +181,13 @@ public void shouldRequestToPublishCourtListWithDefendantRestrictionOnOff() throw courtListRestrictionSteps.waitForRestrictionProjection(courtCentreId, eventTime.toLocalDate(), withJsonPath("$.court.courtSites[0].courtRooms[0].cases.casesDetails[0].defendants", hasSize(1))); + final int webPageCountBeforeSecondPublish = countFilesAt(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26); + final int pubDisplayCountBeforeSecondPublish = countSentXmlForPubDisplay(); + courtCentreId = sendPublishCourtListCommand(publishCourtListJsonObject, courtCentreId); publishCourtListSteps.verifyCourtListPublishStatusReturnedWhenQueryingFromAPI(courtCentreId); + awaitNewFile(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26, webPageCountBeforeSecondPublish); + awaitNewSentXmlForPubDisplay(pubDisplayCountBeforeSecondPublish); filePayload = getFileForPath(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26); filePayloadForPubDisplay = getSentXmlForPubDisplay(); @@ -242,9 +257,14 @@ public void shouldRequestToPublishCourtListForApplicationRestrictionOnOff() thro publishCourtListJsonObject = buildPublishCourtListJsonString(courtCentreId, "26"); + final int webPageCountBeforeSecondPublish = countFilesAt(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26); + final int pubDisplayCountBeforeSecondPublish = countSentXmlForPubDisplay(); + courtCentreId = sendPublishCourtListCommand(publishCourtListJsonObject, courtCentreId); publishCourtListSteps.verifyCourtListPublishStatusReturnedWhenQueryingFromAPI(courtCentreId); + awaitNewFile(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26, webPageCountBeforeSecondPublish); + awaitNewSentXmlForPubDisplay(pubDisplayCountBeforeSecondPublish); filePayload = getFileForPath(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26); filePayloadForPubDisplay = getSentXmlForPubDisplay(); @@ -273,11 +293,9 @@ public void shouldRequestToPublishCourtListForApplicationApplicantRestrictionOnO withJsonPath("$.courtApplicationApplicantIds", hasSize(1)), withJsonPath("$.restrictCourtList", is(true))))); - // Wait for applicant restriction to land in the projection before publishing. - // When restricted the applicant is nulled out and the defendant serialises as {} (no keys), - // so we assert on the object being empty rather than firstName being null (absent key ≠ null). + // Wait for applicant restriction to land in the projection before publishing courtListRestrictionSteps.waitForRestrictionProjection(courtCentreId, eventTime.toLocalDate(), - withJsonPath("$.court.courtSites[0].courtRooms[0].cases.casesDetails[0].defendants[0]", is(java.util.Collections.emptyMap()))); + hasNoJsonPath("$.court.courtSites[0].courtRooms[0].cases.casesDetails[0].defendants[0].firstName")); JsonObject publishCourtListJsonObject = buildPublishCourtListJsonString(courtCentreId, "26"); @@ -310,9 +328,14 @@ public void shouldRequestToPublishCourtListForApplicationApplicantRestrictionOnO publishCourtListJsonObject = buildPublishCourtListJsonString(courtCentreId, "26"); + final int webPageCountBeforeSecondPublish = countFilesAt(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26); + final int pubDisplayCountBeforeSecondPublish = countSentXmlForPubDisplay(); + courtCentreId = sendPublishCourtListCommand(publishCourtListJsonObject, courtCentreId); publishCourtListSteps.verifyCourtListPublishStatusReturnedWhenQueryingFromAPI(courtCentreId); + awaitNewFile(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26, webPageCountBeforeSecondPublish); + awaitNewSentXmlForPubDisplay(pubDisplayCountBeforeSecondPublish); filePayload = getFileForPath(XHIBIT_GATEWAY_SEND_WEB_PAGE_TO_XHIBIT_FILE_NAME_26); filePayloadForPubDisplay = getSentXmlForPubDisplay(); diff --git a/hearing-integration-test/src/test/java/uk/gov/moj/cpp/hearing/steps/CourtListRestrictionSteps.java b/hearing-integration-test/src/test/java/uk/gov/moj/cpp/hearing/steps/CourtListRestrictionSteps.java index aa7743c5a..77874087f 100644 --- a/hearing-integration-test/src/test/java/uk/gov/moj/cpp/hearing/steps/CourtListRestrictionSteps.java +++ b/hearing-integration-test/src/test/java/uk/gov/moj/cpp/hearing/steps/CourtListRestrictionSteps.java @@ -11,6 +11,7 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; import static uk.gov.justice.services.common.http.HeaderConstants.USER_ID; import static uk.gov.justice.services.test.utils.core.http.BaseUriProvider.getBaseUri; import static uk.gov.justice.services.test.utils.core.http.RequestParamsBuilder.requestParams; @@ -106,6 +107,12 @@ public JsonPath hearingEventsCourtListRestrictedReceived(final Matcher> matche * Required because {@link #hearingEventsCourtListRestrictedReceived(Matcher)} only confirms the * hearing event was emitted; the listener that projects it into the JPA entity runs in a * separate transaction and may lag behind the publish command if not waited for. + *
+ * A hearing-visibility precondition ({@code courtRoomId notNullValue}) is prepended to the
+ * caller's matcher to prevent the poll from short-circuiting on the empty/not-yet-projected
+ * state — without this, lenient matchers such as {@code hasNoJsonPath(...)} or
+ * {@code withJsonPath(..., hasSize(0))} would match an empty {@code {}} response and return
+ * before the restriction event has actually been processed.
*/
public void waitForRestrictionProjection(final String courtCentreId,
final LocalDate hearingDate,
@@ -118,7 +125,9 @@ public void waitForRestrictionProjection(final String courtCentreId,
.withHeader(USER_ID, getLoggedInSystemUserHeader()))
.timeout(60, SECONDS)
.pollInterval(1, SECONDS)
- .until(status().is(OK), payload().isJson(expectedPayload));
+ .until(status().is(OK), payload().isJson(allOf(
+ withJsonPath("$.court.courtSites[0].courtRooms[0].courtRoomId", notNullValue()),
+ expectedPayload)));
}
private void sendListingPublicEvent(final JsonObject restrictCourtListDataObject) {
@@ -137,7 +146,7 @@ public CommandHelpers.InitiateHearingCommandHelper createHearingEvent(final UUID
}
public CommandHelpers.InitiateHearingCommandHelper createHearingEventWithYoungDefendant(final UUID caseId, final UUID hearingEventId, final String courtRoomId, final String defenceCounselId,
- final UUID eventDefinitionId, final ZonedDateTime eventTime, final Optional