Search in sources :

Example 1 with FileStoreFailedException

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'"));
    }
}
Also used : FileStoreFailedException(uk.gov.justice.services.adapter.rest.interceptor.FileStoreFailedException) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) MultipartFormDataInput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput) Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 InputPart (org.jboss.resteasy.plugins.providers.multipart.InputPart)1 MultipartFormDataInput (org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput)1 Test (org.junit.Test)1 FileStoreFailedException (uk.gov.justice.services.adapter.rest.interceptor.FileStoreFailedException)1