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