Skip to content

Commit 377ee34

Browse files
AMP-169 - added material content endpoint.
1 parent fa11d84 commit 377ee34

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,16 @@ services:
2020
- db
2121
ports:
2222
- "8082:8082"
23+
24+
wiremock:
25+
image: wiremock/wiremock:3.6.0
26+
container_name: wiremock
27+
ports:
28+
- "9999:9999"
29+
volumes:
30+
- ./src/test/resources/mappings:/home/wiremock/mappings
31+
- ./src/test/resources/__files:/home/wiremock/__files
32+
command:
33+
- "--global-response-templating"
34+
- "--verbose"
35+

src/main/java/uk/gov/hmcts/cp/subscription/clients/MaterialClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
public interface MaterialClient {
1515

1616
@GetMapping("/material-query-api/query/api/rest/material/material/{materialId}/metadata")
17-
MaterialResponse getByMaterialId(@PathVariable UUID materialId);
17+
MaterialResponse getMetadataById(@PathVariable UUID materialId);
18+
19+
@GetMapping("/material-query-api/query/api/rest/material/material/{materialId}/content")
20+
byte[] getContentById(@PathVariable UUID materialId);
1821
}

src/test/java/uk/gov/hmcts/cp/subscription/clients/MaterialClientIntegrationTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import uk.gov.hmcts.cp.subscription.clients.model.MaterialResponse;
1010
import uk.gov.hmcts.cp.subscription.config.TestContainersInitialise;
1111

12+
import java.nio.charset.StandardCharsets;
1213
import java.util.UUID;
1314

1415
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
@@ -26,7 +27,7 @@ class MaterialClientIntegrationTest {
2627
void should_return_material_by_id() {
2728

2829
final UUID materialId = UUID.fromString("6c198796-08bb-4803-b456-fa0c29ca6021");
29-
MaterialResponse response = materialClient.getByMaterialId(materialId);
30+
MaterialResponse response = materialClient.getMetadataById(materialId);
3031

3132
assertThat(response).satisfies(resp -> {
3233
assertThat(resp.getMaterialId()).isEqualTo(materialId);
@@ -39,7 +40,27 @@ void should_return_material_by_id() {
3940
@Test
4041
void should_throw_not_found_when_material_does_not_exist() {
4142
UUID materialId = UUID.fromString("6c198796-08bb-4803-b456-fa0c29ca6022");
42-
assertThatThrownBy(() -> materialClient.getByMaterialId(materialId))
43+
assertThatThrownBy(() -> materialClient.getMetadataById(materialId))
44+
.isInstanceOf(feign.FeignException.NotFound.class);
45+
}
46+
47+
@Test
48+
void should_return_content_by_id() {
49+
50+
final UUID materialId = UUID.fromString("7c198796-08bb-4803-b456-fa0c29ca6021");
51+
byte[] response = materialClient.getContentById(materialId);
52+
53+
assertThat(response);
54+
String pdfAsString = new String(response, StandardCharsets.ISO_8859_1);
55+
assertThat(pdfAsString).startsWith("%PDF");
56+
assertThat(pdfAsString).contains("%%EOF");
57+
assertThat(response).hasSizeGreaterThan(500);
58+
}
59+
60+
@Test
61+
void should_throw_not_found_when_content_does_not_exist() {
62+
UUID materialId = UUID.fromString("7c198796-08bb-4803-b456-fa0c29ca6023");
63+
assertThatThrownBy(() -> materialClient.getContentById(materialId))
4364
.isInstanceOf(feign.FeignException.NotFound.class);
4465
}
4566
}
8.48 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"request": {
3+
"method": "GET",
4+
"url": "/material-query-api/query/api/rest/material/material/7c198796-08bb-4803-b456-fa0c29ca6021/content"
5+
},
6+
"response": {
7+
"status": 200,
8+
"headers": {
9+
"Content-Type": "application/pdf",
10+
"Content-Disposition": "inline; filename=\"material-content.pdf\""
11+
},
12+
"bodyFileName": "material-content.pdf"
13+
}
14+
}

src/test/resources/mappings/material-mapping.json renamed to src/test/resources/mappings/material-metadata-mapping.json

File renamed without changes.

0 commit comments

Comments
 (0)