diff --git a/pom.xml b/pom.xml
index 484c5d4b..ad4a34f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
uk.gov.companieshouse
companies-house-parent
- 2.1.6
+ 2.1.10
psc-data-api
@@ -16,8 +16,8 @@
21
uk.gov.companieshouse.pscdataapi.PscDataApiApplication
- 3.3.1
- 3.3.1
+ 3.3.6
+ 3.3.6
${java.version}
${java.version}
3.3.0
@@ -25,8 +25,8 @@
0.8.12
- 3.0.8
- 4.0.241
+ 3.0.20
+ 4.0.249
1.0.6
2.0.5
3.0.5
@@ -71,7 +71,7 @@
log4j-to-slf4j
-
+
org.springframework.boot
spring-boot-starter-actuator
@@ -132,6 +132,12 @@
org.springframework.boot
spring-boot-starter-test
test
+
+
+ org.xmlunit
+ xmlunit-core
+
+
uk.gov.companieshouse
diff --git a/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java b/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java
index e63380f3..504f4e87 100644
--- a/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java
+++ b/src/itest/java/uk/gov/companieshouse/pscdataapi/steps/PscDataSteps.java
@@ -71,6 +71,12 @@
public class PscDataSteps {
+ private static final String KIND = "individual-person-with-significant-control";
+ private static final String DELTA_AT = "20240219123045999999";
+ private static final String COMPANY_NUMBER = "34777772";
+ private static final String NOTIFICATION_ID = "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ";
+ private static final String CONTEXT_ID = "5234234234";
+
@Autowired
private ObjectMapper objectMapper;
@Autowired
@@ -89,12 +95,6 @@ public class PscDataSteps {
@InjectMocks
private CompanyPscService companyPscService;
-
-
- private final String COMPANY_NUMBER = "34777772";
- private final String NOTIFICATION_ID = "ZfTs9WeeqpXTqf6dc6FZ4C0H0ZZ";
- private final String contextId = "5234234234";
-
private AutoCloseable autoCloseable;
@Before
@@ -144,12 +144,12 @@ public void chs_kafka_api_not_invoked() {
@Then("the CHS Kafka API is not invoked with a DELETE event")
public void chs_kafka_api_not_invoked_for_delete() {
- verify(chsKafkaApiService, times(0)).invokeChsKafkaApiWithDeleteEvent(any(), any(), any(), any(), any());
+ verify(chsKafkaApiService, times(0)).invokeChsKafkaApiWithDeleteEvent(any(), any());
}
@Then("the CHS Kafka API is invoked with a DELETE event")
public void chs_kafka_api_is_invoked_for_delete() {
- verify(chsKafkaApiService, times(1)).invokeChsKafkaApiWithDeleteEvent(any(), any(), any(), any(), any());
+ verify(chsKafkaApiService, times(1)).invokeChsKafkaApiWithDeleteEvent(any(), any());
}
@And("the CHS Kafka API service is not invoked")
@@ -162,8 +162,8 @@ public void i_send_psc_record_put_request_with_payload(String dataFile, String c
String data = FileReaderUtil.readFile("src/itest/resources/json/input/" + dataFile + ".json");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -181,8 +181,8 @@ public void i_send_psc_record_put_request_with_payload(String dataFile, String n
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -200,8 +200,8 @@ public void i_send_psc_data_put_request_with_payload(String dataFile, String not
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -237,8 +237,8 @@ public void aDELETERequestIsSentForWithoutValidERICHeaders(String companyNumber)
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri = "/company/{company_number}/persons-with-significant-control/{notification_id}/full_record";
@@ -249,15 +249,37 @@ public void aDELETERequestIsSentForWithoutValidERICHeaders(String companyNumber)
@When("a DELETE request is sent for {string}")
- public void aDELETERequestIsSentFor(String companyNumber) {
+ public void aDeleteRequestIsSentFor(String companyNumber) {
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
+ headers.set("ERIC-Identity", "TEST-IDENTITY");
+ headers.set("ERIC-Identity-Type", "key");
+ headers.set("ERIC-Authorised-Key-Roles", "*");
+ headers.set("x-kind", KIND);
+ headers.set("x-delta-at", DELTA_AT);
+
+ HttpEntity request = new HttpEntity<>(null, headers);
+ String uri = "/company/%s/persons-with-significant-control/%s/full_record".formatted(companyNumber, NOTIFICATION_ID);
+ ResponseEntity response = restTemplate.exchange(uri, HttpMethod.DELETE, request, Void.class);
+
+ CucumberContext.CONTEXT.set("statusCode", response.getStatusCode().value());
+ }
+
+ @When("a DELETE request is sent for {string} with a stale {string}")
+ public void aDeleteRequestIsSentFor(String companyNumber, String deltaAt) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
+ headers.set("x-kind", KIND);
+ headers.set("x-delta-at", deltaAt);
HttpEntity request = new HttpEntity<>(null, headers);
String uri = "/company/%s/persons-with-significant-control/%s/full_record".formatted(companyNumber, NOTIFICATION_ID);
@@ -279,7 +301,7 @@ public void theDatabaseIsDown() {
@When("the chs kafka api is not available")
public void theChsKafkaApiIsNotAvailable() {
doThrow(ServiceUnavailableException.class).when(chsKafkaApiService).invokeChsKafkaApi(any(), any(), any(), any());
- doThrow(ServiceUnavailableException.class).when(chsKafkaApiService).invokeChsKafkaApiWithDeleteEvent(any(), any(), any(), any(), any());
+ doThrow(ServiceUnavailableException.class).when(chsKafkaApiService).invokeChsKafkaApiWithDeleteEvent(any(), any());
}
@And("a PSC {string} exists for {string} for Super Secure")
@@ -311,8 +333,8 @@ public void aGetRequestIsSentForAndForSuperSecure(String companyNumber, String n
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -343,8 +365,8 @@ public void aGetRequestIsSentForAndWithoutERICHeadersForSuperSecure(String compa
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri =
@@ -361,8 +383,8 @@ public void aGetRequestHasBeenSentForAndForSuperSecure(String companyNumber, Str
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -405,8 +427,8 @@ public void aGetRequestIsSentForAndForSuperSecureBeneficialOwner(String companyN
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -438,8 +460,8 @@ public void aGetRequestIsSentForAndWithoutERICHeadersForSuperSecureBeneficialOwn
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri =
@@ -456,8 +478,8 @@ public void aGetRequestHasBeenSentForAndForSuperSecureBeneficialOwner(String com
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -521,8 +543,8 @@ public void aGetRequestIsSentForAndForCorporateEntity(String companyNumber, Stri
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -553,8 +575,8 @@ public void aGetRequestHasBeenSentForAndForCorporateEntity(String companyNumber,
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -573,8 +595,8 @@ public void aGetRequestIsSentForAndWithoutERICHeadersForCorporateEntity(String c
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri =
@@ -641,13 +663,69 @@ public void aPSCExistsFor(String dataFile, String companyNumber) throws JsonProc
assertThat(companyPscRepository.findById(NOTIFICATION_ID)).isNotEmpty();
}
+ @And("a PSC {string} exists for {string} for Individual with {string}")
+ public void pscExistsWithDeltaAt(String dataFile, String companyNumber, String deltaAt) throws JsonProcessingException {
+ String pscDataFile = FileReaderUtil.readFile("src/itest/resources/json/input/" + dataFile + ".json");
+ PscData pscData = objectMapper.readValue(pscDataFile, PscData.class);
+ PscSensitiveData pscSensitiveData = objectMapper.readValue(pscDataFile, PscSensitiveData.class);
+ PscDocument document = new PscDocument();
+
+ document.setId(NOTIFICATION_ID);
+ document.setCompanyNumber(companyNumber);
+ document.setPscId(NOTIFICATION_ID);
+ document.setDeltaAt("20231120084745378000");
+ pscData.setEtag("string");
+ pscData.setCeasedOn(LocalDate.from(LocalDateTime.now()));
+ pscData.setKind("individual-person-with-significant-control");
+ pscData.setCountryOfResidence("United Kingdom");
+ pscData.setName(companyNumber);
+ NameElements nameElements = new NameElements();
+ nameElements.setTitle("Mr");
+ nameElements.setForename("PHIL");
+ nameElements.setMiddleName("tom");
+ nameElements.setSurname("JONES");
+ pscData.setNameElements(nameElements);
+ DateOfBirth dateOfBirth = new DateOfBirth();
+ dateOfBirth.setDay(2);
+ dateOfBirth.setMonth(3);
+ dateOfBirth.setYear(1994);
+ pscSensitiveData.setDateOfBirth(dateOfBirth);
+ document.setSensitiveData(pscSensitiveData);
+ Links links = new Links();
+ links.setSelf("/company/" + companyNumber + "/persons-with-significant-control/individual/" + NOTIFICATION_ID);
+ links.setStatement("string");
+ pscData.setLinks(links);
+ pscData.setNationality("British");
+ Address address = new Address();
+ address.setAddressLine1("ura_line1");
+ address.setAddressLine2("ura_line2");
+ address.setCareOf("ura_care_of");
+ address.setCountry("United Kingdom");
+ address.setLocality("Cardiff");
+ address.setPoBox("ura_po");
+ address.setPostalCode("CF2 1B6");
+ address.setPremises("URA");
+ address.setRegion("ura_region");
+ pscData.setAddress(address);
+ pscSensitiveData.setUsualResidentialAddress(address);
+ pscSensitiveData.setResidentialAddressIsSameAsServiceAddress(true);
+ List list = new ArrayList<>();
+ list.add("part-right-to-share-surplus-assets-75-to-100-percent");
+ pscData.setNaturesOfControl(list);
+ document.setData(pscData);
+ document.setDeltaAt(deltaAt);
+
+ mongoTemplate.save(document);
+ assertThat(companyPscRepository.findById(NOTIFICATION_ID)).isNotEmpty();
+ }
+
@When("a Get request is sent for {string} and {string} for Individual")
public void aGetRequestIsSentForAnd(String companyNumber, String notification_id) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -664,7 +742,7 @@ public void aGetRequestIsSentForAnd(String companyNumber, String notification_id
@When("an {string} Get request is sent for {string} and {string} for Individual Full Record")
public void aGetFullRecordRequestIsSentForAnd(final String auth, final String companyNumber, final String notification_id) {
final HttpHeaders headers = setupHeaders(!"unauthenticated".equals(auth), "authorized".equals(auth) ? "*": "");
- CucumberContext.CONTEXT.set("contextId", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
final HttpEntity request = new HttpEntity<>(null, headers);
@@ -681,7 +759,7 @@ private HttpHeaders setupHeaders(final boolean includeEric, final String keyRole
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- headers.set("x-request-id", this.contextId);
+ headers.set("x-request-id", CONTEXT_ID);
if (includeEric) {
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
@@ -697,8 +775,8 @@ public void aGetFullRecordRequestIsSentWithoutEricHeadersForAnd(final String com
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -743,8 +821,8 @@ public void aGetRequestIsSentForAndWithoutERICHeaders(String companyNumber, Stri
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri = "/company/{company_number}/persons-with-significant-control/individual/{notification_id}";
@@ -760,8 +838,8 @@ public void aGetRequestHasBeenSentForAnd(String companyNumber, String notificati
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -807,8 +885,8 @@ public void aGetRequestIsSentForAndForIndividualBeneficialOwner(String companyNu
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -839,8 +917,8 @@ public void aGetRequestHasBeenSentForAndForIndividualBeneficialOwner(String comp
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -859,8 +937,8 @@ public void aGetRequestIsSentForAndWithoutERICHeadersForIndividualBeneficialOwne
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri = "/company/{company_number}/persons-with-significant-control/individual-beneficial-owner/{notification_id}";
@@ -909,8 +987,8 @@ public void aGetRequestIsSentForAndForCorporateEntityBeneficialOwner(String comp
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -943,8 +1021,8 @@ public void aGetRequestIsSentForAndWithoutERICHeadersForCorporateEntityBeneficia
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri = "/company/{company_number}/persons-with-significant-control/corporate-entity-beneficial-owner/{notification_id}";
@@ -960,8 +1038,8 @@ public void aGetRequestHasBeenSentForAndForCorporateEntityBeneficialOwner(String
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -1002,8 +1080,8 @@ public void aGetRequestIsSentForAndForLegalPerson(String companyNumber, String n
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -1034,8 +1112,8 @@ public void aGetRequestIsSentForAndWithoutERICHeadersForLegalPerson(String compa
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri = "/company/{company_number}/persons-with-significant-control/legal-person/{notification_id}";
@@ -1051,8 +1129,8 @@ public void aGetRequestHasBeenSentForAndForLegalPerson(String companyNumber, Str
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -1103,8 +1181,8 @@ public void aGetRequestIsSentForAndForLegalPersonBeneficialOwner(String companyN
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -1137,8 +1215,8 @@ public void aGetRequestIsSentForAndWithoutERICHeadersForLegalPersonBeneficialOwn
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri = "/company/{company_number}/persons-with-significant-control/legal-person-beneficial-owner/{notification_id}";
@@ -1154,8 +1232,8 @@ public void aGetRequestHasBeenSentForAndForLegalPersonBeneficialOwner(String com
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -1247,8 +1325,8 @@ public void aGetRequestIsSentForForListSummary(String companyNumber) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -1268,8 +1346,8 @@ public void aGetRequestIsSentForForListSummaryRegisterView(String companyNumber)
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
headers.set("ERIC-Identity", "TEST-IDENTITY");
headers.set("ERIC-Identity-Type", "key");
headers.set("ERIC-Authorised-Key-Roles", "*");
@@ -1301,8 +1379,8 @@ public void aGetRequestIsSentForWithoutERICHeadersForListSummary(String companyN
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- CucumberContext.CONTEXT.set("contextId", this.contextId);
- headers.set("x-request-id", this.contextId);
+ CucumberContext.CONTEXT.set("contextId", CONTEXT_ID);
+ headers.set("x-request-id", CONTEXT_ID);
HttpEntity request = new HttpEntity<>(null, headers);
String uri =
diff --git a/src/itest/resources/features/delete_psc.feature b/src/itest/resources/features/delete_psc.feature
index 8ab70b8c..61a52f39 100644
--- a/src/itest/resources/features/delete_psc.feature
+++ b/src/itest/resources/features/delete_psc.feature
@@ -21,10 +21,11 @@ Feature: Delete PSC
| company_number |
| 34777772 |
- Scenario Outline: Delete PSC unsuccessfully - PSC resource does not exist
+ Scenario Outline: Delete PSC unsuccessfully but chs-kafka-api invoked - PSC resource does not exist
Given a PSC does not exist for ""
When a DELETE request is sent for ""
- Then I should receive 404 status code
+ Then the CHS Kafka API is invoked with a DELETE event
+ And I should receive 200 status code
Examples:
| company_number |
@@ -41,3 +42,14 @@ Feature: Delete PSC
Examples:
| company_number |
| 34777772 |
+
+ Scenario Outline: Delete PSC throws conflict exception if deltaAt is stale
+ Given Psc data api service is running
+ And a PSC "" exists for "" for Individual with ""
+ When a DELETE request is sent for "" with a stale ""
+ Then I should receive 409 status code
+ And the CHS Kafka API is not invoked with a DELETE event
+
+ Examples:
+ | data | company_number | existingDeltaAt | deltaAt |
+ | get_individual | 34777772 | 20231020084745378999 | 20230724093435661593 |
\ No newline at end of file
diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/api/ChsKafkaApiService.java b/src/main/java/uk/gov/companieshouse/pscdataapi/api/ChsKafkaApiService.java
index eb68bffd..9aa1e9d5 100644
--- a/src/main/java/uk/gov/companieshouse/pscdataapi/api/ChsKafkaApiService.java
+++ b/src/main/java/uk/gov/companieshouse/pscdataapi/api/ChsKafkaApiService.java
@@ -7,7 +7,6 @@
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
-
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import uk.gov.companieshouse.api.InternalApiClient;
@@ -19,6 +18,7 @@
import uk.gov.companieshouse.logging.Logger;
import uk.gov.companieshouse.pscdataapi.exceptions.SerDesException;
import uk.gov.companieshouse.pscdataapi.exceptions.ServiceUnavailableException;
+import uk.gov.companieshouse.pscdataapi.models.PscDeleteRequest;
import uk.gov.companieshouse.pscdataapi.models.PscDocument;
import uk.gov.companieshouse.pscdataapi.transform.CompanyPscTransformer;
import uk.gov.companieshouse.pscdataapi.util.PscTransformationHelper;
@@ -44,7 +44,7 @@ public class ChsKafkaApiService {
private String resourceChangedUri;
public ChsKafkaApiService(InternalApiClient internalApiClient, Logger logger,
- ObjectMapper objectMapper, CompanyPscTransformer companyPscTransformer) {
+ ObjectMapper objectMapper, CompanyPscTransformer companyPscTransformer) {
this.internalApiClient = internalApiClient;
this.logger = logger;
this.objectMapper = objectMapper;
@@ -62,7 +62,7 @@ public ChsKafkaApiService(InternalApiClient internalApiClient, Logger logger,
@StreamEvents
public ApiResponse invokeChsKafkaApi(String contextId, String companyNumber,
- String notificationId, String kind) {
+ String notificationId, String kind) {
internalApiClient.setBasePath(chsKafkaApiUrl);
PrivateChangedResourcePost changedResourcePost = internalApiClient
.privateChangedResourceHandler().postChangedResource(resourceChangedUri,
@@ -74,28 +74,22 @@ public ApiResponse invokeChsKafkaApi(String contextId, String companyNumbe
/**
* Creates a ChangedResource object to send a delete request to the chs kafka api.
*
- * @param contextId chs kafka id
- * @param companyNumber company number of psc
- * @param notificationId mongo id
* @return passes request to api response handling
*/
@StreamEvents
- public ApiResponse invokeChsKafkaApiWithDeleteEvent(String contextId,
- String companyNumber,
- String notificationId,
- String kind, PscDocument pscDocument) {
+ public ApiResponse invokeChsKafkaApiWithDeleteEvent(PscDeleteRequest deleteRequest, PscDocument pscDocument) {
+
internalApiClient.setBasePath(chsKafkaApiUrl);
PrivateChangedResourcePost changedResourcePost =
internalApiClient.privateChangedResourceHandler()
.postChangedResource(resourceChangedUri,
- mapChangedResource(contextId, companyNumber,
- notificationId, kind, true, pscDocument));
+ mapChangedResource(deleteRequest.contextId(), deleteRequest.companyNumber(),
+ deleteRequest.notificationId(), deleteRequest.kind(), true, pscDocument));
return handleApiCall(changedResourcePost);
}
- private ChangedResource mapChangedResource(String contextId, String companyNumber,
- String notificationId,
- String kind, boolean isDelete, PscDocument pscDocument) {
+ private ChangedResource mapChangedResource(String contextId, String companyNumber, String notificationId,
+ String kind, boolean isDelete, PscDocument pscDocument) {
ChangedResourceEvent event = new ChangedResourceEvent();
ChangedResource changedResource = new ChangedResource();
event.setPublishedAt(PUBLISHED_AT_FORMAT.format(Instant.now()));
diff --git a/src/main/java/uk/gov/companieshouse/pscdataapi/config/ExceptionHandlerConfig.java b/src/main/java/uk/gov/companieshouse/pscdataapi/config/ExceptionHandlerConfig.java
index 35527897..67561010 100644
--- a/src/main/java/uk/gov/companieshouse/pscdataapi/config/ExceptionHandlerConfig.java
+++ b/src/main/java/uk/gov/companieshouse/pscdataapi/config/ExceptionHandlerConfig.java
@@ -16,6 +16,7 @@
import org.springframework.web.context.request.WebRequest;
import uk.gov.companieshouse.logging.Logger;
import uk.gov.companieshouse.pscdataapi.exceptions.BadRequestException;
+import uk.gov.companieshouse.pscdataapi.exceptions.ConflictException;
import uk.gov.companieshouse.pscdataapi.exceptions.MethodNotAllowedException;
import uk.gov.companieshouse.pscdataapi.exceptions.SerDesException;
import uk.gov.companieshouse.pscdataapi.exceptions.ServiceUnavailableException;
@@ -133,4 +134,24 @@ public ResponseEntity