use of com.axway.ats.rbv.model.NoSuchMetaDataKeyException 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 (NoSuchMetaDataKeyException nsmdke) {
log.warn(nsmdke.getMessage());
return false;
} 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;
}
Aggregations