Skip to content
Merged
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
@@ -1,5 +1,6 @@
package uk.gov.moj.cpp.progression;

import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.withJsonPath;
import static java.util.UUID.randomUUID;
import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -32,6 +33,10 @@
@SuppressWarnings("squid:S1607")
public class CreateCourtApplicationIT extends AbstractIT {
private static final String COURT_APPLICATION_CREATED = "public.progression.court-application-created";
private static final String MH_ACTIVE_CASE_FIXTURE =
"applications/progression.initiate-court-proceedings-mh-source-active-case.json";
private static final String MH_INACTIVE_CASE_FIXTURE =
"applications/progression.initiate-court-proceedings-mh-source-inactive-case.json";

private final JmsMessageConsumerClient consumerForCourtApplicationCreated = newPublicJmsMessageConsumerClientProvider().withEventNames(COURT_APPLICATION_CREATED).getMessageConsumerClient();

Expand Down Expand Up @@ -109,6 +114,55 @@ public void shouldCreateCourtApplicationLinkedWithCaseAndGetConfirmation() throw
pollProsecutionCasesProgressionFor(caseId, caseMatchers);
}

@Test
public void shouldNotStoreOffencesWhenApplicationSourceIsMHAndCaseIsActive() throws Exception {
addProsecutionCaseToCrownCourt(caseId, defendantId);
pollProsecutionCasesProgressionFor(caseId, getProsecutionCaseMatchers(caseId, defendantId));

final String applicationId = randomUUID().toString();

initiateCourtProceedingsForCourtApplication(applicationId, caseId, MH_ACTIVE_CASE_FIXTURE);

verifyCourtApplicationCreatedEventPublished(applicationId);

final Matcher[] matchers = {
withJsonPath("$.courtApplication.id", is(applicationId)),
withJsonPath("$.courtApplication.applicationStatus", notNullValue()),
hasNoJsonPath("$.courtApplication.courtApplicationCases[0].offences")
};

pollForApplication(applicationId, matchers);
}

@Test
public void shouldPreserveOffencesWhenApplicationSourceIsMHAndCaseIsInactive() throws Exception {
final String defendantId = randomUUID().toString();
addProsecutionCaseToCrownCourt(caseId, defendantId);
pollProsecutionCasesProgressionFor(caseId, getProsecutionCaseMatchers(caseId, defendantId));

final String applicationId = randomUUID().toString();

initiateCourtProceedingsForCourtApplication(applicationId, caseId, MH_INACTIVE_CASE_FIXTURE);

verifyCourtApplicationCreatedEventPublished(applicationId);

final Matcher[] matchers = {
withJsonPath("$.courtApplication.id", is(applicationId)),
withJsonPath("$.courtApplication.courtApplicationCases[0].caseStatus", is("INACTIVE")),
withJsonPath("$.courtApplication.courtApplicationCases[0].offences[0]", notNullValue()),
withJsonPath("$.courtApplication.courtApplicationCases[0].offences[0].offenceCode", is("CA03012"))
};

pollForApplication(applicationId, matchers);
}

private void verifyCourtApplicationCreatedEventPublished(final String applicationId) {
final Optional<JsonObject> message = retrieveMessageBody(consumerForCourtApplicationCreated);
assertTrue(message.isPresent(), "Expected court-application-created event on JMS topic");
final String idFromEvent = message.get().getJsonObject("courtApplication").getString("id");
assertThat(idFromEvent, equalTo(applicationId));
}

private void verifyInMessagingQueueForCourtApplicationCreated(String applicationId) {
final Optional<JsonObject> message = retrieveMessageBody(consumerForCourtApplicationCreated);
assertTrue(message.isPresent());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"caseStatus": "ACTIVE",
"offences": [
{
"id": "OFFENCE_ID",
"id": "3ebe41c9-666d-4964-aa80-a005d89927a4",
"chargeDate": "2020-03-14",
"count": 1,
"isDisposed": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"caseStatus": "INACTIVE",
"offences": [
{
"id": "OFFENCE_ID",
"id": "9ce6e439-d5da-4202-a446-ef4ca7072530",
"chargeDate": "2020-03-14",
"count": 1,
"isDisposed": true,
Expand Down
Loading