Search in sources :

Example 1 with FileServiceException

use of uk.gov.justice.services.fileservice.api.FileServiceException in project microservice_framework by CJSCommonPlatform.

the class SingleFileInputDetailsServiceTest method shouldThrowAFileStoreFailedExceptionIfStoringTheInputStreamFails.

@Test
public void shouldThrowAFileStoreFailedExceptionIfStoringTheInputStreamFails() throws Exception {
    final FileServiceException fileServiceException = new FileServiceException("Ooops");
    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)).thenThrow(fileServiceException);
    try {
        singleFileInputDetailsService.store(fileInputDetails, metadata);
        fail();
    } catch (final FileStoreFailedException expected) {
        assertThat(expected.getCause(), is(fileServiceException));
        assertThat(expected.getMessage(), is("Failed to store file in FileStore"));
    }
    verify(inputStream).close();
}
Also used : FileServiceException(uk.gov.justice.services.fileservice.api.FileServiceException) FileInputDetails(uk.gov.justice.services.adapter.rest.multipart.FileInputDetails) InputStream(java.io.InputStream) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 2 with FileServiceException

use of uk.gov.justice.services.fileservice.api.FileServiceException in project microservice_framework by CJSCommonPlatform.

the class FileStreamReturningResponseStrategyTest method shouldThrowExceptionIfFileServiceThrowsException.

@Test(expected = InternalServerErrorException.class)
public void shouldThrowExceptionIfFileServiceThrowsException() throws FileServiceException {
    final UUID fileId = randomUUID();
    when(fileRetriever.retrieve(fileId)).thenThrow(new FileServiceException(""));
    strategy.responseFor("someAction", Optional.of(envelope().with(metadataWithDefaults()).withPayloadOf(fileId, "fileId").build()));
}
Also used : FileServiceException(uk.gov.justice.services.fileservice.api.FileServiceException) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 FileServiceException (uk.gov.justice.services.fileservice.api.FileServiceException)2 InputStream (java.io.InputStream)1 UUID (java.util.UUID)1 UUID.randomUUID (java.util.UUID.randomUUID)1 JsonObject (javax.json.JsonObject)1 FileInputDetails (uk.gov.justice.services.adapter.rest.multipart.FileInputDetails)1