Search in sources :

Example 1 with SystemProcessAction

use of com.axway.ats.environment.process.SystemProcessAction 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 SystemProcessAction

use of com.axway.ats.environment.process.SystemProcessAction 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 SystemProcessAction

use of com.axway.ats.environment.process.SystemProcessAction in project ats-framework by Axway.

the class ConfigurationParser method parseAdditionalActions.

/**
     * @param environmentNode
     * @return
     */
private List<AdditionalAction> parseAdditionalActions(Node environmentNode) {
    NodeList environmentNodeChildren = environmentNode.getChildNodes();
    List<AdditionalAction> actions = new ArrayList<AdditionalAction>();
    for (int i = 0; i < environmentNodeChildren.getLength(); i++) {
        Node environmentNodeChild = environmentNodeChildren.item(i);
        if (environmentNodeChild.getNodeName().equals("action")) {
            String shellCommand;
            int sleepInterval;
            Node shellCommandNode = environmentNodeChild.getAttributes().getNamedItem("command");
            Node sleepNode = environmentNodeChild.getAttributes().getNamedItem("sleep");
            if (shellCommandNode != null && sleepNode != null) {
                shellCommand = shellCommandNode.getNodeValue();
                sleepInterval = Integer.parseInt(sleepNode.getNodeValue().trim());
                actions.add(new SystemProcessAction(shellCommand, sleepInterval));
            }
        }
    }
    return actions;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) SystemProcessAction(com.axway.ats.environment.process.SystemProcessAction) AdditionalAction(com.axway.ats.environment.AdditionalAction)

Aggregations

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