use of uk.gov.justice.services.adapter.rest.multipart.FileInputDetails in project microservice_framework by CJSCommonPlatform.
the class FileBasedInterceptorContextFactoryTest method shouldCreateAnInterceptorContextContainingTheFileDetailsList.
@Test
@SuppressWarnings("unchecked")
public void shouldCreateAnInterceptorContextContainingTheFileDetailsList() throws Exception {
final JsonEnvelope inputEnvelope = mock(JsonEnvelope.class);
final FileInputDetails fileInputDetails_1 = mock(FileInputDetails.class);
final FileInputDetails fileInputDetails_2 = mock(FileInputDetails.class);
final List<FileInputDetails> fileInputDetailss = asList(fileInputDetails_1, fileInputDetails_2);
final InterceptorContext interceptorContext = fileBasedInterceptorContextFactory.create(fileInputDetailss, inputEnvelope);
assertThat(interceptorContext.inputEnvelope(), is(inputEnvelope));
final Optional<Object> inputParameter = interceptorContext.getInputParameter(FILE_INPUT_DETAILS_LIST);
assertThat(inputParameter.isPresent(), is(true));
final List<FileInputDetails> fileInputDetailsList = (List<FileInputDetails>) inputParameter.get();
assertThat(fileInputDetailsList.size(), is(2));
assertThat(fileInputDetailsList, hasItem(fileInputDetails_1));
assertThat(fileInputDetailsList, hasItem(fileInputDetails_2));
}
use of uk.gov.justice.services.adapter.rest.multipart.FileInputDetails in project microservice_framework by CJSCommonPlatform.
the class InputStreamFileInterceptor method process.
@Override
@SuppressWarnings("unchecked")
public InterceptorContext process(final InterceptorContext interceptorContext, final InterceptorChain interceptorChain) {
final Optional<Object> inputParameterOptional = interceptorContext.getInputParameter(FILE_INPUT_DETAILS_LIST);
if (inputParameterOptional.isPresent()) {
final List<FileInputDetails> fileInputDetails = (List<FileInputDetails>) inputParameterOptional.get();
final Map<String, UUID> results = multipleFileInputDetailsService.storeFileDetails(fileInputDetails);
final JsonEnvelope inputEnvelope = resultsHandler.addResultsTo(interceptorContext.inputEnvelope(), results);
return interceptorChain.processNext(interceptorContext.copyWithInput(inputEnvelope));
}
return interceptorChain.processNext(interceptorContext);
}
use of uk.gov.justice.services.adapter.rest.multipart.FileInputDetails in project microservice_framework by CJSCommonPlatform.
the class FileInputDetailsHandlerTest method shouldCreateMetadataAndStoreFile.
@Test
public void shouldCreateMetadataAndStoreFile() throws Exception {
final String fileName = "fileName";
final UUID fileId = randomUUID();
final FileInputDetails fileInputDetails = mock(FileInputDetails.class);
when(fileInputDetails.getFileName()).thenReturn(fileName);
when(singleFileInputDetailsService.store(eq(fileInputDetails), metadataCaptor.capture())).thenReturn(fileId);
assertThat(fileInputDetailsHandler.store(fileInputDetails), is(fileId));
final JsonObject metadata = metadataCaptor.getValue();
with(metadata.toString()).assertThat("$.fileName", is(fileName));
}
use of uk.gov.justice.services.adapter.rest.multipart.FileInputDetails in project microservice_framework by CJSCommonPlatform.
the class InputStreamFileInterceptorTest method shouldStoreTheInputStreamInTheFileStoreAndUpdateTheInputEnvelope.
@Test
public void shouldStoreTheInputStreamInTheFileStoreAndUpdateTheInputEnvelope() throws Exception {
final FileInputDetails fileInputDetails = mock(FileInputDetails.class);
final List<FileInputDetails> fileInputDetailsList = singletonList(fileInputDetails);
final Map<String, UUID> results = ImmutableMap.of("fieldName", randomUUID());
final InterceptorContext inputInterceptorContext = createInterceptorContext(fileInputDetailsList);
when(multipleFileInputDetailsService.storeFileDetails(fileInputDetailsList)).thenReturn(results);
when(resultsHandler.addResultsTo(inputEnvelope, results)).thenReturn(inputEnvelope);
final InterceptorContext outputInterceptorContext = interceptorChain.processNext(inputInterceptorContext);
final Optional<JsonEnvelope> jsonEnvelope = outputInterceptorContext.outputEnvelope();
assertThat(jsonEnvelope.isPresent(), is(true));
assertThat(jsonEnvelope.get(), is(outputEnvelope));
assertThat(resultJsonEnvelope, is(inputEnvelope));
}
use of uk.gov.justice.services.adapter.rest.multipart.FileInputDetails in project microservice_framework by CJSCommonPlatform.
the class SingleFileInputDetailsServiceTest method shouldLogAWarningIfClosingTheInputStreamFails.
@Test
public void shouldLogAWarningIfClosingTheInputStreamFails() throws Exception {
final IOException ioException = new IOException("Ooops");
final UUID fileId = randomUUID();
final FileInputDetails fileInputDetails = mock(FileInputDetails.class);
final JsonObject metadata = mock(JsonObject.class);
final InputStream inputStream = mock(InputStream.class);
when(fileInputDetails.getInputStream()).thenReturn(inputStream);
when(fileStorer.store(metadata, inputStream)).thenReturn(fileId);
doThrow(ioException).when(inputStream).close();
assertThat(singleFileInputDetailsService.store(fileInputDetails, metadata), is(fileId));
verify(logger).warn("Error closing InputStream", ioException);
}
Aggregations