Search in sources :

Example 1 with AspectJExpressionPointcut

use of cn.taketoday.aop.aspectj.AspectJExpressionPointcut in project today-infrastructure by TAKETODAY.

the class AspectJPrecedenceComparatorTests method setUp.

@BeforeEach
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(cn.taketoday.aop.aspectj.AspectJExpressionPointcut) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with AspectJExpressionPointcut

use of cn.taketoday.aop.aspectj.AspectJExpressionPointcut in project today-framework by TAKETODAY.

the class AspectJPrecedenceComparatorTests method setUp.

@BeforeEach
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(cn.taketoday.aop.aspectj.AspectJExpressionPointcut) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with AspectJExpressionPointcut

use of cn.taketoday.aop.aspectj.AspectJExpressionPointcut in project today-framework by TAKETODAY.

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 ExceptionThrowingAspect(null), "someBean"), 1, "someBean");
    assertThat(ajpa.getAspectMetadata().getPerClausePointcut()).isSameAs(Pointcut.TRUE);
    assertThat(ajpa.isPerInstance()).isFalse();
}
Also used : TestBean(cn.taketoday.beans.testfixture.beans.TestBean) AspectJExpressionPointcut(cn.taketoday.aop.aspectj.AspectJExpressionPointcut) ExceptionThrowingAspect(cn.taketoday.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactoryTests.ExceptionThrowingAspect) Test(org.junit.jupiter.api.Test)

Example 4 with AspectJExpressionPointcut

use of cn.taketoday.aop.aspectj.AspectJExpressionPointcut in project today-framework by TAKETODAY.

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");
    assertThat(ajpa.getAspectMetadata().getPerClausePointcut()).isNotSameAs(Pointcut.TRUE);
    boolean condition = ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut;
    assertThat(condition).isTrue();
    assertThat(ajpa.isPerInstance()).isTrue();
    assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class)).isTrue();
    assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), TestBean.class)).isFalse();
    assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), TestBean.class)).isTrue();
}
Also used : PerTargetAspect(test.aop.PerTargetAspect) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) AspectJExpressionPointcut(cn.taketoday.aop.aspectj.AspectJExpressionPointcut) Test(org.junit.jupiter.api.Test)

Example 5 with AspectJExpressionPointcut

use of cn.taketoday.aop.aspectj.AspectJExpressionPointcut in project today-infrastructure by TAKETODAY.

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");
    assertThat(ajpa.getAspectMetadata().getPerClausePointcut()).isNotSameAs(Pointcut.TRUE);
    boolean condition = ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut;
    assertThat(condition).isTrue();
    assertThat(ajpa.isPerInstance()).isTrue();
    assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class)).isTrue();
    assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), TestBean.class)).isFalse();
    assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), TestBean.class)).isTrue();
}
Also used : PerTargetAspect(test.aop.PerTargetAspect) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) AspectJExpressionPointcut(cn.taketoday.aop.aspectj.AspectJExpressionPointcut) Test(org.junit.jupiter.api.Test)

Aggregations

AspectJExpressionPointcut (cn.taketoday.aop.aspectj.AspectJExpressionPointcut)6 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)4 Test (org.junit.jupiter.api.Test)4 ExceptionThrowingAspect (cn.taketoday.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactoryTests.ExceptionThrowingAspect)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 PerTargetAspect (test.aop.PerTargetAspect)2