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());
}
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);
}
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;
}
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;
}
Aggregations