Search in sources :

Example 16 with DbMetaData

use of com.axway.ats.rbv.db.DbMetaData in project ats-framework by Axway.

the class Test_DbBinaryFieldRule method isMatchExpectedFalseNegative.

@Test
public void isMatchExpectedFalseNegative() throws RbvException {
    DbMetaData metaData = new DbMetaData();
    metaData.putProperty("table.column", new byte[] { 0, 2 });
    assertFalse(ruleTest1ExpectFalse.isMatch(metaData));
}
Also used : DbMetaData(com.axway.ats.rbv.db.DbMetaData) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 17 with DbMetaData

use of com.axway.ats.rbv.db.DbMetaData in project ats-framework by Axway.

the class DbBooleanFieldRule method performMatch.

@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
    //this cast is safe, as isMatch has already checked the type of meta data
    DbMetaData dbMetaData = (DbMetaData) metaData;
    Boolean actual = null;
    Object actualValue = dbMetaData.getProperty(this.expectedMetaDataKey.toString());
    // check for null        
    if (this.expectedValue == null) {
        if (actualValue == null) {
            return true;
        }
        return false;
    }
    if (actualValue == null) {
        return false;
    }
    // check if the value is of type String
    if (actualValue instanceof String) {
        if ("0".equals(actualValue)) {
            actual = false;
        } else if ("1".equals(actualValue)) {
            actual = true;
        } else {
            throw new MetaDataIncorrectException("Meta data is incorrect. Received a String containing : " + actualValue);
        }
    }
    // check if value is of type Number
    if (actualValue instanceof Number) {
        Number actualNumber = (Number) actualValue;
        if (actualNumber.byteValue() != actualNumber.doubleValue()) {
            // this would mean that the value has floating point digits which is wrong
            throw new MetaDataIncorrectException("Meta data is incorrect. Received a Number containing floating point digits: " + actualValue);
        }
        if (actualNumber.byteValue() == 0) {
            actual = false;
        } else if (actualNumber.byteValue() == 1) {
            actual = true;
        } else {
            throw new MetaDataIncorrectException("Meta data is incorrect. Received a Number containing : " + actualValue);
        }
    }
    // check if value is of type Number
    if (actualValue instanceof Boolean) {
        actual = (Boolean) actualValue;
    }
    boolean expected = ((Boolean) this.expectedValue).booleanValue();
    if (actual == null) {
        throw new MetaDataIncorrectException("Meta data is incorrect. Unexpected type of the value in the database : " + actualValue.getClass().getCanonicalName());
    }
    if (expected == actual) {
        return true;
    }
    return false;
}
Also used : DbMetaData(com.axway.ats.rbv.db.DbMetaData) MetaDataIncorrectException(com.axway.ats.rbv.model.MetaDataIncorrectException)

Example 18 with DbMetaData

use of com.axway.ats.rbv.db.DbMetaData in project ats-framework by Axway.

the class DbNumericFieldRule method performMatch.

@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
    boolean actualResult = false;
    //this cast is safe, as isMatch has already checked the type of meta data            
    DbMetaData dbMetaData = (DbMetaData) metaData;
    Number actualValue;
    try {
        actualValue = (Number) dbMetaData.getProperty(expectedMetaDataKey.toString());
        log.info("Actual value is '" + actualValue + "'");
    } catch (ClassCastException cce) {
        throw new MetaDataIncorrectException("Meta data is incorrect - expected Number");
    }
    if (expectedValue == null) {
        return actualValue == null;
    } else {
        if (actualValue == null) {
            return false;
        }
    }
    if (!expectedValue.getClass().getName().equals(actualValue.getClass().getName())) {
        log.info("Type of expected value '" + expectedValue.getClass().getSimpleName() + "' is different than type of actual value '" + actualValue.getClass().getSimpleName() + "'");
        return false;
    }
    if (expectedValue.equals(actualValue)) {
        actualResult = true;
    }
    return actualResult;
}
Also used : DbMetaData(com.axway.ats.rbv.db.DbMetaData) MetaDataIncorrectException(com.axway.ats.rbv.model.MetaDataIncorrectException)

