Search in sources :

Example 1 with AspectJExpressionPointcut

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

the class AspectJPrecedenceComparatorTests method setUp.

@Before
public void setUp() throws Exception {
    this.comparator = new AspectJPrecedenceComparator();
    this.anyOldMethod = getClass().getMethods()[0];
    this.anyOldPointcut = new AspectJExpressionPointcut();
    this.anyOldPointcut.setExpression("execution(* *(..))");
}
Also used : AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) Before(org.junit.Before)

Example 2 with AspectJExpressionPointcut

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

the class AspectJPointcutAdvisorTests method testSingleton.

@Test
public void testSingleton() throws SecurityException, NoSuchMethodException {
    AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
    ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
    InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(ajexp, TestBean.class.getMethod("getAge"), af, new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null), "someBean"), 1, "someBean");
    assertSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
    assertFalse(ajpa.isPerInstance());
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) Test(org.junit.Test)

Example 3 with AspectJExpressionPointcut

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

the class AspectJPointcutAdvisorTests method testPerTarget.

@Test
public void testPerTarget() throws SecurityException, NoSuchMethodException {
    AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
    ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
    InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(ajexp, TestBean.class.getMethod("getAge"), af, new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean"), 1, "someBean");
    assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
    assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
    assertTrue(ajpa.isPerInstance());
    assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class));
    assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), TestBean.class));
    assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), TestBean.class));
}
Also used : PerTargetAspect(test.aop.PerTargetAspect) TestBean(org.springframework.tests.sample.beans.TestBean) AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) Test(org.junit.Test)

Example 4 with AspectJExpressionPointcut

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

the class ReflectiveAspectJAdvisorFactory method getAdvisor.

@Override
public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrderInAspect, String aspectName) {
    validate(aspectInstanceFactory.getAspectMetadata().getAspectClass());
    AspectJExpressionPointcut expressionPointcut = getPointcut(candidateAdviceMethod, aspectInstanceFactory.getAspectMetadata().getAspectClass());
    if (expressionPointcut == null) {
        return null;
    }
    return new InstantiationModelAwarePointcutAdvisorImpl(expressionPointcut, candidateAdviceMethod, this, aspectInstanceFactory, declarationOrderInAspect, aspectName);
}
Also used : AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut)

Example 5 with AspectJExpressionPointcut

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

the class GroovyAspectTests method manualGroovyBeanWithStaticPointcut.

@Test
public void manualGroovyBeanWithStaticPointcut() throws Exception {
    TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(new ClassPathResource("GroovyServiceImpl.grv", getClass())));
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("execution(* %s.TestService+.*(..))", ClassUtils.getPackageName(getClass())));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

AspectJExpressionPointcut (org.springframework.aop.aspectj.AspectJExpressionPointcut)8 Test (org.junit.Test)5 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ResourceScriptSource (org.springframework.scripting.support.ResourceScriptSource)3 TestBean (org.springframework.tests.sample.beans.TestBean)2 Before (org.junit.Before)1 PerTargetAspect (test.aop.PerTargetAspect)1