Search in sources :

Example 1 with AllRealMethodsPointcut

use of jodd.proxetta.pointcuts.AllRealMethodsPointcut in project jodd by oblac.

the class AnnTest method testMethodAnnotationsProxy.

@Test
public void testMethodAnnotationsProxy() {
    ProxyProxetta proxetta = ProxyProxetta.withAspects(new ProxyAspect(HeroProxyAdvice.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("BatmanHero37W88.3CatWoman99speeeeedXRAYnull", hero.name());
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) WrapperProxettaBuilder(jodd.proxetta.impl.WrapperProxettaBuilder) Hero(jodd.proxetta.data.Hero) AllRealMethodsPointcut(jodd.proxetta.pointcuts.AllRealMethodsPointcut) HeroProxyAdvice(jodd.proxetta.data.HeroProxyAdvice) Test(org.junit.Test)

Example 2 with AllRealMethodsPointcut

use of jodd.proxetta.pointcuts.AllRealMethodsPointcut 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 3 with AllRealMethodsPointcut

use of jodd.proxetta.pointcuts.AllRealMethodsPointcut 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 4 with AllRealMethodsPointcut

use of jodd.proxetta.pointcuts.AllRealMethodsPointcut 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)

Example 5 with AllRealMethodsPointcut

use of jodd.proxetta.pointcuts.AllRealMethodsPointcut 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

AllRealMethodsPointcut (jodd.proxetta.pointcuts.AllRealMethodsPointcut)5 Test (org.junit.Test)5 WrapperProxettaBuilder (jodd.proxetta.impl.WrapperProxettaBuilder)4 ProxyProxetta (jodd.proxetta.impl.ProxyProxetta)3 Hero (jodd.proxetta.data.Hero)2 HeroProxyAdvice (jodd.proxetta.data.HeroProxyAdvice)2 HeroProxyAdvice2 (jodd.proxetta.data.HeroProxyAdvice2)2 WrapperProxetta (jodd.proxetta.impl.WrapperProxetta)2 ProxettaAwarePetiteContainer (jodd.petite.proxetta.ProxettaAwarePetiteContainer)1 ProxyAspect (jodd.proxetta.ProxyAspect)1