Search in sources :

Example 6 with DatabaseEnvironmentUnit

use of com.axway.ats.environment.database.DatabaseEnvironmentUnit in project ats-framework by Axway.

the class Test_ConfigurationParser method getEnvironmentUnitsWithPort.

@Test
public void getEnvironmentUnitsWithPort() throws Exception {
    InputStream descriptorFileStream = Test_ConfigurationParser.class.getResourceAsStream("descriptor_with_port.xml");
    ConfigurationParser configParser = new ConfigurationParser();
    configParser.parse(descriptorFileStream, jarFileAbsolutePath);
    List<EnvironmentUnit> environmentUnits = configParser.getEnvironments().get(0).getEnvironmentUnits();
    assertEquals(3, environmentUnits.size());
    assertEquals(DatabaseEnvironmentUnit.class, environmentUnits.get(0).getClass());
    assertEquals(FileEnvironmentUnit.class, environmentUnits.get(1).getClass());
    assertEquals(FileEnvironmentUnit.class, environmentUnits.get(2).getClass());
    // check connection properties
    DatabaseEnvironmentUnit dbUnit = (DatabaseEnvironmentUnit) configParser.getEnvironments().get(0).getEnvironmentUnits().get(0);
    assertEquals("127.127.127.127", dbUnit.getDbConnection().getHost());
    assertEquals("st", dbUnit.getDbConnection().getDb());
    assertEquals("root", dbUnit.getDbConnection().getUser());
    assertEquals("axway", dbUnit.getDbConnection().getPassword());
    assertEquals("mysql".toUpperCase(), dbUnit.getDbConnection().getDbType().toString());
    Map<String, Object> customDbConnectionProperties = dbUnit.getDbConnection().getCustomProperties();
    assertEquals(33060, customDbConnectionProperties.get(DbKeys.PORT_KEY));
}
Also used : InputStream(java.io.InputStream) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) 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) Test(org.junit.Test)

Example 7 with DatabaseEnvironmentUnit

use of com.axway.ats.environment.database.DatabaseEnvironmentUnit in project ats-framework by Axway.

the class Test_ConfigurationParser method checkDbEnvironmentUnit_OracleServiceName.

@Test
public void checkDbEnvironmentUnit_OracleServiceName() throws Exception {
    InputStream descriptorFileStream = Test_ConfigurationParser.class.getResourceAsStream("descriptor_oracle_with_service_name.xml");
    ConfigurationParser configParser = new ConfigurationParser();
    configParser.parse(descriptorFileStream, jarFileAbsolutePath);
    assertEquals(DatabaseEnvironmentUnit.class, configParser.getEnvironments().get(0).getEnvironmentUnits().get(0).getClass());
    DatabaseEnvironmentUnit dbUnit = (DatabaseEnvironmentUnit) configParser.getEnvironments().get(0).getEnvironmentUnits().get(0);
    Map<String, Object> customDbConnectionProperties = dbUnit.getDbConnection().getCustomProperties();
    // check the Service Name
    assertEquals("some_service_name", customDbConnectionProperties.get(OracleKeys.SERVICE_NAME_KEY));
    // check that the URL is right (using the service name correctly)
    assertEquals("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=some_service_name)))", dbUnit.getDbConnection().getURL());
}
Also used : InputStream(java.io.InputStream) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) Test(org.junit.Test)

Example 8 with DatabaseEnvironmentUnit

use of com.axway.ats.environment.database.DatabaseEnvironmentUnit in project ats-framework by Axway.

the class ConfigurationParser method parseDbEnvironment.

/**
     * Parse the database environment node in the Agent descriptor.
     *
     * @param dbEnvironmentNode the DB environment node.
     * @throws AgentException on error.
     */
