Search in sources :

Example 1 with FileEnvironmentUnit

use of com.axway.ats.environment.file.FileEnvironmentUnit in project ats-framework by Axway.

the class Test_ConfigurationParser method testAdditionalActionOfFileEnvironmentUnit.

@Test
public void testAdditionalActionOfFileEnvironmentUnit() throws Exception {
    InputStream _descriptorFileStream = Test_ConfigurationParser.class.getClassLoader().getResourceAsStream("test_descriptors/test_agent_descriptor_with_additional_actions.xml");
    ConfigurationParser configParser = new ConfigurationParser();
    configParser.parse(_descriptorFileStream, jarFileAbsolutePath);
    List<EnvironmentUnit> environmentUnits = configParser.getEnvironments().get(0).getEnvironmentUnits();
    assertEquals(3, environmentUnits.size());
    // check unit 1
    FileEnvironmentUnit fUnit1 = (FileEnvironmentUnit) environmentUnits.get(0);
    assertEquals(0, fUnit1.getAdditionalActions().size());
    // check unit 2
    FileEnvironmentUnit fUnit2 = (FileEnvironmentUnit) environmentUnits.get(1);
    assertEquals(1, fUnit2.getAdditionalActions().size());
    SystemProcessAction proc1 = (SystemProcessAction) fUnit2.getAdditionalActions().get(0);
    assertEquals(3, proc1.getSleepInterval());
    assertEquals(" shell command 'proc1'", proc1.getDescription());
    // check unit 3
    FileEnvironmentUnit fUnit3 = (FileEnvironmentUnit) environmentUnits.get(2);
    assertEquals(2, fUnit3.getAdditionalActions().size());
    SystemProcessAction proc2 = (SystemProcessAction) fUnit3.getAdditionalActions().get(0);
    assertEquals(5, proc2.getSleepInterval());
    assertEquals(" shell command 'proc1'", proc2.getDescription());
    SystemProcessAction proc3 = (SystemProcessAction) fUnit3.getAdditionalActions().get(1);
    assertEquals(0, proc3.getSleepInterval());
    assertEquals(" shell command 'proc2'", proc3.getDescription());
}
Also used : InputStream(java.io.InputStream) SystemProcessAction(com.axway.ats.environment.process.SystemProcessAction) FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) DirectoryEnvironmentUnit(com.axway.ats.environment.file.DirectoryEnvironmentUnit) FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) Test(org.junit.Test)

Example 2 with FileEnvironmentUnit

use of com.axway.ats.environment.file.FileEnvironmentUnit in project ats-framework by Axway.

the class Test_ConfigurationParser method testParsingMoreEnvironments.

@Test
public void testParsingMoreEnvironments() throws Exception {
    InputStream _descriptorFileStream = Test_ConfigurationParser.class.getClassLoader().getResourceAsStream("test_descriptors/test_agent_descriptor_with_more_env.xml");
    ConfigurationParser configParser = new ConfigurationParser();
    configParser.parse(_descriptorFileStream, jarFileAbsolutePath);
    List<ComponentEnvironment> environments = configParser.getEnvironments();
    assertEquals(2, environments.size());
    assertEquals("env1", environments.get(0).getEnvironmentName());
    assertEquals("env2", environments.get(1).getEnvironmentName());
    assertEquals(2, environments.get(0).getEnvironmentUnits().size());
    assertEquals(1, environments.get(1).getEnvironmentUnits().size());
    // check unit 1 of env1
    FileEnvironmentUnit fUnit1 = (FileEnvironmentUnit) environments.get(0).getEnvironmentUnits().get(0);
    assertEquals(0, fUnit1.getAdditionalActions().size());
    // check unit 2 of env1
    FileEnvironmentUnit fUnit2 = (FileEnvironmentUnit) environments.get(0).getEnvironmentUnits().get(1);
    assertEquals(1, fUnit2.getAdditionalActions().size());
    SystemProcessAction proc1 = (SystemProcessAction) fUnit2.getAdditionalActions().get(0);
    assertEquals(3, proc1.getSleepInterval());
    assertEquals(" shell command 'proc1'", proc1.getDescription());
    // check unit 1 of env2
    assertTrue(environments.get(1).getEnvironmentUnits().get(0) instanceof DirectoryEnvironmentUnit);
}
Also used : DirectoryEnvironmentUnit(com.axway.ats.environment.file.DirectoryEnvironmentUnit) InputStream(java.io.InputStream) SystemProcessAction(com.axway.ats.environment.process.SystemProcessAction) FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) Test(org.junit.Test)

Example 3 with FileEnvironmentUnit

use of com.axway.ats.environment.file.FileEnvironmentUnit in project ats-framework by Axway.

the class ConfigurationParser method parseFileEnvironment.

/**
     * Parse the file environment node in the Agent descriptor.
     *
     * @param fileEnvironmentNode the file environment node.
     * @throws AgentException on error.
     */
private EnvironmentUnit parseFileEnvironment(Node fileEnvironmentNode, String backupFolder) {
    // get the original file
    String originalFile = fileEnvironmentNode.getAttributes().getNamedItem("path").getNodeValue();
    originalFile = IoUtils.normalizeUnixFile(originalFile);
    // get the backup file
    String backupName;
    if (fileEnvironmentNode.getAttributes().getNamedItem("backupName") != null) {
        backupName = fileEnvironmentNode.getAttributes().getNamedItem("backupName").getNodeValue();
    } else {
        backupName = IoUtils.getFileName(originalFile);
    }
    // get the optional addition actions to executed on file restore
    List<AdditionalAction> additionalActions = parseAdditionalActions(fileEnvironmentNode);
    FileEnvironmentUnit fileEnvironment = new FileEnvironmentUnit(originalFile, backupFolder, backupName);
    fileEnvironment.addAdditionalActions(additionalActions);
    return fileEnvironment;
}
Also used : FileEnvironmentUnit(com.axway.ats.environment.file.FileEnvironmentUnit) AdditionalAction(com.axway.ats.environment.AdditionalAction)

Example 4 with FileEnvironmentUnit

use of com.axway.ats.environment.file.FileEnvironmentUnit 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)

Aggregations

FileEnvironmentUnit (com.axway.ats.environment.file.FileEnvironmentUnit)4 DirectoryEnvironmentUnit (com.axway.ats.environment.file.DirectoryEnvironmentUnit)3 EnvironmentUnit (com.axway.ats.environment.EnvironmentUnit)2 DatabaseEnvironmentUnit (com.axway.ats.environment.database.DatabaseEnvironmentUnit)2 SystemProcessAction (com.axway.ats.environment.process.SystemProcessAction)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 AdditionalAction (com.axway.ats.environment.AdditionalAction)1 ArrayList (java.util.ArrayList)1