use of uk.gov.justice.services.adapter.rest.interceptor.FileStoreFailedException in project microservice_framework by CJSCommonPlatform.
the class DefaultFileInputDetailsFactoryTest method shouldThrowFileStoreFailedExceptionIfGettingFileInputStreamFails.
@Test
public void shouldThrowFileStoreFailedExceptionIfGettingFileInputStreamFails() throws Exception {
final IOException ioException = new IOException("bunnies");
final String fileName = "the-file-name.jpeg";
final String fieldName = "myFieldName";
final MultipartFormDataInput multipartFormDataInput = mock(MultipartFormDataInput.class);
final InputPart inputPart = mock(InputPart.class);
final Map<String, List<InputPart>> formDataMap = ImmutableMap.of(fieldName, singletonList(inputPart));
when(multipartFormDataInput.getFormDataMap()).thenReturn(formDataMap);
when(inputPartFileNameExtractor.extractFileName(inputPart)).thenReturn(fileName);
when(inputPart.getMediaType()).thenReturn(TEXT_XML_TYPE);
when(inputPart.getBody(InputStream.class, null)).thenThrow(ioException);
try {
fileInputDetailsFactory.createFileInputDetailsFrom(multipartFormDataInput, singletonList(fieldName));
fail();
} catch (final FileStoreFailedException expected) {
assertThat(expected.getCause(), is(ioException));
assertThat(expected.getMessage(), is("Failed to store file 'the-file-name.jpeg'"));
}
}
Aggregations