From 7052ce5d75101f66f0489d55ff99df5a193f8b40 Mon Sep 17 00:00:00 2001 From: Arcadius Ahouansou Date: Fri, 5 Jun 2026 10:22:40 +0100 Subject: [PATCH] further int test fixes --- .../steps/CourtListRestrictionSteps.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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 849e1b598..6fb6f8999 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 @@ -130,6 +130,33 @@ public void waitForRestrictionProjection(final String courtCentreId, expectedPayload))); } + /** + * Polls the publish-side query {@code hearing.latest-hearings-by-court-centres} until the + * just-created hearing is observable. MUST be called after {@code createHearingEvent*} and + * BEFORE any {@code hide*FromXhibit} call. + *

+ * Without this wait, the {@code public.listing.court-list-restricted} → ... → + * {@code hearing.event.court-list-restricted} chain can reach + * {@link uk.gov.moj.cpp.hearing.event.listener.CourtListRestrictionEventListener} before the + * hearing-creation projection has committed to {@code ha_hearing}. The listener does + * {@code hearingRepository.findOptionalBy(hearingId)} and, if the row is missing, silently + * returns (the message is consumed and never replayed). The restriction is then lost, the + * subsequent publish reads the un-restricted hearing, and the assertion on the redacted XML + * fails. This flake reproduced ~2/3 of CI runs on team/rv-2616. + */ + public void waitForHearingVisible(final String courtCentreId, final LocalDate hearingDate) { + setupAsAuthorizedAndSystemUser(USER_ID_VALUE_AS_ADMIN); + final String queryPart = format(ENDPOINT_PROPERTIES.getProperty("hearing.latest-hearings-by-court-centres"), courtCentreId, hearingDate); + final String searchCourtListUrl = String.format("%s/%s", getBaseUri(), queryPart); + + poll(requestParams(searchCourtListUrl, "application/vnd.hearing.latest-hearings-by-court-centres+json") + .withHeader(USER_ID, getLoggedInSystemUserHeader())) + .timeout(60, SECONDS) + .pollInterval(1, SECONDS) + .until(status().is(OK), payload().isJson( + withJsonPath("$.court.courtSites[0].courtRooms[0].courtRoomId", notNullValue()))); + } + private void sendListingPublicEvent(final JsonObject restrictCourtListDataObject) { sendMessage( getPublicTopicInstance().createProducer(), @@ -142,11 +169,12 @@ public CommandHelpers.InitiateHearingCommandHelper createHearingEvent(final UUID final UUID eventDefinitionId, final ZonedDateTime eventTime, final Optional hearingTypeId, String courtCenter, LocalDate localDate) throws NoSuchAlgorithmException { final CommandHelpers.InitiateHearingCommandHelper hearing = h(UseCases.initiateHearingWithNsp(getRequestSpec(), initiateHearingTemplateWithParamNoReportingRestriction(fromString(courtCenter), fromString(courtRoomId), "CourtRoom 1", localDate, fromString(defenceCounselId), caseId, hearingTypeId))); logEvent(hearingEventId, getRequestSpec(), asDefault(), hearing.it(), eventDefinitionId, false, fromString(defenceCounselId), eventTime, null); + waitForHearingVisible(courtCenter, eventTime.toLocalDate()); return hearing; } public CommandHelpers.InitiateHearingCommandHelper createHearingEventWithYoungDefendant(final UUID caseId, final UUID hearingEventId, final String courtRoomId, final String defenceCounselId, - final UUID eventDefinitionId, final ZonedDateTime eventTime, final Optional hearingTypeId, final String courtCenter, final LocalDate localDate) throws NoSuchAlgorithmException { + final UUID eventDefinitionId, final ZonedDateTime eventTime, final Optional hearingTypeId, final String courtCenter, final LocalDate localDate) throws NoSuchAlgorithmException { try (final Utilities.EventListener eventListener = listenFor(HEARING_EVENTS_COURT_LIST_RESTRICTED, HEARING_EVENT) .withFilter(isJson(allOf( withJsonPath("$.defendantIds", hasSize(1)), @@ -155,6 +183,7 @@ public CommandHelpers.InitiateHearingCommandHelper createHearingEventWithYoungDe initiateHearingTemplateWithParamNoReportingRestrictionYoungDefendant(fromString(courtCenter), fromString(courtRoomId), "CourtRoom 1", localDate, fromString(defenceCounselId), caseId, hearingTypeId))); logEvent(hearingEventId, getRequestSpec(), asDefault(), hearing.it(), eventDefinitionId, false, fromString(defenceCounselId), eventTime, null); eventListener.waitFor(); + waitForHearingVisible(courtCenter, eventTime.toLocalDate()); return hearing; } } @@ -164,6 +193,7 @@ public CommandHelpers.InitiateHearingCommandHelper createHearingEventForApplicat final CommandHelpers.InitiateHearingCommandHelper hearing = h(initiateHearingForApplication(getRequestSpec(), initiateHearingTemplateForApplicationNoReportingRestriction(fromString(courtCenter), fromString(courtRoomId), "CourtRoom 1", localDate, fromString(defenceCounselId), caseId, hearingTypeId))); givenAUserHasLoggedInAsACourtClerk(randomUUID()); logEvent(hearingEventId, getRequestSpec(), asDefault(), hearing.it(), eventDefinitionId, false, fromString(defenceCounselId), eventTime, null); + waitForHearingVisible(courtCenter, eventTime.toLocalDate()); return hearing; }