Search in sources :

Example 21 with TestModel

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);
}
Also used : TestModel(org.jaffa.rules.TestModel) Test(org.junit.Test)

Example 22 with 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));
}
Also used : IRuleEvaluator(org.jaffa.rules.rulemeta.IRuleEvaluator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RuleMetaData(org.jaffa.rules.meta.RuleMetaData) TestModel(org.jaffa.rules.TestModel) Test(org.junit.Test)

Aggregations

TestModel (org.jaffa.rules.TestModel)22 Test (org.junit.Test)22 Method (java.lang.reflect.Method)3 MethodInvocation (org.jboss.aop.joinpoint.MethodInvocation)3 RuleMetaData (org.jaffa.rules.meta.RuleMetaData)2 IRuleEvaluator (org.jaffa.rules.rulemeta.IRuleEvaluator)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 FakeModel (org.jaffa.persistence.FakeModel)1 AbstractRuleInterceptor (org.jaffa.rules.jbossaop.interceptors.AbstractRuleInterceptor)1 CaseTypeInterceptor (org.jaffa.rules.jbossaop.interceptors.CaseTypeInterceptor)1 CommentInterceptor (org.jaffa.rules.jbossaop.interceptors.CommentInterceptor)1 InitializeInterceptor (org.jaffa.rules.jbossaop.interceptors.InitializeInterceptor)1