use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.
the class ComponentEnvironment method getNewCopy.
public ComponentEnvironment getNewCopy() {
ComponentEnvironment newComponentEnvironment = new ComponentEnvironment(this.componentName, this.environmentName, null, this.backupFolder);
List<EnvironmentUnit> newEnvironmentUnits = new ArrayList<EnvironmentUnit>();
for (EnvironmentUnit environmentUnit : this.environmentUnits) {
EnvironmentUnit newEnvironmentUnit;
if (environmentUnit instanceof DatabaseEnvironmentUnit) {
newEnvironmentUnit = ((DatabaseEnvironmentUnit) environmentUnit).getNewCopy();
} else if (environmentUnit instanceof FileEnvironmentUnit) {
newEnvironmentUnit = ((FileEnvironmentUnit) environmentUnit).getNewCopy();
} else {
// it is instance of DirectoryEnvironmentUnit
newEnvironmentUnit = ((DirectoryEnvironmentUnit) environmentUnit).getNewCopy();
}
newEnvironmentUnits.add(newEnvironmentUnit);
}
newComponentEnvironment.environmentUnits = newEnvironmentUnits;
return newComponentEnvironment;
}
use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.
the class Test_DirectoryEnvironmentUnit method backupPositive.
@Test
public void backupPositive() throws EnvironmentCleanupException, IOException {
log.debug("backupDirPath: " + backupDirPath);
String originalDir = IoUtils.normalizeDirPath(backupDirPath + backupDirName);
log.debug("originalDir: " + originalDir);
EnvironmentUnit dirEnvUnit = new DirectoryEnvironmentUnit(originalDir, backupDirPath, tempBackupDirName);
dirEnvUnit.backup();
// verify the content of the backup folder
/*
* TODO: the check here will not be good if we change the folder we create backup from
* We should make the check independent to particular folder content
*/
String tempBackupDir = IoUtils.normalizeDirPath(backupDirPath + tempBackupDirName);
log.debug("tempBackupDir: " + tempBackupDir);
assertTrue(new File(tempBackupDir).exists());
assertEquals(3, new File(tempBackupDir).listFiles().length);
String file1 = tempBackupDir + "file1.txt";
assertTrue(new File(file1).exists());
assertEquals(new File(file1).length(), new File(tempBackupDir + "file1.txt").length());
String emptyDir = IoUtils.normalizeDirPath(tempBackupDir + "emptydir/");
org.apache.log4j.Logger.getLogger(Test_DirectoryEnvironmentUnit.class).error("emptydir='" + emptyDir + "'");
assertTrue(new File(emptyDir).exists());
assertEquals(new File(emptyDir).listFiles().length, 0);
String subDir = IoUtils.normalizeDirPath(tempBackupDir + "subdir/");
assertTrue(new File(subDir).exists());
assertEquals(new File(subDir).listFiles().length, 1);
String file2 = subDir + "file2.txt";
assertTrue(new File(file2).exists());
assertEquals(new File(file2).length(), new File(tempBackupDir + "subdir/file2.txt").length());
}
use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.
the class Test_DirectoryEnvironmentUnit method restoreNotNeeded.
// TODO - investigate failing error. It is just on CI machine, only when run from Jenkins
@Ignore
@Test
public void restoreNotNeeded() throws EnvironmentCleanupException {
EnvironmentUnit dirEnvUnit = new DirectoryEnvironmentUnit(restoreDirPath, backupDirPath, backupDirName);
Assert.assertTrue(dirEnvUnit.restore());
// now the restore is not needed
Assert.assertFalse(dirEnvUnit.restore());
}
use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.
the class Test_DirectoryEnvironmentUnit method restore_aNewSubdirMustBeDeleted.
// TODO - investigate failing error. It is just on CI machine, only when run from Jenkins
@Ignore
@Test
public void restore_aNewSubdirMustBeDeleted() throws EnvironmentCleanupException, IOException {
EnvironmentUnit dirEnvUnit = new DirectoryEnvironmentUnit(restoreDirPath, backupDirPath, backupDirName);
Assert.assertTrue(dirEnvUnit.restore());
new File(restoreDirPath + "new_sub_dir").mkdir();
// now the restore is not needed
Assert.assertTrue(dirEnvUnit.restore());
}
use of com.axway.ats.environment.EnvironmentUnit in project ats-framework by Axway.
the class Test_DirectoryEnvironmentUnit method backupNegative_noOriginalDir.
@Test
public void backupNegative_noOriginalDir() throws EnvironmentCleanupException, IOException {
String originalDir = IoUtils.normalizeDirPath(backupDirPath + "fakeDirName");
EnvironmentUnit dirEnvUnit = new DirectoryEnvironmentUnit(originalDir, backupDirPath, "backupFakeDirName");
dirEnvUnit.backup();
// check if the backup is really skipped
assertFalse(new File(IoUtils.normalizeDirPath(backupDirPath + "backupFakeDirName")).exists());
}
Aggregations