@Test(expected = TransferException.class) public void testGetFailure() { final Answer<Object> exceptionThrower = new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { throw mock(SftpException.class); } }; final ChannelSftp mockChannel = mock(ChannelSftp.class, exceptionThrower); final FileRequest mockRequest = mock(FileRequest.class); when(mockRequest.getSourceFile()).thenReturn(URI.create("target/unit/dummy.src")); when(mockRequest.getTargetFile()).thenReturn(new File("target/unit/dummy.out").toURI()); new DownloadProcessor(mockRequest).run(mockChannel); }
@Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } }
DownloadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } } }
DownloadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } } DownloadProcessor(final FileRequest request); }
DownloadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } } DownloadProcessor(final FileRequest request); @Override void run(final ChannelSftp channel); }
DownloadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final FileOutputStream writer = new FileOutputStream(new File(request.getTargetFile()), false); final InputStream stream = channel.get(request.getSourceFile().getPath()); IOUtils.copy(stream, writer); } catch (final SftpException e) { throw new TransferException( "Failed to retrieve file from remote server: " + request.getSourceFile().getPath(), e); } catch (final IOException e) { throw new TransferException("Failed to download file to local disk: " + request.getSourceFile().getPath(), e); } finally { point.collect(); } } DownloadProcessor(final FileRequest request); @Override void run(final ChannelSftp channel);  }