@Override public void onComplete(InputStream inputStream) { inputStreamConsumer.onComplete(inputStream); }
@Override protected void onConversionFinished(RemoteConversionContext conversionContext) throws Exception { Response response = conversionContext.getWebResponse().get(); // We do not need to check the status again, this callback will only be triggered on a successful conversion. try { consumer.onComplete(response.readEntity(InputStream.class)); } finally { response.close(); } }
@Override public void onComplete(File file) { try { inputStreamConsumer.onComplete(new DeleteFileOnCloseInputStream(file)); } catch (IOException e) { throw new FileSystemInteractionException(String.format("Could not process file: %s", file), e); } }
@Test(timeout = DEFAULT_CONVERSION_TIMEOUT) public void testInputStreamSourceToInputStreamConsumerExecute() throws Exception { File source = validFile(true); InputStream inputStream = spy(new FileInputStream(source)); IInputStreamSource inputStreamSource = mock(IInputStreamSource.class); when(inputStreamSource.getInputStream()).thenReturn(inputStream); OutputStream outputStream = mock(OutputStream.class); IInputStreamConsumer inputStreamConsumer = mock(IInputStreamConsumer.class); doAnswer(new CloseStreamAnswer()).when(inputStreamConsumer).onComplete(any(InputStream.class)); assertTrue(getConverter().convert(inputStreamSource).as(validInputType()).to(inputStreamConsumer).as(validTargetType()).execute()); assertTrue(source.exists()); verify(inputStreamSource, times(1)).getInputStream(); verify(inputStreamSource, times(1)).onConsumed(any(InputStream.class)); verify(inputStream, never()).close(); inputStream.close(); verify(inputStreamConsumer, times(1)).onComplete(any(InputStream.class)); verifyNoMoreInteractions(inputStreamConsumer); verify(outputStream, never()).close(); }
@Test(timeout = DEFAULT_CONVERSION_TIMEOUT) public void testInputStreamSourceToInputStreamConsumerFuture() throws Exception { File source = validFile(true); InputStream inputStream = spy(new FileInputStream(source)); IInputStreamSource inputStreamSource = mock(IInputStreamSource.class); when(inputStreamSource.getInputStream()).thenReturn(inputStream); OutputStream outputStream = mock(OutputStream.class); IInputStreamConsumer inputStreamConsumer = mock(IInputStreamConsumer.class); doAnswer(new CloseStreamAnswer()).when(inputStreamConsumer).onComplete(any(InputStream.class)); assertTrue(getConverter().convert(inputStreamSource).as(validInputType()).to(inputStreamConsumer).as(validTargetType()).schedule().get()); assertTrue(source.exists()); verify(inputStreamSource, times(1)).getInputStream(); verify(inputStreamSource, times(1)).onConsumed(any(InputStream.class)); verify(inputStream, never()).close(); inputStream.close(); verify(inputStreamConsumer, times(1)).onComplete(any(InputStream.class)); verifyNoMoreInteractions(inputStreamConsumer); verify(outputStream, never()).close(); }
switch (this) { case OK: callback.onComplete(new ByteArrayInputStream(asReply(message).getBytes(Charsets.UTF_8))); return MockResult.indicating(true); case CANCEL: