Skip to content

Commit 3cbd95c

Browse files
authored
Merge pull request #12 from companieshouse/feature/change-return-status-code
Change returned status to 201
2 parents f531a52 + 4a5222f commit 3cbd95c

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

src/main/java/uk/gov/companieshouse/pscdataapi/controller/CompanyPscController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package uk.gov.companieshouse.pscdataapi.controller;
22

33
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.http.HttpStatus;
45
import org.springframework.http.ResponseEntity;
56
import org.springframework.web.bind.annotation.PutMapping;
67
import org.springframework.web.bind.annotation.RequestBody;
@@ -37,7 +38,7 @@ public ResponseEntity<Void> submitPscData(@RequestHeader("x-request-id") String
3738
try {
3839
LOGGER.info("Payload received, inserting record...");
3940
pscService.insertPscRecord(contextId, request);
40-
return ResponseEntity.ok().build();
41+
return ResponseEntity.status(HttpStatus.CREATED).build();
4142
} catch (ServiceUnavailableException exception) {
4243
LOGGER.info(exception.getMessage());
4344
return ResponseEntity.internalServerError().build();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package uk.gov.companieshouse.pscdataapi.controller;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.boot.test.mock.mockito.MockBean;
8+
import org.springframework.test.web.servlet.MockMvc;
9+
import uk.gov.companieshouse.api.psc.FullRecordCompanyPSCApi;
10+
import uk.gov.companieshouse.pscdataapi.service.CompanyPscService;
11+
import uk.gov.companieshouse.pscdataapi.util.TestHelper;
12+
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
import static org.mockito.ArgumentMatchers.anyString;
15+
import static org.mockito.ArgumentMatchers.isA;
16+
import static org.mockito.Mockito.doNothing;
17+
import static org.springframework.http.MediaType.APPLICATION_JSON;
18+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
19+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
20+
21+
@SpringBootTest
22+
@AutoConfigureMockMvc
23+
class CompanyPscControllerTest {
24+
private static final String PUT_URL =
25+
"/company/123456789/persons-with-significant-control/123456789/full_record";
26+
private static final String X_REQUEST_ID = "123456";
27+
28+
@MockBean
29+
private CompanyPscService companyPscService;
30+
@Autowired
31+
private MockMvc mockMvc;
32+
@Autowired
33+
private CompanyPscController companyPscController;
34+
35+
@Test
36+
void contextLoads() {
37+
assertThat(companyPscController).isNotNull();
38+
}
39+
40+
41+
@Test
42+
void callPutRequest() throws Exception {
43+
doNothing()
44+
.when(companyPscService).insertPscRecord(anyString(), isA(FullRecordCompanyPSCApi.class));
45+
46+
mockMvc.perform(put(PUT_URL)
47+
.contentType(APPLICATION_JSON)
48+
.header("x-request-id", X_REQUEST_ID)
49+
.content(TestHelper.createJsonPayload()))
50+
.andExpect(status().isCreated());
51+
}
52+
}

src/test/java/uk/gov/companieshouse/pscdataapi/util/TestHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package uk.gov.companieshouse.pscdataapi.util;
22

3+
import java.io.InputStreamReader;
4+
import java.io.IOException;
35
import java.time.LocalDate;
46
import java.time.OffsetDateTime;
57
import java.util.List;
68

9+
import org.springframework.util.FileCopyUtils;
710
import uk.gov.companieshouse.api.psc.Data;
811
import uk.gov.companieshouse.api.psc.ExternalData;
912
import uk.gov.companieshouse.api.psc.FullRecordCompanyPSCApi;
@@ -90,4 +93,11 @@ public static PscDocument buildPscDocument(String kind) {
9093

9194
return output;
9295
}
96+
97+
public static String createJsonPayload() throws IOException {
98+
InputStreamReader exampleJsonPayload = new InputStreamReader(
99+
ClassLoader.getSystemClassLoader().getResourceAsStream("psc_payload.json"));
100+
101+
return FileCopyUtils.copyToString(exampleJsonPayload);
102+
}
93103
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"_id": "YfTs9WeeqpXTqf6dc6FZ4C0H0RQ",
3+
"internal_data": {
4+
"created_at" : "2021-11-02T08:47:45",
5+
"updated_at" :"2021-09-14T10:30:16.000Z",
6+
"updated_by" :"CHIPS",
7+
"delta_at" : "2023-11-02T08:47:45.378Z"
8+
},
9+
"external_data": {
10+
"notification_id": "ZfTs9WeeqpXTqf6dc6FZ4C0H0RQ",
11+
"psc_id" : "YfTs9WeeqpXTqf6dc6FZ4C0H0RQ",
12+
"sensitive_data": {
13+
"usual_residential_address" : {
14+
"address_line_1" : "ura_line1",
15+
"address_line_2" : "ura_line2",
16+
"care_of" : "ura_care_of",
17+
"country" : "United Kingdom",
18+
"locality" : "Cardiff",
19+
"po_box" : "ura_po",
20+
"postal_code" : "CF2 1B6",
21+
"premises" : "URA",
22+
"region" : "ura_region"
23+
},
24+
"date_of_birth": {
25+
"day": 21,
26+
"year": 1995,
27+
"month": 10
28+
},
29+
"residential_address_same_as_service_address": true
30+
},
31+
"data" : {
32+
"service_address" : {
33+
"address_line_1" : "sa_line1",
34+
"address_line_2" : "sa_line2",
35+
"care_of" : "sa_care_of",
36+
"country" : "United Kingdom",
37+
"locality" : "Cardiff",
38+
"po_box" : "sa_po",
39+
"postal_code" : "CF2 1B6",
40+
"premises" : "SA",
41+
"region" : "sa_region"
42+
},
43+
"natures_of_control": [
44+
"part-right-to-share-surplus-assets-75-to-100-percent"
45+
],
46+
"country_of_residence" : "United Kingdom",
47+
"links" : [{
48+
"self" : "/company/34777770/appointments/YfTs9WeeqpXTqf6dc6FZ4C0H0RQ"
49+
}],
50+
"nationality" : "British",
51+
"occupation" : "Lawyer",
52+
"kind" : "individual-person-with-significant-control",
53+
"surname" : "JONES",
54+
"forename" : "PHIL",
55+
"other_forenames" : "tom",
56+
"company_number": "34777770",
57+
"name_elements": {
58+
"surname" : "JONES",
59+
"forename" : "PHIL",
60+
"other_forenames" : "tom"
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)