Search in sources :

Example 6 with WrapperProxettaBuilder

use of jodd.proxetta.impl.WrapperProxettaBuilder in project jodd by oblac.

the class WrapperTest method testClassWrapper.

@Test
public void testClassWrapper() throws Exception {
    Calc calc = new CalcImpl();
    WrapperProxetta proxetta = WrapperProxetta.withAspects(new ProxyAspect(StatCounterAdvice.class, new ProxyPointcutSupport() {

        public boolean apply(MethodInfo methodInfo) {
            return !isRootMethod(methodInfo) && isPublic(methodInfo);
        }
    }));
    //		proxetta.setDebugFolder("d:\\");
    // wrapper over CLASS
    // resulting object has ALL interfaces
    // resulting object wraps ALL target class methods
    WrapperProxettaBuilder builder = proxetta.builder(calc.getClass());
    Class calc2Class = builder.define();
    Object object = calc2Class.newInstance();
    assertTrue(object instanceof Calc);
    assertEquals(CalcImpl.class, ProxettaUtil.getTargetClass(object.getClass()));
    assertEquals(1, calc2Class.getInterfaces().length);
    builder.injectTargetIntoWrapper(calc, object);
    // counter in static block !!!
    assertEquals(1, StatCounter.counter);
    Method method = calc2Class.getMethod("hello");
    assertNotNull(method);
    method.invoke(object);
    assertEquals(2, StatCounter.counter);
    method = calc2Class.getMethod("calculate", int.class, int.class);
    assertNotNull(method);
    Integer result = (Integer) method.invoke(object, 3, 7);
    assertEquals(10, result.intValue());
    assertEquals(3, StatCounter.counter);
    assertNotNull(calc2Class.getMethod("customMethod"));
}
Also used : WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) WrapperProxetta(jodd.proxetta.impl.WrapperProxetta) ProxyPointcutSupport(jodd.proxetta.pointcuts.ProxyPointcutSupport) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 7 with WrapperProxettaBuilder

use of jodd.proxetta.impl.WrapperProxettaBuilder in project jodd by oblac.

the class GenericsInDefaultTest method testClassesWithGenericsAsReturnValueWrapperDefault.

@Test
public void testClassesWithGenericsAsReturnValueWrapperDefault() {
    try {
        ProxyAspect aspect = new ProxyAspect(DelegateAdvice.class);
        WrapperProxetta proxetta = WrapperProxetta.withAspects(aspect);
        WrapperProxettaBuilder builder = proxetta.builder(Foo.class, IFoo.class);
        builder.newInstance();
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.toString());
    }
}
Also used : WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) WrapperProxetta(jodd.proxetta.impl.WrapperProxetta) ProxyAspect(jodd.proxetta.ProxyAspect) Test(org.junit.Test)

Example 8 with WrapperProxettaBuilder

use of jodd.proxetta.impl.WrapperProxettaBuilder in project jodd by oblac.

the class AnnTest method testClassAnnotationsWrapper.

@Test
public void testClassAnnotationsWrapper() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    WrapperProxetta proxetta = WrapperProxetta.withAspects(new ProxyAspect(HeroProxyAdvice2.class, new AllRealMethodsPointcut() {

        @Override
        public boolean apply(MethodInfo methodInfo) {
            if (!methodInfo.isTopLevelMethod()) {
                return false;
            }
            return super.apply(methodInfo);
        }
    }));
    WrapperProxettaBuilder proxettaBuilder = proxetta.builder();
    proxettaBuilder.setTarget(Hero.class);
    proxetta.setVariableClassName(true);
    Object hero = proxettaBuilder.newInstance();
    assertEquals("SilverHero89W99.222None1000speeeeedXRAYnull", ReflectUtil.invoke(hero, "name"));
}
Also used : WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) WrapperProxetta(jodd.proxetta.impl.WrapperProxetta) AllRealMethodsPointcut(jodd.proxetta.pointcuts.AllRealMethodsPointcut) HeroProxyAdvice2(jodd.proxetta.data.HeroProxyAdvice2) Test(org.junit.Test)

Example 9 with WrapperProxettaBuilder

use of jodd.proxetta.impl.WrapperProxettaBuilder in project jodd by oblac.

the class AnnTest method testMethodAnnotationsWrapper.

@Test
public void testMethodAnnotationsWrapper() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    WrapperProxetta proxetta = WrapperProxetta.withAspects(new ProxyAspect(HeroProxyAdvice.class, new AllRealMethodsPointcut() {

        @Override
        public boolean apply(MethodInfo methodInfo) {
            if (!methodInfo.isTopLevelMethod()) {
                return false;
            }
            return super.apply(methodInfo);
        }
    }));
    WrapperProxettaBuilder proxettaBuilder = proxetta.builder();
    proxettaBuilder.setTarget(Hero.class);
    proxetta.setVariableClassName(true);
    Object hero = proxettaBuilder.newInstance();
    assertEquals("BatmanHero37W88.3CatWoman99speeeeedXRAYnull", ReflectUtil.invoke(hero, "name"));
}
Also used : WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) WrapperProxetta(jodd.proxetta.impl.WrapperProxetta) AllRealMethodsPointcut(jodd.proxetta.pointcuts.AllRealMethodsPointcut) HeroProxyAdvice(jodd.proxetta.data.HeroProxyAdvice) Test(org.junit.Test)

Aggregations

WrapperProxetta (jodd.proxetta.impl.WrapperProxetta)9 WrapperProxettaBuilder (jodd.proxetta.impl.WrapperProxettaBuilder)9 Test (org.junit.Test)9 ProxyPointcutSupport (jodd.proxetta.pointcuts.ProxyPointcutSupport)5 AllRealMethodsPointcut (jodd.proxetta.pointcuts.AllRealMethodsPointcut)2 Method (java.lang.reflect.Method)1 ProxyAspect (jodd.proxetta.ProxyAspect)1 HeroProxyAdvice (jodd.proxetta.data.HeroProxyAdvice)1 HeroProxyAdvice2 (jodd.proxetta.data.HeroProxyAdvice2)1