Search in sources :

Example 1 with Foo

use of jodd.proxetta.data.Foo in project jodd by oblac.

the class MethodInfoTest method testMethodInfo.

@Test
public void testMethodInfo() {
    final ValueHolder<MethodInfo> valueHolder = ValueHolderWrapper.create();
    ProxyAspect proxyAspect = new ProxyAspect(FooProxyAdvice.class, new ProxyPointcut() {

        public boolean apply(MethodInfo methodInfo) {
            if (methodInfo.getMethodName().equals("p1")) {
                valueHolder.set(methodInfo);
                return true;
            }
            return false;
        }
    });
    ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(proxyAspect);
    proxyProxetta.setClassNameSuffix("$$$Proxetta888");
    ProxyProxettaBuilder pb = proxyProxetta.builder();
    pb.setTarget(Foo.class);
    Foo foo = (Foo) pb.newInstance();
    assertNotNull(foo);
    MethodInfo mi = valueHolder.get();
    assertEquals("p1", mi.getMethodName());
    assertEquals(Foo.class.getName().replace('.', '/'), mi.getClassname());
    assertEquals("(java.lang.String)", mi.getDeclaration());
    assertEquals("(Ljava/lang/String;)Ljava/lang/String;", mi.getDescription());
    assertEquals("java.lang.String", mi.getReturnType());
    assertEquals("Ljava/lang/String;", mi.getReturnTypeName());
    assertEquals("java.lang.String p1(java.lang.String)", mi.getSignature());
    assertEquals(1, mi.getArgumentsCount());
    assertEquals("Ljava/lang/String;", mi.getArgumentTypeName(1));
    assertTrue(mi.isTopLevelMethod());
    AnnotationInfo[] anns = mi.getArgumentAnnotations(0);
    assertNotNull(anns);
    assertEquals(1, anns.length);
    assertEquals(FooAnn.class.getName(), anns[0].getAnnotationClassname());
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder) Foo(jodd.proxetta.data.Foo) FooAnn(jodd.proxetta.data.FooAnn) Test(org.junit.Test)

Example 2 with Foo

use of jodd.proxetta.data.Foo in project jodd by oblac.

the class AdviceWithMethodTest method testCollector.

@Test
public void testCollector() throws NoSuchFieldException, IllegalAccessException {
    ProxyProxetta proxetta = ProxyProxetta.withAspects(new ProxyAspect(CollectorAdvice.class, new AllTopMethodsPointcut()));
    //		proxetta.setDebugFolder("d:\\");
    Foo foo = (Foo) proxetta.builder(Foo.class).newInstance();
    Field field = foo.getClass().getDeclaredField("$__methods$0");
    field.setAccessible(true);
    List<String> list = (List<String>) field.get(foo);
    assertNotNull(list);
    assertEquals(0, list.size());
    foo.m1();
    assertEquals(1, list.size());
    assertEquals("m1", list.get(0));
    foo.m1();
    assertEquals(2, list.size());
    assertEquals("m1", list.get(0));
    assertEquals("m1", list.get(1));
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) Field(java.lang.reflect.Field) Foo(jodd.proxetta.data.Foo) AllTopMethodsPointcut(jodd.proxetta.pointcuts.AllTopMethodsPointcut) CollectorAdvice(jodd.proxetta.data.CollectorAdvice) List(java.util.List) Test(org.junit.Test)

Aggregations

Foo (jodd.proxetta.data.Foo)2 ProxyProxetta (jodd.proxetta.impl.ProxyProxetta)2 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 List (java.util.List)1 CollectorAdvice (jodd.proxetta.data.CollectorAdvice)1 FooAnn (jodd.proxetta.data.FooAnn)1 ProxyProxettaBuilder (jodd.proxetta.impl.ProxyProxettaBuilder)1 AllTopMethodsPointcut (jodd.proxetta.pointcuts.AllTopMethodsPointcut)1