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