@Test public void testRun() throws Exception { final File targetFile = new File("target/unit/upload.test"); final ChannelSftp mockChannel = mock(ChannelSftp.class); final FileRequest mockRequest = mock(FileRequest.class); when(mockRequest.getSourceFile()).thenReturn(new File("target/unit/dummy.src").toURI()); when(mockRequest.getTargetFile()).thenReturn(targetFile.toURI()); final UploadProcessor processor = new UploadProcessor(mockRequest, false, Uploader.GOD_PERMISSIONS); processor.run(mockChannel); verify(mockChannel, times(1)).put(new File(mockRequest.getSourceFile()).getAbsolutePath(), mockRequest.getTargetFile().getPath()); }
@Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final File sourceFile = new File(request.getSourceFile()); final String remotePath = request.getTargetFile().getPath(); try { channel.put(sourceFile.getAbsolutePath(), remotePath); } catch (final SftpException e) { throw new TransferException("Failed to upload: " + sourceFile.getAbsolutePath(), e); } try { channel.chmod(permissions, remotePath); } catch (final SftpException e) { if (!ignoreChmodErrors) { throw new TransferException("Failed to chmod uploaded file.", e); } } } finally { point.collect(); } }
UploadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final File sourceFile = new File(request.getSourceFile()); final String remotePath = request.getTargetFile().getPath(); try { channel.put(sourceFile.getAbsolutePath(), remotePath); } catch (final SftpException e) { throw new TransferException("Failed to upload: " + sourceFile.getAbsolutePath(), e); } try { channel.chmod(permissions, remotePath); } catch (final SftpException e) { if (!ignoreChmodErrors) { throw new TransferException("Failed to chmod uploaded file.", e); } } } finally { point.collect(); } } }
UploadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final File sourceFile = new File(request.getSourceFile()); final String remotePath = request.getTargetFile().getPath(); try { channel.put(sourceFile.getAbsolutePath(), remotePath); } catch (final SftpException e) { throw new TransferException("Failed to upload: " + sourceFile.getAbsolutePath(), e); } try { channel.chmod(permissions, remotePath); } catch (final SftpException e) { if (!ignoreChmodErrors) { throw new TransferException("Failed to chmod uploaded file.", e); } } } finally { point.collect(); } } UploadProcessor(final FileRequest request, final boolean ignoreChmodErrors, final int permissions); }
UploadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final File sourceFile = new File(request.getSourceFile()); final String remotePath = request.getTargetFile().getPath(); try { channel.put(sourceFile.getAbsolutePath(), remotePath); } catch (final SftpException e) { throw new TransferException("Failed to upload: " + sourceFile.getAbsolutePath(), e); } try { channel.chmod(permissions, remotePath); } catch (final SftpException e) { if (!ignoreChmodErrors) { throw new TransferException("Failed to chmod uploaded file.", e); } } } finally { point.collect(); } } UploadProcessor(final FileRequest request, final boolean ignoreChmodErrors, final int permissions); @Override void run(final ChannelSftp channel); }
UploadProcessor implements FileTransferProcessor { @Override public void run(final ChannelSftp channel) { final EtmPoint point = MONITOR.createPoint(getClass().getName() + ": run(ChannelSftp)"); try { final File sourceFile = new File(request.getSourceFile()); final String remotePath = request.getTargetFile().getPath(); try { channel.put(sourceFile.getAbsolutePath(), remotePath); } catch (final SftpException e) { throw new TransferException("Failed to upload: " + sourceFile.getAbsolutePath(), e); } try { channel.chmod(permissions, remotePath); } catch (final SftpException e) { if (!ignoreChmodErrors) { throw new TransferException("Failed to chmod uploaded file.", e); } } } finally { point.collect(); } } UploadProcessor(final FileRequest request, final boolean ignoreChmodErrors, final int permissions); @Override void run(final ChannelSftp channel);  }