Search in sources :

Example 16 with ProxyProxetta

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());
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) AllTopMethodsPointcut(jodd.proxetta.pointcuts.AllTopMethodsPointcut) ProxyAspect(jodd.proxetta.ProxyAspect) Test(org.junit.Test)

Example 17 with ProxyProxetta

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));
}
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)

Example 18 with ProxyProxetta

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());
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) Hero(jodd.proxetta.data.Hero) AllRealMethodsPointcut(jodd.proxetta.pointcuts.AllRealMethodsPointcut) HeroProxyAdvice2(jodd.proxetta.data.HeroProxyAdvice2) Test(org.junit.Test)

Example 19 with ProxyProxetta

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());
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) ProxettaAwarePetiteContainer(jodd.petite.proxetta.ProxettaAwarePetiteContainer) AllRealMethodsPointcut(jodd.proxetta.pointcuts.AllRealMethodsPointcut) ProxyAspect(jodd.proxetta.ProxyAspect) ProxettaAwarePetiteContainer(jodd.petite.proxetta.ProxettaAwarePetiteContainer) Test(org.junit.Test)

Aggregations

ProxyProxetta (jodd.proxetta.impl.ProxyProxetta)19 Test (org.junit.Test)15 ProxyProxettaBuilder (jodd.proxetta.impl.ProxyProxettaBuilder)10 AllMethodsPointcut (jodd.proxetta.pointcuts.AllMethodsPointcut)5 ProxyAspect (jodd.proxetta.ProxyAspect)4 Field (java.lang.reflect.Field)3 AllRealMethodsPointcut (jodd.proxetta.pointcuts.AllRealMethodsPointcut)3 List (java.util.List)2 PetiteConfig (jodd.petite.PetiteConfig)2 ProxettaAwarePetiteContainer (jodd.petite.proxetta.ProxettaAwarePetiteContainer)2 Foo (jodd.proxetta.data.Foo)2 Hero (jodd.proxetta.data.Hero)2 Retro (jodd.proxetta.data.Retro)2 WrapperProxettaBuilder (jodd.proxetta.impl.WrapperProxettaBuilder)2 AllTopMethodsPointcut (jodd.proxetta.pointcuts.AllTopMethodsPointcut)2 Before (org.junit.Before)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1