@Test(groups = "Integration")
 public void testSshIgnoringHeaderProperty() {
   host.setConfig(BrooklynConfigKeys.SSH_CONFIG_SCRIPT_HEADER, "#!/bin/bash -e\necho foo\n");
   ProcessTaskWrapper<Integer> t = submit(SshTasks.newSshExecTaskFactory(host, false, "echo bar"));
   Assert.assertTrue(
       t.block().getStdout().trim().matches("bar"), "mismatched output was: " + t.getStdout());
 }
 @Test(groups = "Integration")
 public void testSshEchoHello() {
   ProcessTaskWrapper<Integer> t =
       submit(SshTasks.newSshExecTaskFactory(host, "sleep 1 ; echo hello world"));
   Assert.assertFalse(t.isDone());
   Assert.assertEquals(t.get(), (Integer) 0);
   Assert.assertEquals(t.getTask().getUnchecked(), (Integer) 0);
   Assert.assertEquals(t.getStdout().trim(), "hello world");
 }
 @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 testSshFetch() throws IOException {
    String fn = Urls.mergePaths(tempDir.getPath(), "f2");
    FileUtils.write(new File(fn), "hello fetched world");

    SshFetchTaskFactory tf = SshTasks.newSshFetchTaskFactory(host, fn);
    SshFetchTaskWrapper t = tf.newTask();
    mgmt.getExecutionManager().submit(t);

    t.block();
    Assert.assertTrue(t.isDone());
    Assert.assertEquals(t.get(), "hello fetched world");
    Assert.assertEquals(t.getBytes(), "hello fetched world".getBytes());
  }
 @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);
 }