SshTasks { public static SshPutTaskFactory newSshPutTaskFactory(SshMachineLocation machine, String remoteFile) { return newSshPutTaskFactory(machine, true, remoteFile); }  static ProcessTaskFactory<Integer> newSshExecTaskFactory(SshMachineLocation machine, String ...commands); static ProcessTaskFactory<Integer> newSshExecTaskFactory(SshMachineLocation machine, final boolean useMachineConfig, String ...commands); static ProcessTaskFactory<Integer> newSshExecTaskFactory(SshMachineLocation machine, List<String> commands); static ProcessTaskFactory<Integer> newSshExecTaskFactory(SshMachineLocation machine, final boolean useMachineConfig, List<String> commands); static SshPutTaskFactory newSshPutTaskFactory(SshMachineLocation machine, String remoteFile); static SshPutTaskFactory newSshPutTaskFactory(SshMachineLocation machine, final boolean useMachineConfig, String remoteFile); static SshFetchTaskFactory newSshFetchTaskFactory(SshMachineLocation machine, String remoteFile); static SshFetchTaskFactory newSshFetchTaskFactory(SshMachineLocation machine, final boolean useMachineConfig, String remoteFile); static ProcessTaskFactory<Boolean> dontRequireTtyForSudo(SshMachineLocation machine, final boolean failIfCantSudo); static ProcessTaskFactory<Boolean> dontRequireTtyForSudo(SshMachineLocation machine, OnFailingTask onFailingTaskRequested); static Function<ProcessTaskWrapper<?>, String> returningStdoutLoggingInfo(final Logger logger, final boolean requireZero); static TaskFactory<?> installFromUrl(final SshMachineLocation location, final String url, final String destPath); static TaskFactory<?> installFromUrl(final Map<String, ?> props, final SshMachineLocation location, final String url, final String destPath); static TaskFactory<?> installFromUrl(final ResourceUtils utils, final Map<String, ?> props, final SshMachineLocation location, final String url, final String destPath);  }
@Test(groups="Integration") public void testCopyTo() throws IOException { String fn = Urls.mergePaths(tempDir.getPath(), "f1"); SshPutTaskWrapper t = submit(SshTasks.newSshPutTaskFactory(host, fn).contents("hello world")); t.block(); Assert.assertEquals(FileUtils.readFileToString(new File(fn)), "hello world"); Assert.assertTrue(t.isDone()); Assert.assertTrue(t.isSuccessful()); Assert.assertEquals(t.get(), null); Assert.assertEquals(t.getExitCode(), (Integer)0); }
@Test(groups="Integration") public void testCopyToFailBadSubdir() throws IOException { String fn = Urls.mergePaths(tempDir.getPath(), "non-existent-subdir/file"); SshPutTaskWrapper t = submit(SshTasks.newSshPutTaskFactory(host, fn).contents("hello world")); t.block(); Assert.assertTrue(t.isDone()); setExpectingFailure(); try { t.get(); } catch (Exception e) { log.info("The error if file cannot be written is: "+e); clearExpectedFailure(); } checkExpectedFailure(); Assert.assertFalse(t.isSuccessful()); Assert.assertNotNull(t.getException()); Assert.assertNotEquals(t.getExitCode(), 0); }
@Test(groups="Integration") public void testCopyToFailBadSubdirAllow() throws IOException { String fn = Urls.mergePaths(tempDir.getPath(), "non-existent-subdir/file"); SshPutTaskWrapper t = submit(SshTasks.newSshPutTaskFactory(host, fn).contents("hello world").allowFailure()); t.block(); Assert.assertTrue(t.isDone()); Assert.assertEquals(t.get(), null); Assert.assertNotNull(t.getException()); Assert.assertFalse(t.isSuccessful()); Assert.assertNotEquals(t.getExitCode(), 0); }
@Test(groups="Integration") public void testCopyToFailBadSubdirCreate() throws IOException { String fn = Urls.mergePaths(tempDir.getPath(), "non-existent-subdir-to-create/file"); SshPutTaskWrapper t = submit(SshTasks.newSshPutTaskFactory(host, fn).contents("hello world").createDirectory()); t.block(); Assert.assertEquals(FileUtils.readFileToString(new File(fn)), "hello world"); Assert.assertEquals(t.getExitCode(), (Integer)0); }