Skip to content

Commit

Permalink
HMAN-319 - add V2 "Submit event for case" endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivangareth committed Jul 20, 2022
1 parent 4cb9607 commit 356e4ac
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;
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.CaseResource;
import uk.gov.hmcts.reform.ccd.client.model.Event;
import uk.gov.hmcts.reform.ccd.client.model.StartEventResponse;

Expand Down Expand Up @@ -348,5 +349,36 @@ void saveSupplementaryData() {
assertThat(theCase.getId())
.isEqualTo(caseDetails.getId());
}

@Test
@DisplayName("Should be able to submit an event for a case")
void createEventForCase() {
CaseDetails caseDetails = createCase(caseWorker);

StartEventResponse startEventResponse = coreCaseDataApi.startEvent(
caseWorker.getAuthToken(),
authTokenGenerator.generate(),
caseDetails.getId() + "",
UPDATE_CASE_EVENT);

CaseDataContent caseDataContent = CaseDataContent.builder()
.caseReference(startEventResponse.getCaseDetails().getId().toString())
.data(startEventResponse.getCaseDetails().getData())
.event(Event.builder().id(UPDATE_CASE_EVENT).build())
.eventToken(startEventResponse.getToken())
.build();

CaseResource theCase = coreCaseDataApi.createEvent(
caseWorker.getAuthToken(),
authTokenGenerator.generate(),
caseDetails.getId() + "",
caseDataContent);

assertThat(theCase.getReference())
.isEqualTo(caseDetails.getId().toString());
assertThat(theCase.getData().get("TextField").asText())
.isEqualTo(caseDetails.getData().get("TextField").toString());
assertThat(theCase.getState()).isEqualTo("IN_PROGRESS");
}
}
}
2 changes: 1 addition & 1 deletion src/functionalTest/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ idam:
s2s-auth:
totp_secret: 'AAAAAAAAAAAAAAAA'
microservice: 'ccd_gateway'
url: 'http://localhost:4552'
url: 'http://localhost:4502'
api:
url: 'http://localhost:5000'
client:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -11,6 +12,7 @@
import uk.gov.hmcts.reform.ccd.client.healthcheck.InternalHealth;
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.CaseResource;
import uk.gov.hmcts.reform.ccd.client.model.PaginatedSearchMetadata;
import uk.gov.hmcts.reform.ccd.client.model.SearchResult;
import uk.gov.hmcts.reform.ccd.client.model.StartEventResponse;
Expand Down Expand Up @@ -288,7 +290,16 @@ StartEventResponse startEvent(
@PathVariable("caseId") String caseId,
@PathVariable("triggerId") String eventId
);


@PostMapping(
path = "/cases/{caseId}/events",
headers = EXPERIMENTAL
)
CaseResource createEvent(@RequestHeader(AUTHORIZATION) String userAuthorizationHeader,
@RequestHeader(SERVICE_AUTHORIZATION) String serviceAuthorization,
@PathVariable("caseId") String caseId,
@RequestBody CaseDataContent caseDataContent);

@RequestMapping(
method = RequestMethod.POST,
value = "/cases/{caseId}/supplementary-data"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package uk.gov.hmcts.reform.ccd.client.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.Map;

@Data
@EqualsAndHashCode
@NoArgsConstructor
public class CaseResource {

@JsonProperty("id")
private String reference;

@JsonProperty("jurisdiction")
private String jurisdiction;

@JsonProperty("case_type")
private String caseType;

@JsonProperty("created_on")
private LocalDateTime createdOn;

@JsonProperty("last_modified_on")
private LocalDateTime lastModifiedOn;

@JsonProperty("last_state_modified_on")
private LocalDateTime lastStateModifiedOn;

@JsonProperty("state")
private String state;

@JsonProperty("security_classification")
private Classification securityClassification;

@JsonProperty("data")
private Map<String, JsonNode> data;

@JsonProperty("data_classification")
private Map<String, JsonNode> dataClassification;

@JsonProperty("after_submit_callback_response")
@SuppressWarnings("squid:common-java:DuplicatedBlocks")
private SubmittedCallbackResponse afterSubmitCallbackResponse;

@JsonProperty("callback_response_status_code")
@SuppressWarnings("squid:common-java:DuplicatedBlocks")
private Integer callbackResponseStatusCode;

@JsonProperty("callback_response_status")
@SuppressWarnings("squid:common-java:DuplicatedBlocks")
private String callbackResponseStatus;

@JsonProperty("delete_draft_response_status_code")
@SuppressWarnings("squid:common-java:DuplicatedBlocks")
private Integer deleteDraftResponseStatusCode;

@JsonProperty("delete_draft_response_status")
@SuppressWarnings("squid:common-java:DuplicatedBlocks")
private String deleteDraftResponseStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import uk.gov.hmcts.reform.ccd.client.mock.CcdWireMock;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.ccd.client.model.Classification;
Expand All @@ -27,6 +28,7 @@
CoreCaseDataConfiguration.class,
CoreCaseDataApi.class
})
@DirtiesContext
@EnableAutoConfiguration
class CcdClientTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.MappingBuilder;
import com.github.tomakehurst.wiremock.core.Options;
import com.google.common.io.Resources;

import java.io.IOException;
Expand All @@ -12,7 +13,7 @@
import static org.springframework.http.HttpHeaders.AUTHORIZATION;

public class CcdWireMock {
private static final WireMockServer SERVER = new WireMockServer(8081);
private static final WireMockServer SERVER = new WireMockServer(Options.DYNAMIC_PORT);

private CcdWireMock() {
}
Expand Down

0 comments on commit 356e4ac

Please sign in to comment.