Search in sources :

Example 11 with TestModel

use of org.jaffa.rules.TestModel 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());
}
Also used : IRuleEvaluator(org.jaffa.rules.rulemeta.IRuleEvaluator) RuleMetaData(org.jaffa.rules.meta.RuleMetaData) TestModel(org.jaffa.rules.TestModel) Test(org.junit.Test)

Example 12 with TestModel

use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.

the class RuleInitializerFactoryTest method testDifferent.

/**
 * Hits with different classes should return different instances.
 */
@Test
public void testDifferent() throws JaffaRulesFrameworkException {
    Initializer<TestModel> initializer1 = target.getInitializer(new TestModel());
    Initializer<FakeModel> initializer2 = target.getInitializer(new FakeModel());
    assertNotSame(initializer1, initializer2);
}
Also used : FakeModel(org.jaffa.persistence.FakeModel) TestModel(org.jaffa.rules.TestModel) Test(org.junit.Test)

Example 13 with TestModel

use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.

the class RuleInitializerFactoryTest method testVariation.

/**
 * Hits with different variations should return different instances.
 */
@Test
public void testVariation() throws JaffaRulesFrameworkException {
    Initializer<TestModel> initializer1 = target.getInitializer(new TestModel());
    VariationContext.setVariation("B");
    Initializer<TestModel> initializer2 = target.getInitializer(new TestModel());
    assertNotSame(initializer1, initializer2);
}
Also used : TestModel(org.jaffa.rules.TestModel) Test(org.junit.Test)

Example 14 with TestModel

use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.

the class CaseTypeValidatorTest method testInterceptor.

/**
 * Demonstrate that there's a proper situation for the CaseTypeInterceptor to change the case of the field.
 */
@Test
public void testInterceptor() throws Throwable {
    testModel.setField1(TEST_STRING);
    CaseTypeInterceptor interceptor = new CaseTypeInterceptor();
    interceptor.setTargetClassName(TestModel.class.getName());
    Method method = TestModel.class.getMethod("validate");
    MethodInvocation invocation = new MethodInvocation(new Interceptor[0], 0, method, method, null);
    // "field1" is configured to be UPPER CASE, but is set to all lower case.
    invocation.setTargetObject(testModel);
    interceptor.invoke(invocation);
    assertEquals(TEST_STRING.toUpperCase(), testModel.getField1());
}
Also used : CaseTypeInterceptor(org.jaffa.rules.jbossaop.interceptors.CaseTypeInterceptor) MethodInvocation(org.jboss.aop.joinpoint.MethodInvocation) Method(java.lang.reflect.Method) TestModel(org.jaffa.rules.TestModel) Test(org.junit.Test)

Example 15 with TestModel

use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.

the class MaxLengthValidatorTest method testValidator.

/**
 * If the field length is to long, the validator should throw a too much data field exception with the field label.
 */
@Test
public void testValidator() throws ApplicationException, FrameworkException {
    TestModel testModel = new TestModel();
    // max length is exceeded
    testModel.setField1("1234567891011");
    executeValidator(targetMaxLength, testModel, "[Field1]", TooMuchDataException.class);
}
Also used : 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