Search in sources :

Example 6 with OracleEnvironmentHandler

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

the class Test_OracleEnvironmentHandler method createBackupNegativeNoColumns.

@Test()
public void createBackupNegativeNoColumns() throws DatabaseEnvironmentCleanupException, DbException, IOException, ParseException {
    DbTable table1 = new DbTable("table1");
    DbTable table2 = new DbTable("table2");
    OracleEnvironmentHandler envHandler = new OracleEnvironmentHandler(mockDbConnection, mockDbProvider);
    envHandler.addTable(table1);
    envHandler.addTable(table2);
    expect(mockDbConnection.getUser()).andReturn("myUserName");
    expect(mockDbProvider.select(isA(String.class))).andReturn(new DbRecordValuesList[] {});
    replay(mockDbConnection);
    replay(mockDbProvider);
    try {
        envHandler.writeBackupToFile(mockFileWriter);
    } catch (DbException e) {
        Assert.assertTrue(e.getMessage() != null && e.getMessage().startsWith("Could not get columns for table"));
    }
}
Also used : OracleEnvironmentHandler(com.axway.ats.environment.database.OracleEnvironmentHandler) DbTable(com.axway.ats.environment.database.model.DbTable) DbException(com.axway.ats.core.dbaccess.exceptions.DbException) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Example 7 with OracleEnvironmentHandler

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

the class Test_OracleEnvironmentHandler method createBackupNegativeSkippedColumnIsNotNullable.

@Test(expected = ColumnHasNoDefaultValueException.class)
public void createBackupNegativeSkippedColumnIsNotNullable() throws DatabaseEnvironmentCleanupException, DbException, IOException, ParseException {
    DbTable table1 = new DbTable("table1");
    List<String> columnsToSkip = new ArrayList<String>();
    columnsToSkip.add("name2");
    DbTable table2 = new DbTable("table2", columnsToSkip);
    //the columns meta data
    DbRecordValuesList column1MetaData = new DbRecordValuesList();
    column1MetaData.add(new DbRecordValue("", "COLUMN_NAME", "name1"));
    column1MetaData.add(new DbRecordValue("", "DATA_TYPE", "varchar(32)"));
    column1MetaData.add(new DbRecordValue("", "DATA_DEFAULT", true));
    DbRecordValuesList column2MetaData = new DbRecordValuesList();
    column2MetaData.add(new DbRecordValue("", "COLUMN_NAME", "name2"));
    column2MetaData.add(new DbRecordValue("", "DATA_TYPE", "varchar(32)"));
    column2MetaData.add(new DbRecordValue("", "DATA_DEFAULT", null));
    DbRecordValuesList column3MetaData = new DbRecordValuesList();
    column3MetaData.add(new DbRecordValue("", "COLUMN_NAME", "name3"));
    column3MetaData.add(new DbRecordValue("", "DATA_TYPE", "bit"));
    column3MetaData.add(new DbRecordValue("", "DATA_DEFAULT", 1));
    DbRecordValuesList[] columnsMetaData = new DbRecordValuesList[] { column1MetaData, column2MetaData, column3MetaData };
    DbRecordValuesList record1Value = new DbRecordValuesList();
    record1Value.add(new DbRecordValue("table1", "name1", "value1"));
    record1Value.add(new DbRecordValue("table1", "name2", null));
    record1Value.add(new DbRecordValue("table1", "name3", new String(new char[] { 1 })));
    DbRecordValuesList[] recordValues = new DbRecordValuesList[] { record1Value };
    OracleEnvironmentHandler envHandler = new OracleEnvironmentHandler(mockDbConnection, mockDbProvider);
    envHandler.addTable(table1);
    envHandler.addTable(table2);
    expect(mockDbConnection.getUser()).andReturn("myUserName").atLeastOnce();
    expect(mockDbProvider.select(isA(String.class))).andReturn(columnsMetaData);
    expect(mockDbProvider.select(isA(DbQuery.class), eq(DbReturnModes.ESCAPED_STRING))).andReturn(recordValues);
    expect(mockDbProvider.select(isA(String.class))).andReturn(columnsMetaData);
    expect(mockDbProvider.select(isA(DbQuery.class), eq(DbReturnModes.ESCAPED_STRING))).andReturn(recordValues);
    replay(mockDbConnection);
    replay(mockDbProvider);
    envHandler.writeBackupToFile(mockFileWriter);
    verify(mockDbConnection);
    verify(mockDbProvider);
}
Also used : DbRecordValuesList(com.axway.ats.core.dbaccess.DbRecordValuesList) DbQuery(com.axway.ats.common.dbaccess.DbQuery) DbRecordValue(com.axway.ats.core.dbaccess.DbRecordValue) OracleEnvironmentHandler(com.axway.ats.environment.database.OracleEnvironmentHandler) ArrayList(java.util.ArrayList) DbTable(com.axway.ats.environment.database.model.DbTable) BaseTest(com.axway.ats.environment.BaseTest) Test(org.junit.Test)

Aggregations

BaseTest (com.axway.ats.environment.BaseTest)7 OracleEnvironmentHandler (com.axway.ats.environment.database.OracleEnvironmentHandler)7 Test (org.junit.Test)7 DbTable (com.axway.ats.environment.database.model.DbTable)5 DbRecordValue (com.axway.ats.core.dbaccess.DbRecordValue)4 DbRecordValuesList (com.axway.ats.core.dbaccess.DbRecordValuesList)4 DbQuery (com.axway.ats.common.dbaccess.DbQuery)3 ArrayList (java.util.ArrayList)2 DbException (com.axway.ats.core.dbaccess.exceptions.DbException)1 SQLException (java.sql.SQLException)1