@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(); // directory should be created, and file readable now Assert.assertEquals(FileUtils.readFileToString(new File(fn)), "hello world"); Assert.assertEquals(t.getExitCode(), (Integer) 0); }
@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"); // and make sure this doesn't throw Assert.assertTrue(t.isDone()); Assert.assertTrue(t.isSuccessful()); Assert.assertEquals(t.get(), null); Assert.assertEquals(t.getExitCode(), (Integer) 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()); // this doesn't fail t.block(); Assert.assertTrue(t.isDone()); // and this doesn't fail either Assert.assertEquals(t.get(), null); // but it's not successful Assert.assertNotNull(t.getException()); Assert.assertFalse(t.isSuccessful()); // exit code probably null, but won't be zero Assert.assertNotEquals(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")); // this doesn't fail t.block(); Assert.assertTrue(t.isDone()); setExpectingFailure(); try { // but this does t.get(); } catch (Exception e) { log.info("The error if file cannot be written is: " + e); clearExpectedFailure(); } checkExpectedFailure(); // and the results indicate failure Assert.assertFalse(t.isSuccessful()); Assert.assertNotNull(t.getException()); Assert.assertNotEquals(t.getExitCode(), (Integer) 0); }