Search in sources :

Example 6 with AspectJProxyFactory

use of org.springframework.aop.aspectj.annotation.AspectJProxyFactory in project java-chassis by ServiceComb.

the class TestBeanUtils method test.

@Test
public void test() {
    Intf target = new Impl();
    AspectJProxyFactory factory = new AspectJProxyFactory(target);
    MyAspect aspect = new MyAspect();
    factory.addAspect(aspect);
    Intf proxy = factory.getProxy();
    Assert.assertEquals(Impl.class, BeanUtils.getImplClassFromBean(proxy));
    Assert.assertEquals(Impl.class, BeanUtils.getImplClassFromBean(new Impl()));
}
Also used : AspectJProxyFactory(org.springframework.aop.aspectj.annotation.AspectJProxyFactory) Test(org.junit.Test)

Example 7 with AspectJProxyFactory

use of org.springframework.aop.aspectj.annotation.AspectJProxyFactory in project spring-framework by spring-projects.

the class CounterAspect method testProgrammaticProxyCreation.

@Test
public void testProgrammaticProxyCreation() {
    ITestBean testBean = new TestBean();
    AspectJProxyFactory factory = new AspectJProxyFactory();
    factory.setTarget(testBean);
    CounterAspect myCounterAspect = new CounterAspect();
    factory.addAspect(myCounterAspect);
    ITestBean proxyTestBean = factory.getProxy();
    boolean condition = proxyTestBean instanceof Advised;
    assertThat(condition).as("Expected a proxy").isTrue();
    proxyTestBean.setAge(20);
    assertThat(myCounterAspect.count).as("Programmatically created proxy shouldn't match bean()").isEqualTo(0);
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) AspectJProxyFactory(org.springframework.aop.aspectj.annotation.AspectJProxyFactory) Advised(org.springframework.aop.framework.Advised) Test(org.junit.jupiter.api.Test)

Example 8 with AspectJProxyFactory

use of org.springframework.aop.aspectj.annotation.AspectJProxyFactory in project uPortal by Jasig.

the class AspectApplyingAspect method applyAspect.

public Object applyAspect(ProceedingJoinPoint pjp) throws Throwable {
    final Object result = pjp.proceed();
    if (result == null) {
        return result;
    }
    final AspectJProxyFactory portletPreferencesProxyFactory = new AspectJProxyFactory(result);
    for (final Advice advice : this.advices) {
        portletPreferencesProxyFactory.addAdvice(advice);
    }
    return portletPreferencesProxyFactory.getProxy();
}
Also used : AspectJProxyFactory(org.springframework.aop.aspectj.annotation.AspectJProxyFactory) Advice(org.aopalliance.aop.Advice)

Example 9 with AspectJProxyFactory

use of org.springframework.aop.aspectj.annotation.AspectJProxyFactory in project uPortal by Jasig.

the class AspectJExpressionTest method testProgramaticPointcut.

@Test
public void testProgramaticPointcut() {
    final RepositoryPointcutInterface targetPointcutInterface = new RepositoryPointcutInterfaceImpl();
    final AspectJProxyFactory portletPreferencesProxyFactory = new AspectJProxyFactory(targetPointcutInterface);
    final Method interceptorMethod = ReflectionUtils.findMethod(CountingMethodInterceptor.class, "countInvocation", ProceedingJoinPoint.class);
    final AspectJAroundAdvice aspectJAroundAdvice = new AspectJAroundAdvice(interceptorMethod, repositoryPointcutInterfaceExecutionPointcut, new SingletonAspectInstanceFactory(this.countingMethodInterceptor));
    portletPreferencesProxyFactory.addAdvice(aspectJAroundAdvice);
    final RepositoryPointcutInterface proxiedPointcutInterface = (RepositoryPointcutInterface) portletPreferencesProxyFactory.getProxy();
    assertEquals(0, countingMethodInterceptor.getCount());
    proxiedPointcutInterface.methodOne("test");
    assertEquals(1, countingMethodInterceptor.getCount());
    proxiedPointcutInterface.methodOne("test");
    assertEquals(2, countingMethodInterceptor.getCount());
}
Also used : AspectJAroundAdvice(org.springframework.aop.aspectj.AspectJAroundAdvice) AspectJProxyFactory(org.springframework.aop.aspectj.annotation.AspectJProxyFactory) SingletonAspectInstanceFactory(org.springframework.aop.aspectj.SingletonAspectInstanceFactory) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 10 with AspectJProxyFactory

use of org.springframework.aop.aspectj.annotation.AspectJProxyFactory in project uPortal by Jasig.

the class AspectJExpressionTest method testProgramaticPointcut2.

@Test
public void testProgramaticPointcut2() {
    final RepositoryPointcutInterface targetPointcutInterface = new RepositoryPointcutInterfaceImpl();
    final AspectJProxyFactory portletPreferencesProxyFactory = new AspectJProxyFactory(targetPointcutInterface);
    portletPreferencesProxyFactory.addAdvice(countingMethodInterceptorRepositoryAdvice);
    final RepositoryPointcutInterface proxiedPointcutInterface = (RepositoryPointcutInterface) portletPreferencesProxyFactory.getProxy();
    assertEquals(0, countingMethodInterceptor.getCount());
    proxiedPointcutInterface.methodOne("test");
    assertEquals(1, countingMethodInterceptor.getCount());
    proxiedPointcutInterface.methodOne("test");
    assertEquals(2, countingMethodInterceptor.getCount());
}
Also used : AspectJProxyFactory(org.springframework.aop.aspectj.annotation.AspectJProxyFactory) Test(org.junit.Test)

Aggregations

AspectJProxyFactory (org.springframework.aop.aspectj.annotation.AspectJProxyFactory)12 Test (org.junit.Test)5 Before (org.junit.Before)3 Test (org.junit.jupiter.api.Test)2 User (ca.corefacility.bioinformatics.irida.model.user.User)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 Method (java.lang.reflect.Method)1 Advice (org.aopalliance.aop.Advice)1 AspectJAroundAdvice (org.springframework.aop.aspectj.AspectJAroundAdvice)1 SingletonAspectInstanceFactory (org.springframework.aop.aspectj.SingletonAspectInstanceFactory)1 Advised (org.springframework.aop.framework.Advised)1 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)1 TestBean (org.springframework.beans.testfixture.beans.TestBean)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)1