Search in sources :

Example 1 with NoSuchMetaDataKeyException

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;
}
Also used : DbMetaData(com.axway.ats.rbv.db.DbMetaData) Pattern(java.util.regex.Pattern) MetaDataIncorrectException(com.axway.ats.rbv.model.MetaDataIncorrectException) NoSuchMetaDataKeyException(com.axway.ats.rbv.model.NoSuchMetaDataKeyException) RbvException(com.axway.ats.rbv.model.RbvException)

Aggregations

DbMetaData (com.axway.ats.rbv.db.DbMetaData)1 MetaDataIncorrectException (com.axway.ats.rbv.model.MetaDataIncorrectException)1 NoSuchMetaDataKeyException (com.axway.ats.rbv.model.NoSuchMetaDataKeyException)1 RbvException (com.axway.ats.rbv.model.RbvException)1 Pattern (java.util.regex.Pattern)1