Search in sources :

Example 1 with WrapperProxetta

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

the class GenericsTest method testClassesWithGenericsAsReturnValueWrapper.

@Test
public void testClassesWithGenericsAsReturnValueWrapper() {
    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) {
        fail(ex.toString());
    }
}
Also used : WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) WrapperProxetta(jodd.proxetta.impl.WrapperProxetta) Test(org.junit.Test)

Example 2 with WrapperProxetta

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

the class WrapperTest method testClassWrapperCastToInterface.

@Test
public void testClassWrapperCastToInterface() 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 casted to interface,
    // resulting object has ONE interface
    // ALL target methods are wrapped
    WrapperProxettaBuilder builder = proxetta.builder(calc.getClass(), Calc.class, ".CalcImpl2");
    Class<Calc> calc2Class = builder.define();
    Calc calc2 = calc2Class.newInstance();
    builder.injectTargetIntoWrapper(calc, calc2);
    // counter in static block !!!
    assertEquals(1, StatCounter.counter);
    calc2.hello();
    assertEquals(2, StatCounter.counter);
    assertEquals(10, calc2.calculate(3, 7));
    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) Test(org.junit.Test)

Example 3 with WrapperProxetta

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

the class WrapperTest method testNoPointcutMatched.

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

        public boolean apply(MethodInfo methodInfo) {
            return false;
        }
    }));
    //		proxetta.setDebugFolder("d:\\");
    WrapperProxettaBuilder builder = proxetta.builder(CalcSuper.class, ".CalcSuper22");
    Class<CalcSuper> calc2Class = builder.define();
    CalcSuper calc2 = calc2Class.newInstance();
    builder.injectTargetIntoWrapper(calc, calc2);
    // counter in static block !!!
    assertEquals(1, StatCounter.counter);
    calc2.hello();
    assertEquals(1, StatCounter.counter);
    assertEquals(10, calc2.calculate(3, 7));
    // counter not called in calculate!
    assertEquals(1, StatCounter.counter);
    calc2.ola();
    assertEquals(1, StatCounter.counter);
    calc2.superhi();
    calc2.maybe(4, 5);
    calc2.calculate(4, 5);
    assertEquals(1, StatCounter.counter);
}
Also used : WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) WrapperProxetta(jodd.proxetta.impl.WrapperProxetta) ProxyPointcutSupport(jodd.proxetta.pointcuts.ProxyPointcutSupport) Test(org.junit.Test)

Example 4 with WrapperProxetta

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

the class WrapperTest method testInterfaceWrapper.

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

        public boolean apply(MethodInfo methodInfo) {
            return isTopLevelMethod(methodInfo) && isPublic(methodInfo);
        }
    }));
    //proxetta.setDebugFolder("/Users/igor");
    // wrapper over INTERFACE
    // resulting object has ONE interface
    // only interface methods are wrapped
    WrapperProxettaBuilder builder = proxetta.builder(Calc.class, ".CalcImpl3");
    Class<Calc> calc2Class = builder.define();
    Calc calc2 = calc2Class.newInstance();
    builder.injectTargetIntoWrapper(calc, calc2);
    // counter in static block !!!
    assertEquals(1, StatCounter.counter);
    calc2.hello();
    assertEquals(2, StatCounter.counter);
    assertEquals(10, calc2.calculate(3, 7));
    assertEquals(3, StatCounter.counter);
    try {
        calc2Class.getMethod("customMethod");
        fail();
    } catch (Exception ex) {
    }
}
Also used : WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) WrapperProxetta(jodd.proxetta.impl.WrapperProxetta) ProxyPointcutSupport(jodd.proxetta.pointcuts.ProxyPointcutSupport) Test(org.junit.Test)

Example 5 with WrapperProxetta

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

the class WrapperTest method testPartialMethodsWrapped.

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

        public boolean apply(MethodInfo methodInfo) {
            return isPublic(methodInfo) && (methodInfo.getMethodName().equals("hello") || methodInfo.getMethodName().equals("ola"));
        }
    }));
    //		proxetta.setDebugFolder("d:\\");
    WrapperProxettaBuilder builder = proxetta.builder(CalcSuper.class);
    Class<CalcSuper> calc2Class = builder.define();
    CalcSuper calc2 = calc2Class.newInstance();
    builder.injectTargetIntoWrapper(calc, calc2);
    // counter in static block !!!
    assertEquals(1, StatCounter.counter);
    calc2.hello();
    assertEquals(2, StatCounter.counter);
    assertEquals(10, calc2.calculate(3, 7));
    // counter not called in calculate!
    assertEquals(2, StatCounter.counter);
    calc2.ola();
    assertEquals(3, StatCounter.counter);
    calc2.superhi();
    calc2.maybe(4, 5);
    calc2.calculate(4, 5);
    assertEquals(3, StatCounter.counter);
}
Also used : WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) WrapperProxetta(jodd.proxetta.impl.WrapperProxetta) ProxyPointcutSupport(jodd.proxetta.pointcuts.ProxyPointcutSupport) 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