use of jodd.proxetta.impl.ProxyProxetta in project jodd by oblac.
the class MethrefTest method testMethRefOnProxifiedClass.
@Test
public void testMethRefOnProxifiedClass() {
Methref<? extends Oink> m = Methref.on(Oink.class);
m.to().woink();
assertEquals("woink", m.ref());
ProxyAspect a1 = new ProxyAspect(DummyAdvice.class, new AllTopMethodsPointcut());
ProxyProxetta pp = ProxyProxetta.withAspects(a1);
Oink oink = (Oink) pp.builder(Oink.class).newInstance();
assertFalse(oink.getClass().equals(Oink.class));
m = Methref.on(oink.getClass());
m.to().woink();
assertEquals("woink", m.ref());
}
use of jodd.proxetta.impl.ProxyProxetta 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));
}
use of jodd.proxetta.impl.ProxyProxetta in project jodd by oblac.
the class AnnTest method testClassAnnotationsProxy.
@Test
public void testClassAnnotationsProxy() {
ProxyProxetta proxetta = ProxyProxetta.withAspects(new ProxyAspect(HeroProxyAdvice2.class, new AllRealMethodsPointcut() {
@Override
public boolean apply(MethodInfo methodInfo) {
if (!methodInfo.isTopLevelMethod()) {
return false;
}
return super.apply(methodInfo);
}
}));
ProxettaBuilder proxettaBuilder = proxetta.builder();
proxettaBuilder.setTarget(Hero.class);
proxetta.setVariableClassName(true);
Hero hero = (Hero) proxettaBuilder.newInstance();
assertEquals("SilverHero89W99.222None1000speeeeedXRAYnull", hero.name());
}
use of jodd.proxetta.impl.ProxyProxetta in project jodd by oblac.
the class ProxettaAwareContainerTest method testProxyProxetta.
@Test
public void testProxyProxetta() {
ProxyProxetta proxetta = ProxyProxetta.withAspects(new ProxyAspect(AddStringAdvice.class, new AllRealMethodsPointcut()));
PetiteContainer papc = new ProxettaAwarePetiteContainer(proxetta);
papc.registerPetiteBean(SecretService.class, null, null, null, false);
BeanDefinition beanDefinition = papc.registerPetiteBean(PublicService.class, null, null, null, false);
papc.registerPetiteBean(PublicService2.class, null, null, null, false);
papc.registerPetiteBean(PublicService3.class, null, null, null, false);
assertNotEquals(PublicService.class, beanDefinition.getType());
PublicService publicService = (PublicService) papc.getBean(beanDefinition.getName());
assertNotNull(publicService.secretService);
assertEquals("Hello World! And Universe, too!", publicService.hello());
PublicService2 publicService2 = papc.getBean(PublicService2.class);
assertNotNull(publicService2.secretService);
assertEquals("Hello World! And Universe, too!", publicService2.hello());
PublicService3 publicService3 = papc.getBean(PublicService3.class);
assertNotNull(publicService3.secretService);
assertEquals("Hello World! And Universe, too!", publicService3.hello());
}
Aggregations