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());
}
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);
}
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);
}
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());
}
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);
}
Aggregations