diff --git a/docker-compose.yml b/docker-compose.yml index 27cd1a2e..099b87f8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,3 +20,16 @@ services: - db ports: - "8082:8082" + + wiremock: + image: wiremock/wiremock:3.6.0 + container_name: wiremock + ports: + - "9999:9999" + volumes: + - ./src/test/resources/mappings:/home/wiremock/mappings + - ./src/test/resources/__files:/home/wiremock/__files + command: + - "--global-response-templating" + - "--verbose" + diff --git a/src/main/java/uk/gov/hmcts/cp/subscription/clients/MaterialClient.java b/src/main/java/uk/gov/hmcts/cp/subscription/clients/MaterialClient.java index 44a4917c..438cd9d5 100644 --- a/src/main/java/uk/gov/hmcts/cp/subscription/clients/MaterialClient.java +++ b/src/main/java/uk/gov/hmcts/cp/subscription/clients/MaterialClient.java @@ -14,5 +14,8 @@ public interface MaterialClient { @GetMapping("/material-query-api/query/api/rest/material/material/{materialId}/metadata") - MaterialResponse getByMaterialId(@PathVariable UUID materialId); + MaterialResponse getMetadataById(@PathVariable UUID materialId); + + @GetMapping("/material-query-api/query/api/rest/material/material/{materialId}/content") + byte[] getContentById(@PathVariable UUID materialId); } \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/cp/subscription/clients/MaterialClientIntegrationTest.java b/src/test/java/uk/gov/hmcts/cp/subscription/clients/MaterialClientIntegrationTest.java index a966d4bc..9a2e5d60 100644 --- a/src/test/java/uk/gov/hmcts/cp/subscription/clients/MaterialClientIntegrationTest.java +++ b/src/test/java/uk/gov/hmcts/cp/subscription/clients/MaterialClientIntegrationTest.java @@ -9,6 +9,7 @@ import uk.gov.hmcts.cp.subscription.clients.model.MaterialResponse; import uk.gov.hmcts.cp.subscription.config.TestContainersInitialise; +import java.nio.charset.StandardCharsets; import java.util.UUID; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -26,7 +27,7 @@ class MaterialClientIntegrationTest { void should_return_material_by_id() { final UUID materialId = UUID.fromString("6c198796-08bb-4803-b456-fa0c29ca6021"); - MaterialResponse response = materialClient.getByMaterialId(materialId); + MaterialResponse response = materialClient.getMetadataById(materialId); assertThat(response).satisfies(resp -> { assertThat(resp.getMaterialId()).isEqualTo(materialId); @@ -39,7 +40,27 @@ void should_return_material_by_id() { @Test void should_throw_not_found_when_material_does_not_exist() { UUID materialId = UUID.fromString("6c198796-08bb-4803-b456-fa0c29ca6022"); - assertThatThrownBy(() -> materialClient.getByMaterialId(materialId)) + assertThatThrownBy(() -> materialClient.getMetadataById(materialId)) + .isInstanceOf(feign.FeignException.NotFound.class); + } + + @Test + void should_return_content_by_id() { + + final UUID materialId = UUID.fromString("7c198796-08bb-4803-b456-fa0c29ca6021"); + byte[] response = materialClient.getContentById(materialId); + + assertThat(response); + String pdfAsString = new String(response, StandardCharsets.ISO_8859_1); + assertThat(pdfAsString).startsWith("%PDF"); + assertThat(pdfAsString).contains("%%EOF"); + assertThat(response).hasSizeGreaterThan(500); + } + + @Test + void should_throw_not_found_when_content_does_not_exist() { + UUID materialId = UUID.fromString("7c198796-08bb-4803-b456-fa0c29ca6023"); + assertThatThrownBy(() -> materialClient.getContentById(materialId)) .isInstanceOf(feign.FeignException.NotFound.class); } } diff --git a/src/test/resources/__files/material-content.pdf b/src/test/resources/__files/material-content.pdf new file mode 100644 index 00000000..94e3be39 Binary files /dev/null and b/src/test/resources/__files/material-content.pdf differ diff --git a/src/test/resources/mappings/material-content-mapping.json b/src/test/resources/mappings/material-content-mapping.json new file mode 100644 index 00000000..89d431bb --- /dev/null +++ b/src/test/resources/mappings/material-content-mapping.json @@ -0,0 +1,14 @@ +{ + "request": { + "method": "GET", + "url": "/material-query-api/query/api/rest/material/material/7c198796-08bb-4803-b456-fa0c29ca6021/content" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/pdf", + "Content-Disposition": "inline; filename=\"material-content.pdf\"" + }, + "bodyFileName": "material-content.pdf" + } +} diff --git a/src/test/resources/mappings/material-mapping.json b/src/test/resources/mappings/material-metadata-mapping.json similarity index 100% rename from src/test/resources/mappings/material-mapping.json rename to src/test/resources/mappings/material-metadata-mapping.json