@Test public void notExistingBackupDir() throws Exception { Path dirToBkp = Files.createTempDirectory("dirToBkp2"); Path parentdirfile1 = createTempFile(dirToBkp, "FILE_1", ".tmp"); Path parentdirfile2 = createTempFile(dirToBkp, "FILE_2", ".tmp"); new BackupHelper(conf).backupFileOrDir(dirToBkp); Path bkp = PathUtils.get(conf.getBackupDir(), dirToBkp); assertThat(exists(bkp), is(true)); assertThat(exists(PathUtils.get(bkp, parentdirfile1.getFileName())), is(true)); assertThat(exists(PathUtils.get(bkp, parentdirfile2.getFileName())), is(true)); }
@Test public void backupFile() throws IOException { Path dirToBkp = Files.createTempDirectory("dirToBkp3"); Path parentdirfile1 = createTempFile(dirToBkp, "FILE_1", ".tmp"); new BackupHelper(conf).backupFile(parentdirfile1); Path bkp = PathUtils.get(conf.getBackupDir(), parentdirfile1); assertThat(exists(bkp), is(true)); }
@Test public void backupComplexDir() throws IOException { Path dirToBkp = Files.createTempDirectory("dirToBkp4"); Path subDir1 = Files.createTempDirectory(dirToBkp, "subDir1"); Path subDir2 = Files.createTempDirectory(dirToBkp, "subDir2"); Path subDir3 = Files.createTempDirectory(subDir1, "subDir3"); Path parentdirfile1 = createTempFile(dirToBkp, "FILE_1", ".tmp"); Path parentdirfile2 = createTempFile(subDir1, "FILE_2", ".tmp"); Path parentdirfile3 = createTempFile(subDir3, "FILE_3", ".tmp"); new BackupHelper(conf).backupFileOrDir(dirToBkp); Path bkp = PathUtils.get(conf.getBackupDir(), dirToBkp); assertThat(exists(bkp), is(true)); assertThat(exists(PathUtils.get(bkp, parentdirfile1.getFileName())), is(true)); assertThat(exists(PathUtils.get(bkp, subDir1.getFileName())), is(true)); assertThat(exists(PathUtils.get(bkp, subDir2.getFileName())), is(true)); assertThat( exists( PathUtils.get(PathUtils.get(bkp, subDir1.getFileName()), parentdirfile2.getFileName())), is(true)); assertThat( exists(PathUtils.get(PathUtils.get(bkp, subDir1.getFileName()), subDir3.getFileName())), is(true)); assertThat( exists( PathUtils.get( PathUtils.get(PathUtils.get(bkp, subDir1.getFileName()), subDir3.getFileName()), parentdirfile3.getFileName())), is(true)); }