use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.
the class FieldInitializerTest method testInterceptor.
/**
* Tests the interceptor based initializer
*/
@Test
public void testInterceptor() throws Throwable {
TestModel testModel = new TestModel();
AbstractRuleInterceptor interceptor = new InitializeInterceptor();
interceptor.setTargetClassName(testModel.getClass().getName());
// this has to be a valid method, in production code it would be the constructor
Method method = TestModel.class.getMethod("validate");
MethodInvocation invocation = new MethodInvocation(new Interceptor[0], 0, method, method, null);
invocation.setTargetObject(testModel);
assertNull(testModel.getField1());
interceptor.invoke(invocation);
assertEquals(FIELD1_INIT_VALUE, testModel.getField1());
}
use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.
the class RuleInitializerFactoryTest method testCaching.
/**
* Multiple hits to the same class/realm/variation should return the same instance.
*/
@Test
public void testCaching() {
Initializer<TestModel> initializer1 = target.getInitializer(new TestModel());
Initializer<TestModel> initializer2 = target.getInitializer(new TestModel());
assertSame(initializer1, initializer2);
}
use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.
the class RuleInitializerFactoryTest method testInitializer.
/**
* If initialize rules are present for an object, an initializer should be returned.
*/
@Test
public void testInitializer() throws FrameworkException, ApplicationException {
TestModel model = new TestModel();
Initializer<TestModel> initializer = target.getInitializer(model);
initializer.initialize(model);
assertEquals(FieldInitializerTest.FIELD1_INIT_VALUE, model.getField1());
}
use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.
the class CommentValidatorTest method testInterceptor.
/**
* Demonstrate that there's a proper situation for the CommentInterceptor to change the value of the field.
*/
@Test
public void testInterceptor() throws Throwable {
testModel.setField1(NEW_COMMENT);
testModel.setOriginalValue("");
CommentInterceptor interceptor = new CommentInterceptor();
interceptor.setTargetClassName(TestModel.class.getName());
Method method = TestModel.class.getMethod("validate");
MethodInvocation invocation = new MethodInvocation(new Interceptor[0], 0, method, method, null);
// "field3" is configured for the comment
invocation.setTargetObject(testModel);
interceptor.invoke(invocation);
// if field1 has changed, them the comment was changed by the interceptor.
assertNotEquals(NEW_COMMENT, testModel.getField1());
}
use of org.jaffa.rules.TestModel in project jaffa-framework by jaffa-projects.
the class MaxLengthValidatorTest 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();
// max length not exceeded
testModel.setField1("123");
targetMaxLength.validate(testModel);
}
Aggregations