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());
}
}
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"));
}
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);
}
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) {
}
}
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);
}
Aggregations