Search in sources :

Example 1 with InitializeInterceptor

use of org.jaffa.rules.jbossaop.interceptors.InitializeInterceptor 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());
}
Also used : AbstractRuleInterceptor(org.jaffa.rules.jbossaop.interceptors.AbstractRuleInterceptor) MethodInvocation(org.jboss.aop.joinpoint.MethodInvocation) InitializeInterceptor(org.jaffa.rules.jbossaop.interceptors.InitializeInterceptor) 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 AbstractRuleInterceptor (org.jaffa.rules.jbossaop.interceptors.AbstractRuleInterceptor)1 InitializeInterceptor (org.jaffa.rules.jbossaop.interceptors.InitializeInterceptor)1 MethodInvocation (org.jboss.aop.joinpoint.MethodInvocation)1 Test (org.junit.Test)1