Search in sources :

Example 1 with DatabaseOperations

use of com.axway.ats.action.dbaccess.DatabaseOperations in project ats-framework by Axway.

the class DatabaseBackupRestoreTests method init.

@BeforeMethod
public void init() {
    serverBox = new TestBox();
    serverBox.setHost(configuration.getDatabaseHost());
    serverBox.setDbType(configuration.getDatabaseType());
    serverBox.setDbName(configuration.getBackupDatabaseName());
    serverBox.setDbUser(configuration.getDatabaseUser());
    serverBox.setDbPass(configuration.getDatabasePassword());
    serverBox.setDbPort(String.valueOf(configuration.getDbPort()));
    // establish DB connection
    dbOperations = new DatabaseOperations(serverBox);
    dbConn = new DbConnPostgreSQL(configuration.getDatabaseHost(), port, configuration.getBackupDatabaseName(), configuration.getDatabaseUser(), configuration.getDatabasePassword(), null);
    // establish tables which to be inspected
    dbTables = new ArrayList<>();
    dbTables.add(new DbTable(TABLE));
}
Also used : TestBox(com.axway.ats.harness.config.TestBox) DatabaseOperations(com.axway.ats.action.dbaccess.DatabaseOperations) DbConnPostgreSQL(com.axway.ats.core.dbaccess.postgresql.DbConnPostgreSQL) DbTable(com.axway.ats.environment.database.model.DbTable)

Example 2 with DatabaseOperations

use of com.axway.ats.action.dbaccess.DatabaseOperations in project ats-framework by Axway.

the class DatabaseVerificationTests method beforeMethod.

/**
 * Prior to each test we make sure we have the table we worked with
 * is in same state
 */
@BeforeMethod
public void beforeMethod() {
    // initialize all connection parameters
    dbServerBox = new TestBox();
    dbServerBox.setHost(configuration.getDatabaseHost());
    dbServerBox.setDbType(configuration.getDatabaseType());
    dbServerBox.setDbName(configuration.getDatabaseName());
    dbServerBox.setDbUser(configuration.getDatabaseUser());
    dbServerBox.setDbPass(configuration.getDatabasePassword());
    dbServerBox.setDbPort(String.valueOf(configuration.getDbPort()));
    // initialize this helper class
    dbOperations = new DatabaseOperations(dbServerBox);
    // cleanup the table we use and fill it with the needed data
    dbOperations.delete(TABLE, "1=1");
    dbOperations.insertValues(TABLE, new String[] { "id", "firstName", "lastName", "age" }, new String[] { "1", "Chuck", "Norris", "70" });
    dbOperations.insertValues(TABLE, new String[] { "id", "firstName", "lastName", "age" }, new String[] { "2", "Jackie", "Chan", "64" });
    // Initialize the class we will use in our tests
    dbVerification = new DbVerification(dbServerBox, TABLE);
}
Also used : TestBox(com.axway.ats.harness.config.TestBox) DatabaseOperations(com.axway.ats.action.dbaccess.DatabaseOperations) DbVerification(com.axway.ats.rbv.clients.DbVerification) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with DatabaseOperations

use of com.axway.ats.action.dbaccess.DatabaseOperations in project ats-framework by Axway.

the class DatabaseOperationTests method beforeMethod.

/**
 * Prior to each test we make sure we have the table we worked with
 * is in same state
 */
@BeforeMethod
public void beforeMethod() {
    // Here we define all connection parameters
    TestBox serverBox = new TestBox();
    serverBox.setHost(configuration.getDatabaseHost());
    serverBox.setDbType(configuration.getDatabaseType());
    serverBox.setDbName(configuration.getDatabaseName());
    serverBox.setDbUser(configuration.getDatabaseUser());
    serverBox.setDbPass(configuration.getDatabasePassword());
    serverBox.setDbPort(String.valueOf(configuration.getDbPort()));
    // establish DB connection
    dbOperations = new DatabaseOperations(serverBox);
    // cleanup the table we use and fill it with the needed data
    dbOperations.delete(TABLE, "1=1");
    dbOperations.insertValues(TABLE, new String[] { "id", "firstName", "lastName", "age" }, new String[] { "1", "Chuck", "Norris", "70" });
    dbOperations.insertValues(TABLE, new String[] { "id", "firstName", "lastName", "age" }, new String[] { "2", "Jackie", "Chan", "64" });
}
Also used : TestBox(com.axway.ats.harness.config.TestBox) DatabaseOperations(com.axway.ats.action.dbaccess.DatabaseOperations) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with DatabaseOperations

use of com.axway.ats.action.dbaccess.DatabaseOperations in project ats-framework by Axway.

the class AtsVersionVerifier method getDatabaseVersion.

private static String getDatabaseVersion(TestBox box, Map<String, Object> properties) {
    DatabaseOperations dbOps = new DatabaseOperations(box, properties);
    try {
        String query = null;
        if (box.getDbType().equals(DbConnSQLServer.DATABASE_TYPE)) {
            query = "SELECT value from tInternal where [key] = 'version'";
        } else if (box.getDbType().equals(DbConnPostgreSQL.DATABASE_TYPE)) {
            query = "SELECT value from \"tInternal\" where key = 'version'";
        } else {
            throw new UnsupportedOperationException("Could not construct statement query for getting database version for connection of class '" + box.getDbType() + "'");
        }
        DatabaseRow[] rows = dbOps.getDatabaseData(query);
        if (rows != null) {
            for (DatabaseRow row : rows) {
                return row.getCellValue("version");
            }
        }
        throw new RuntimeException(String.format("SQL Select Query '%s' returned 0 (zero) results!", query));
    } catch (Exception e) {
        throw new RuntimeException(String.format("Could not get ATS Version for ATS Log Database at %s%s", box.toString(), (properties != null && !properties.isEmpty()) ? " with custom properties " + properties.toString() : ""), e);
    } finally {
        if (dbOps != null) {
            dbOps.disconnect();
        }
    }
}
Also used : DatabaseOperations(com.axway.ats.action.dbaccess.DatabaseOperations) DatabaseRow(com.axway.ats.action.dbaccess.model.DatabaseRow)

Aggregations

DatabaseOperations (com.axway.ats.action.dbaccess.DatabaseOperations)4 TestBox (com.axway.ats.harness.config.TestBox)3 BeforeMethod (org.testng.annotations.BeforeMethod)2 DatabaseRow (com.axway.ats.action.dbaccess.model.DatabaseRow)1 DbConnPostgreSQL (com.axway.ats.core.dbaccess.postgresql.DbConnPostgreSQL)1 DbTable (com.axway.ats.environment.database.model.DbTable)1 DbVerification (com.axway.ats.rbv.clients.DbVerification)1