Search in sources :

Example 1 with TwoAdviceAspect

use of test.aop.TwoAdviceAspect in project spring-framework by spring-projects.

the class PerThisAspect method twoAdvicesOnOneAspect.

@Test
void twoAdvicesOnOneAspect() {
    TestBean target = new TestBean();
    TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect();
    List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect, "someBean"));
    assertThat(advisors.size()).as("Two advice methods found").isEqualTo(2);
    ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
    itb.setName("");
    assertThat(itb.getAge()).isEqualTo(0);
    int newAge = 32;
    itb.setAge(newAge);
    assertThat(itb.getAge()).isEqualTo(1);
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) Advisor(org.springframework.aop.Advisor) TwoAdviceAspect(test.aop.TwoAdviceAspect) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.jupiter.api.Test)

Example 2 with TwoAdviceAspect

use of test.aop.TwoAdviceAspect in project spring-framework by spring-projects.

the class PerThisAspect method testTwoAdvicesOnOneAspect.

@Test
public void testTwoAdvicesOnOneAspect() {
    TestBean target = new TestBean();
    TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect();
    List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect, "someBean"));
    assertEquals("Two advice methods found", 2, advisors.size());
    ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
    itb.setName("");
    assertEquals(0, itb.getAge());
    int newAge = 32;
    itb.setAge(newAge);
    assertEquals(1, itb.getAge());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) SyntheticInstantiationAdvisor(org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) Advisor(org.springframework.aop.Advisor) TwoAdviceAspect(test.aop.TwoAdviceAspect) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.Test)

Aggregations

JoinPoint (org.aspectj.lang.JoinPoint)2 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)2 Advisor (org.springframework.aop.Advisor)2 TwoAdviceAspect (test.aop.TwoAdviceAspect)2 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 SyntheticInstantiationAdvisor (org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor)1 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)1 TestBean (org.springframework.beans.testfixture.beans.TestBean)1 ITestBean (org.springframework.tests.sample.beans.ITestBean)1 TestBean (org.springframework.tests.sample.beans.TestBean)1