Search in sources :

Example 1 with CommentInterceptor

use of org.jaffa.rules.jbossaop.interceptors.CommentInterceptor 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());
}
Also used : CommentInterceptor(org.jaffa.rules.jbossaop.interceptors.CommentInterceptor) MethodInvocation(org.jboss.aop.joinpoint.MethodInvocation) Method(java.lang.reflect.Method) TestModel(org.jaffa.rules.TestModel) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)1 TestModel (org.jaffa.rules.TestModel)1 CommentInterceptor (org.jaffa.rules.jbossaop.interceptors.CommentInterceptor)1 MethodInvocation (org.jboss.aop.joinpoint.MethodInvocation)1 Test (org.junit.Test)1