Search in sources :

Example 11 with EnvironmentUnit

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;
}
Also used : DirectoryEnvironmentUnit(com.axway.ats.environment.file.DirectoryEnvironmentUnit) ArrayList(java.util.ArrayList) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) DirectoryEnvironmentUnit(com.axway.ats.environment.file.DirectoryEnvironmentUnit) FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit)

Example 12 with EnvironmentUnit

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());
}
Also used : EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) File(java.io.File) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Example 13 with EnvironmentUnit

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());
}
Also used : EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) Ignore(org.junit.Ignore) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Example 14 with EnvironmentUnit

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());
}
Also used : EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) File(java.io.File) Ignore(org.junit.Ignore) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Example 15 with EnvironmentUnit

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());
}
Also used : EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) File(java.io.File) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Aggregations

EnvironmentUnit (com.axway.ats.environment.EnvironmentUnit)18 Test (org.junit.Test)11 DatabaseEnvironmentUnit (com.axway.ats.environment.database.DatabaseEnvironmentUnit)10 BaseTest (com.axway.ats.environment.BaseTest)8 DirectoryEnvironmentUnit (com.axway.ats.environment.file.DirectoryEnvironmentUnit)8 FileEnvironmentUnit (com.axway.ats.environment.file.FileEnvironmentUnit)8 File (java.io.File)8 AgentException (com.axway.ats.agent.core.exceptions.AgentException)3 EnvironmentCleanupException (com.axway.ats.environment.EnvironmentCleanupException)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)3 ComponentEnvironment (com.axway.ats.agent.core.ComponentEnvironment)2 Component (com.axway.ats.agent.core.Component)1 ComponentRepository (com.axway.ats.agent.core.ComponentRepository)1 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)1 DbConnection (com.axway.ats.core.dbaccess.DbConnection)1 DbConnMySQL (com.axway.ats.core.dbaccess.mysql.DbConnMySQL)1 SystemProcessAction (com.axway.ats.environment.process.SystemProcessAction)1 Date (java.util.Date)1