private EnvironmentUnit parseDbEnvironment(Node dbEnvironmentNode, String backupFolder) throws AgentException {
    //create the connection descriptor
    DbConnection dbConnection = createConnection(dbEnvironmentNode.getAttributes());
    //read the tables
    List<DbTable> dbTables = new ArrayList<DbTable>();
    NodeList dbChildNodes = dbEnvironmentNode.getChildNodes();
    for (int k = 0; k < dbChildNodes.getLength(); k++) {
        Node dbChildNode = dbChildNodes.item(k);
        if (dbChildNode.getNodeName().equals(TABLE)) {
            String tableName = dbChildNode.getAttributes().getNamedItem("name").getNodeValue();
            String[] columnsToExclude = {};
            if (dbChildNode.getAttributes().getNamedItem("columnsToExclude") != null) {
                columnsToExclude = dbChildNode.getAttributes().getNamedItem("columnsToExclude").getNodeValue().split(",");
            }
            DbTable dbTable = null;
            // parse db table 'lock' attribute
            if (dbChildNode.getAttributes().getNamedItem("lock") != null) {
                if (dbConnection.getDbType().equals(DbConnOracle.DATABASE_TYPE)) {
                    log.warn("Db table 'lock' attribute is NOT implemented for Oracle yet. " + "Table locking is skipped for the moment.");
                }
                String nodeValue = dbChildNode.getAttributes().getNamedItem("lock").getNodeValue().trim();
                if ("false".equalsIgnoreCase(nodeValue) || "true".equalsIgnoreCase(nodeValue)) {
                    dbTable = new DbTable(tableName, Arrays.asList(columnsToExclude), Boolean.parseBoolean(nodeValue));
                } else {
                    log.warn("Invalid db table 'lock' attribute value '" + nodeValue + "'. Valid values are 'true' and 'false'. The default value 'true' will be used.");
                }
            }
            if (dbTable == null) {
                dbTable = new DbTable(tableName, Arrays.asList(columnsToExclude));
            }
            // parse db table 'autoIncrementResetValue' attribute
            if (dbChildNode.getAttributes().getNamedItem(TABLE_ATTR_AUTOINCR_RESET_VALUE) != null) {
                if (dbConnection.getDbType().equals(DbConnOracle.DATABASE_TYPE)) {
                    throw new AgentException("Db table 'autoIncrementResetValue' attribute is NOT implemented for Oracle yet.");
                }
                String autoInrcResetValue = dbChildNode.getAttributes().getNamedItem(TABLE_ATTR_AUTOINCR_RESET_VALUE).getNodeValue().trim();
                try {
                    Integer.parseInt(autoInrcResetValue);
                } catch (NumberFormatException nfe) {
                    throw new AgentException("Ivalid db table 'autoIncrementResetValue' attribute value '" + autoInrcResetValue + "'. It must be valid number.");
                }
                dbTable.setAutoIncrementResetValue(autoInrcResetValue);
            }
            dbTables.add(dbTable);
        }
    }
    String backupFileName = componentName + "-" + dbConnection.getDb() + ".sql";
    //create the environment unit
    DatabaseEnvironmentUnit dbEnvironment = new DatabaseEnvironmentUnit(backupFolder, backupFileName, dbConnection, dbTables);
    return dbEnvironment;
}
Also used : AgentException(com.axway.ats.agent.core.exceptions.AgentException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) DbConnection(com.axway.ats.core.dbaccess.DbConnection) DbTable(com.axway.ats.environment.database.model.DbTable)

Example 9 with DatabaseEnvironmentUnit

use of com.axway.ats.environment.database.DatabaseEnvironmentUnit 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 10 with DatabaseEnvironmentUnit

use of com.axway.ats.environment.database.DatabaseEnvironmentUnit in project ats-framework by Axway.

the class MockDbEnvironmentUnit method testChangingHost.

@Test
public void testChangingHost() throws ConfigurationException {
    Properties properties = new Properties();
    properties.put(EnvironmentConfigurator.DB_CONFIGURATION_INDEX, 0);
    properties.put(EnvironmentConfigurator.DB_HOST, "new_test_host");
    EnvironmentConfigurator environmentConfigurator = new EnvironmentConfigurator(COMPONENT_NAME, Arrays.asList(properties));
    assertTrue(environmentConfigurator.needsApplying());
    environmentConfigurator.apply();
    DatabaseEnvironmentUnit dbEnvUnit = (DatabaseEnvironmentUnit) testComponent.getEnvironments().get(0).getEnvironmentUnits().get(0);
    assertEquals("new_test_host", dbEnvUnit.getDbConnection().getHost());
}
Also used : DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

DatabaseEnvironmentUnit (com.axway.ats.environment.database.DatabaseEnvironmentUnit)14 Test (org.junit.Test)11 Properties (java.util.Properties)6 ArrayList (java.util.ArrayList)5 DbTable (com.axway.ats.environment.database.model.DbTable)4 BaseTest (com.axway.ats.environment.BaseTest)3 EnvironmentUnit (com.axway.ats.environment.EnvironmentUnit)3 InputStream (java.io.InputStream)3 DbConnection (com.axway.ats.core.dbaccess.DbConnection)2 DirectoryEnvironmentUnit (com.axway.ats.environment.file.DirectoryEnvironmentUnit)2 FileEnvironmentUnit (com.axway.ats.environment.file.FileEnvironmentUnit)2 ComponentEnvironment (com.axway.ats.agent.core.ComponentEnvironment)1 ComponentRepository (com.axway.ats.agent.core.ComponentRepository)1 AgentException (com.axway.ats.agent.core.exceptions.AgentException)1 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1