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