Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import uk.gov.moj.sjp.it.command.CreateCase;
import uk.gov.moj.sjp.it.commandclient.AssignNextCaseClient;
import uk.gov.moj.sjp.it.helper.AssignmentHelper;
import uk.gov.moj.sjp.it.helper.CaseHelper;
import uk.gov.moj.sjp.it.helper.OffencesWithdrawalRequestHelper;
import uk.gov.moj.sjp.it.helper.SessionHelper;

Expand Down Expand Up @@ -248,6 +249,9 @@ void nonLondonCourtsShouldHandleOnlyNonTflCases() {
void shouldHandleConcurrentAssignmentRequestFromMultipleLegalAdvisers() {
final Map<UUID, UUID> sessionIdByUserId = Stream.generate(UUID::randomUUID).limit(3).collect(toMap(identity(), la -> randomUUID()));

CaseHelper.pollUntilCaseReady(tflOldPiaCasePayloadBuilder.getId());
CaseHelper.pollUntilCaseReady(tflOldPiaCasePayloadBuilder.getId());
CaseHelper.pollUntilCaseReady(tflPleadedGuiltyCasePayloadBuilder.getId());
sessionIdByUserId
.entrySet()
.parallelStream()
Expand Down Expand Up @@ -292,6 +296,8 @@ private static void verifyCaseAssigned(final String courtHouseOUCode, final Sess

SessionHelper.startSessionAndConfirm(sessionId, userId, courtHouseOUCode, sessionType);

CaseHelper.pollUntilCaseReady(caseId);

requestCaseAssignmentAndConfirm(sessionId, userId, caseId);
pollUntilCaseAssignedToUser(caseId, userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import uk.gov.moj.sjp.it.commandclient.CreateCaseClient;
import uk.gov.moj.sjp.it.commandclient.UnassignCaseClient;
import uk.gov.moj.sjp.it.helper.AssignmentHelper;
import uk.gov.moj.sjp.it.helper.CaseHelper;
import uk.gov.moj.sjp.it.model.Defendant;
import uk.gov.moj.sjp.it.model.ProsecutingAuthority;
import uk.gov.moj.sjp.it.util.CaseAssignmentRestrictionHelper;
Expand Down Expand Up @@ -67,6 +68,10 @@ public void setUp() throws SQLException {
Optional<Response> createCaseResponse = createCase.getExecutor().executeSync();
assertThat(createCaseResponse.get().getStatus(), equalTo(202));

long start = System.currentTimeMillis();
CaseHelper.pollUntilCaseReady(CASE_ID);
log.info("Case became ready after {} md", System.currentTimeMillis() - start);

startSessionAndConfirm(SESSION_ID, DEFAULT_USER.getUserId(), COURT_HOUSE_OU_CODE, SessionType.MAGISTRATE);
requestCaseAssignmentAndConfirm(SESSION_ID, DEFAULT_USER.getUserId(), createCase.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import static uk.gov.moj.sjp.it.util.SjpDatabaseCleaner.cleanViewStore;
import static uk.gov.moj.sjp.it.verifier.PersonInfoVerifier.personInfoVerifierForPersonalDetails;

import org.json.JSONArray;
import uk.gov.justice.json.schemas.domains.sjp.Gender;
import uk.gov.justice.json.schemas.domains.sjp.User;
import uk.gov.justice.services.common.converter.StringToJsonObjectConverter;
Expand All @@ -87,12 +88,7 @@
import uk.gov.moj.cpp.sjp.persistence.entity.PersonalDetails;
import uk.gov.moj.sjp.it.command.CreateCase;
import uk.gov.moj.sjp.it.command.UpdateDefendantDetails;
import uk.gov.moj.sjp.it.helper.CaseSearchResultHelper;
import uk.gov.moj.sjp.it.helper.CitizenHelper;
import uk.gov.moj.sjp.it.helper.EmployerHelper;
import uk.gov.moj.sjp.it.helper.EventListener;
import uk.gov.moj.sjp.it.helper.FinancialMeansHelper;
import uk.gov.moj.sjp.it.helper.PleadOnlineHelper;
import uk.gov.moj.sjp.it.helper.*;
import uk.gov.moj.sjp.it.model.DecisionCommand;
import uk.gov.moj.sjp.it.model.PleasView;
import uk.gov.moj.sjp.it.model.ProsecutingAuthority;
Expand Down Expand Up @@ -266,15 +262,22 @@ public void shouldPleadOnlineMultiOffencesWithPublicEvent() throws IOException {
PleasView pleasView = objectMapper.readValue(pleaResponse, PleasView.class);
final JSONObject defendantsPlea = new JSONObject(objectMapper.writeValueAsString(pleasView.getPleas().get(0)));

assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(0).get("offenceId"), equalTo(offenceId1.toString()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(0).get("plea"), equalTo(pleaType1.name()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(0).get("mitigation"), equalTo("I was drunk at the time"));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(1).get("offenceId"), equalTo(offenceId2.toString()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(1).get("plea"), equalTo(pleaType2.name()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(1).get("notGuiltyBecause"), equalTo("I was forced to do it"));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(2).get("offenceId"), equalTo(offenceId3.toString()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(2).get("plea"), equalTo(pleaType3.name()));
assertFalse(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(2).has("mitigation"));
final JSONArray onlinePleaDetails = defendantsPlea.getJSONArray("onlinePleaDetails");

final JSONObject plea1 = findPleaDetailByOffenceId(onlinePleaDetails, offenceId1);
assertThat(plea1.get("offenceId"), equalTo(offenceId1.toString()));
assertThat(plea1.get("plea"), equalTo(pleaType1.name()));
assertThat(plea1.get("mitigation"), equalTo("I was drunk at the time"));

final JSONObject plea2 =findPleaDetailByOffenceId(onlinePleaDetails, offenceId2);
assertThat(plea2.get("offenceId"), equalTo(offenceId2.toString()));
assertThat(plea2.get("plea"), equalTo(pleaType2.name()));
assertThat(plea2.get("notGuiltyBecause"), equalTo("I was forced to do it"));

final JSONObject plea3 = findPleaDetailByOffenceId(onlinePleaDetails, offenceId3);
assertThat(plea3.get("offenceId"), equalTo(offenceId3.toString()));
assertThat(plea3.get("plea"), equalTo(pleaType3.name()));
assertFalse(plea3.has("mitigation"));
assertThat(defendantsPlea.getJSONObject("personalDetails").get("firstName"), equalTo("Testy"));
assertThat(defendantsPlea.getJSONObject("personalDetails").get("lastName"), equalTo("LLOYD"));
assertThat(defendantsPlea.getJSONObject("personalDetails").getJSONObject("address").get("address1"), equalTo("14 Tottenham Court Road"));
Expand Down Expand Up @@ -531,15 +534,23 @@ public void shouldPleadOnlineWithUnchangedPersonalDetails() throws IOException {
PleasView pleasView = objectMapper.readValue(pleaResponse, PleasView.class);
final JSONObject defendantsPlea = new JSONObject(objectMapper.writeValueAsString(pleasView.getPleas().get(0)));

assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(0).get("offenceId"), equalTo(offenceId1.toString()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(0).get("plea"), equalTo(pleaType1.name()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(0).get("mitigation"), equalTo("I was drunk at the time"));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(1).get("offenceId"), equalTo(offenceId2.toString()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(1).get("plea"), equalTo(pleaType2.name()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(1).get("notGuiltyBecause"), equalTo("I was forced to do it"));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(2).get("offenceId"), equalTo(offenceId3.toString()));
assertThat(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(2).get("plea"), equalTo(pleaType3.name()));
assertFalse(defendantsPlea.getJSONArray("onlinePleaDetails").getJSONObject(2).has("mitigation"));
final JSONArray onlinePleaDetails = defendantsPlea.getJSONArray("onlinePleaDetails");

final JSONObject plea1 = findPleaDetailByOffenceId(onlinePleaDetails, offenceId1);

assertThat(plea1.get("offenceId"), equalTo(offenceId1.toString()));
assertThat(plea1.get("plea"), equalTo(pleaType1.name()));
assertThat(plea1.get("mitigation"), equalTo("I was drunk at the time"));

final JSONObject plea2 = findPleaDetailByOffenceId(onlinePleaDetails, offenceId2);
assertThat(plea2.get("offenceId"), equalTo(offenceId2.toString()));
assertThat(plea2.get("plea"), equalTo(pleaType2.name()));
assertThat(plea2.get("notGuiltyBecause"), equalTo("I was forced to do it"));

final JSONObject plea3 = findPleaDetailByOffenceId(onlinePleaDetails, offenceId3);
assertThat(plea3.get("offenceId"), equalTo(offenceId3.toString()));
assertThat(plea3.get("plea"), equalTo(pleaType3.name()));
assertFalse(plea3.has("mitigation"));
assertThat(defendantsPlea.getJSONObject("personalDetails").get("firstName"), equalTo("David"));
assertThat(defendantsPlea.getJSONObject("personalDetails").get("lastName"), equalTo("LLOYD"));
assertThat(defendantsPlea.getJSONObject("personalDetails").getJSONObject("address").get("address1"), equalTo("14 Tottenham Court Road"));
Expand Down Expand Up @@ -1000,6 +1011,7 @@ public void shouldRejectOnlinePleaIfCaseIsReferredForCourtHearing() {
stubReferralReason(referralReasonId.toString(), "stub-data/referencedata.referral-reason.json");
stubHearingTypesQuery(HEARING_TYPE_ID.toString(), HEARING_CODE, HEARING_DESCRIPTION);
startSessionAndConfirm(sjpSessionId, legalAdviser.getUserId(), DEFAULT_LONDON_COURT_HOUSE_OU_CODE, MAGISTRATE);
CaseHelper.pollUntilCaseReady(createCasePayloadBuilder.getId());
requestCaseAssignmentAndConfirm(sjpSessionId, legalAdviser.getUserId(), createCasePayloadBuilder.getId());
final DefendantCourtOptions defendantCourtOptions = new DefendantCourtOptions(new DefendantCourtInterpreter("French", true), false, NO_DISABILITY_NEEDS);
final ReferForCourtHearing referForCourtHearing = new ReferForCourtHearing(null, singletonList(new OffenceDecisionInformation(offenceId, VerdictType.NO_VERDICT)),
Expand Down Expand Up @@ -1745,4 +1757,14 @@ private JsonObject getUpdatedDefendantDetails() {
assertThat(response.getStatus(), Matchers.equalTo(Response.Status.OK.getStatusCode()));
return createReader(new StringReader(response.readEntity(String.class))).readObject();
}

private static JSONObject findPleaDetailByOffenceId(JSONArray onlinePleaDetails, UUID offenceId) {
for (int i=0; i < onlinePleaDetails.length(); i++) {
JSONObject entry = onlinePleaDetails.getJSONObject(i);
if (entry.get("offenceId").equals(offenceId.toString())) {
return entry;
}
}
throw new AssertionError("No plea detail found for offenceId" + offenceId);
}
}
Loading