Search in sources :

Example 6 with MultipartFormDataInput

use of org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput in project microservice_framework by CJSCommonPlatform.

the class DefaultFileInputDetailsFactoryTest method shouldThrowBadRequestExceptionIfTheListOfFilePartsForAFieldNameIsEmpty.

@Test
public void shouldThrowBadRequestExceptionIfTheListOfFilePartsForAFieldNameIsEmpty() throws Exception {
    final String fileName = "the-file-name.jpeg";
    final String fieldName = "myFieldName";
    final MultipartFormDataInput multipartFormDataInput = mock(MultipartFormDataInput.class);
    final InputPart inputPart = mock(InputPart.class);
    final InputStream inputStream = mock(InputStream.class);
    final Map<String, List<InputPart>> formDataMap = ImmutableMap.of(fieldName, emptyList());
    when(multipartFormDataInput.getFormDataMap()).thenReturn(formDataMap);
    when(inputPartFileNameExtractor.extractFileName(inputPart)).thenReturn(fileName);
    when(inputPart.getBody(InputStream.class, null)).thenReturn(inputStream);
    try {
        fileInputDetailsFactory.createFileInputDetailsFrom(multipartFormDataInput, singletonList(fieldName));
    } catch (final BadRequestException expected) {
        assertThat(expected.getMessage(), is("The list of input parts named 'myFieldName' is empty"));
    }
}
Also used : InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) MultipartFormDataInput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput) InputStream(java.io.InputStream) BadRequestException(uk.gov.justice.services.adapter.rest.exception.BadRequestException) Collections.emptyList(java.util.Collections.emptyList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Aggregations

InputPart (org.jboss.resteasy.plugins.providers.multipart.InputPart)6 MultipartFormDataInput (org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput)6 Test (org.junit.Test)6 Arrays.asList (java.util.Arrays.asList)5 Collections.emptyList (java.util.Collections.emptyList)5 Collections.singletonList (java.util.Collections.singletonList)5 List (java.util.List)5 InputStream (java.io.InputStream)4 BadRequestException (uk.gov.justice.services.adapter.rest.exception.BadRequestException)2 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FileStoreFailedException (uk.gov.justice.services.adapter.rest.interceptor.FileStoreFailedException)1