Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
}
Binary file added src/test/resources/__files/material-content.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions src/test/resources/mappings/material-content-mapping.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading