use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.
the class MinValueValidatorTest method testNoFailure.
/**
* If the one rule is satisfied, there should be no validation exception.
*/
@Test
public void testNoFailure() throws ApplicationException, FrameworkException {
TestModel testModel = new TestModel();
// min value not exceeded
testModel.setField2(7);
targetMinValue.validate(testModel);
}
use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.
the class RuleValidatorTest method testConditionalValidation.
/**
* When a condition is specified on a rule, property validation should only be called if the condition is true.
*/
@Test
public void testConditionalValidation() throws FrameworkException, ApplicationExceptions, ApplicationException {
TestValidator target = new TestValidator();
IRuleEvaluator ruleEvaluator = mock(IRuleEvaluator.class);
target.setRuleEvaluator(ruleEvaluator);
Map<String, List<RuleMetaData>> ruleMap = new HashMap<>();
List<RuleMetaData> rules = new ArrayList<>();
RuleMetaData trueCondition = new RuleMetaData();
rules.add(trueCondition);
RuleMetaData falseCondition = new RuleMetaData();
rules.add(falseCondition);
ruleMap.put("field1", rules);
target.setRuleMap(ruleMap);
TestModel obj = new TestModel();
obj.setField1("value");
when(ruleEvaluator.checkCondition(obj, trueCondition)).thenReturn(true);
target.validate(obj);
assertEquals(1, target.validatedRules.size());
assertEquals(trueCondition, target.validatedRules.get(0));
}
Aggregations