use of org.jaffa.rules.rulemeta.IRuleEvaluator in project jaffa-framework by jaffa-projects.
the class FieldInitializerTest method testConditionalInitialization.
/**
* If a condition exists for the rule, it should be evaluated.
*/
@Test
public void testConditionalInitialization() throws FrameworkException, ApplicationExceptions {
TestModel testModel = new TestModel();
IRuleEvaluator evaluator = mock(IRuleEvaluator.class);
when(evaluator.checkCondition(anyObject(), any(RuleMetaData.class))).thenReturn(false);
target.setRuleEvaluator(evaluator);
target.initialize(testModel);
// Neither field should have been initialized.
assertNull(testModel.getField1());
assertNull(testModel.getField2());
}
use of org.jaffa.rules.rulemeta.IRuleEvaluator 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