Example 19 with DbMetaData

use of com.axway.ats.rbv.db.DbMetaData in project ats-framework by Axway.

the class DbStringFieldRule method performMatch.

@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
    boolean actualResult = false;
    //this cast is safe, as isMatch has already checked the type of meta data
    DbMetaData dbMetaData = (DbMetaData) metaData;
    String actualValue;
    try {
        actualValue = (String) dbMetaData.getProperty(expectedMetaDataKey.toString());
        if (dbEncryptor != null) {
            actualValue = dbEncryptor.decrypt(actualValue);
        }
        log.info("Actual value is '" + actualValue + "'");
    } catch (ClassCastException cce) {
        throw new MetaDataIncorrectException("Meta data is incorrect - expected String");
    }
    if (expectedValue == null) {
        return actualValue == null;
    } else {
        if (actualValue == null) {
            return false;
        }
    }
    if (relation == MatchRelation.EQUALS) {
        actualResult = expectedValue.equals(actualValue);
    } else if (relation == MatchRelation.CONTAINS) {
        actualResult = actualValue.contains((String) expectedValue);
    } else if (relation == MatchRelation.REGEX_MATCH) {
        Pattern regexPattern = Pattern.compile((String) expectedValue);
        actualResult = regexPattern.matcher(actualValue).matches();
    } else {
        throw new RbvException("No implementation for MatchRelation '" + relation.toString() + "' in DbStringFieldMatchingTerm");
    }
    return actualResult;
}
Also used : DbMetaData(com.axway.ats.rbv.db.DbMetaData) Pattern(java.util.regex.Pattern) MetaDataIncorrectException(com.axway.ats.rbv.model.MetaDataIncorrectException) RbvException(com.axway.ats.rbv.model.RbvException)

Example 20 with DbMetaData

use of com.axway.ats.rbv.db.DbMetaData in project ats-framework by Axway.

the class Test_DbStringFieldRule method isMatchExpectedFalseMultipleRulesNegative.

@Test
public void isMatchExpectedFalseMultipleRulesNegative() throws RbvException {
    DbMetaData metaData = new DbMetaData();
    metaData.putProperty("test1", "test");
    metaData.putProperty("test2", "test");
    AndRuleOperation andRule = new AndRuleOperation();
    andRule.addRule(ruleTest1ExpectFalse);
    andRule.addRule(ruleTest2ExpectFalse);
    assertFalse(andRule.isMatch(metaData));
}
Also used : DbMetaData(com.axway.ats.rbv.db.DbMetaData) AndRuleOperation(com.axway.ats.rbv.rules.AndRuleOperation) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Aggregations

DbMetaData (com.axway.ats.rbv.db.DbMetaData)57 BaseTest (com.axway.ats.rbv.BaseTest)50 Test (org.junit.Test)50 AndRuleOperation (com.axway.ats.rbv.rules.AndRuleOperation)20 MetaData (com.axway.ats.rbv.MetaData)16 DbStringFieldRule (com.axway.ats.rbv.db.rules.DbStringFieldRule)15 SnapshotExecutor (com.axway.ats.rbv.executors.SnapshotExecutor)15 MetaDataIncorrectException (com.axway.ats.rbv.model.MetaDataIncorrectException)4 ArrayList (java.util.ArrayList)2 DbMetaDataKey (com.axway.ats.rbv.db.DbMetaDataKey)1 DbDateFieldRule (com.axway.ats.rbv.db.rules.DbDateFieldRule)1 RbvException (com.axway.ats.rbv.model.RbvException)1 Rule (com.axway.ats.rbv.rules.Rule)1 Calendar (java.util.Calendar)1 Pattern (java.util.regex.Pattern)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1