@Test(groups = "Integration")
  public void testCopyResourceCreatingParentDir() throws Exception {
    File tempDataDirSub = new File(tempDataDir, "subdir");
    File tempDest = new File(tempDataDirSub, "tempDest.txt");
    String tempLocalContent = "abc";
    File tempLocal = new File(tempDataDir, "tempLocal.txt");
    Files.write(tempLocalContent, tempLocal, Charsets.UTF_8);

    localhost.setConfig(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath());

    MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class));
    app.start(ImmutableList.of(localhost));

    // First confirm would get exception in createeParentDir==false
    try {
      entity
          .getDriver()
          .copyResource(tempLocal.toURI().toString(), tempDest.getAbsolutePath(), false);
      assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent));
      fail("Should have failed to create " + tempDest);
    } catch (SshException e) {
      // success
    } finally {
      Os.deleteRecursively(tempDataDirSub);
    }

    // Copy to absolute path
    try {
      entity
          .getDriver()
          .copyResource(tempLocal.toURI().toString(), tempDest.getAbsolutePath(), true);
      assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent));
    } finally {
      Os.deleteRecursively(tempDataDirSub);
    }

    // Copy to absolute path
    String runDir = entity.getDriver().getRunDir();
    String tempDataDirRelativeToRunDir = "subdir";
    String tempDestRelativeToRunDir = Os.mergePaths(tempDataDirRelativeToRunDir, "tempDest.txt");
    File tempDestInRunDir = new File(Os.mergePaths(runDir, tempDestRelativeToRunDir));
    try {
      entity.getDriver().copyResource(tempLocal.toURI().toString(), tempDestRelativeToRunDir, true);
      assertEquals(
          Files.readLines(tempDestInRunDir, Charsets.UTF_8), ImmutableList.of(tempLocalContent));
    } finally {
      Os.deleteRecursively(new File(runDir, tempDataDirRelativeToRunDir));
    }
  }
예제 #2
0
 @AfterMethod(alwaysRun = true)
 public void tearDown() throws Exception {
   if (mgmt != null) Entities.destroyAll(mgmt);
   mgmt = null;
   tempDir = Os.deleteRecursively(tempDir).asNullOrThrowing();
   checkExpectedFailure();
 }
 @AfterMethod(alwaysRun = true)
 public void tearDown() throws Exception {
   if (app != null) Entities.destroyAll(app.getManagementContext());
   if (tempDataDir != null) Os.deleteRecursively(tempDataDir);
 }
 @AfterMethod(alwaysRun = true)
 public void tearDown() throws Exception {
   mementoDir = Os.deleteRecursively(mementoDir).asNullOrThrowing();
   super.tearDown();
 }