Search in sources :

Example 91 with ITestBean

use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.

the class TraceBeforeAdvice method testRepeatedAroundAdviceInvocations.

private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated around advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    assertThat(AopUtils.isAopProxy(adrian)).isTrue();
    assertThat(adrian.getAge()).isEqualTo(68);
    for (int i = 0; i < howmany; i++) {
        adrian.getAge();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) StopWatch(org.springframework.util.StopWatch)

Example 92 with ITestBean

use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.

the class TraceBeforeAdvice method testAfterReturningAdviceWithoutJoinPoint.

private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated after returning advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    assertThat(AopUtils.isAopProxy(adrian)).isTrue();
    Advised a = (Advised) adrian;
    assertThat(a.getAdvisors().length >= 3).isTrue();
    // Hits joinpoint
    adrian.setAge(25);
    for (int i = 0; i < howmany; i++) {
        adrian.setAge(i);
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) StopWatch(org.springframework.util.StopWatch)

Example 93 with ITestBean

use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.

the class TraceBeforeAdvice method testMix.

private long testMix(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated mixed invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    assertThat(AopUtils.isAopProxy(adrian)).isTrue();
    Advised a = (Advised) adrian;
    assertThat(a.getAdvisors().length >= 3).isTrue();
    for (int i = 0; i < howmany; i++) {
        // Hit all 3 joinpoints
        adrian.getAge();
        adrian.getName();
        adrian.setAge(i);
        // Invoke three non-advised methods
        adrian.getDoctor();
        adrian.getLawyer();
        adrian.getSpouse();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) StopWatch(org.springframework.util.StopWatch)

Example 94 with ITestBean

use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.

the class TraceBeforeAdvice method testBeforeAdviceWithoutJoinPoint.

private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
    ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
    StopWatch sw = new StopWatch();
    sw.start(howmany + " repeated before advice invocations with " + technology);
    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    assertThat(AopUtils.isAopProxy(adrian)).isTrue();
    Advised a = (Advised) adrian;
    assertThat(a.getAdvisors().length >= 3).isTrue();
    assertThat(adrian.getName()).isEqualTo("adrian");
    for (int i = 0; i < howmany; i++) {
        adrian.getName();
    }
    sw.stop();
    System.out.println(sw.prettyPrint());
    return sw.getLastTaskTimeMillis();
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) StopWatch(org.springframework.util.StopWatch)

Example 95 with ITestBean

use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.

the class AopNamespaceHandlerProxyTargetClassTests method testIsClassProxy.

@Test
public void testIsClassProxy() {
    ITestBean bean = getTestBean();
    assertThat(AopUtils.isCglibProxy(bean)).as("Should be a CGLIB proxy").isTrue();
    assertThat(((Advised) bean).isExposeProxy()).as("Should expose proxy").isTrue();
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) Test(org.junit.jupiter.api.Test)

Aggregations

ITestBean (org.springframework.beans.testfixture.beans.ITestBean)210 Test (org.junit.jupiter.api.Test)199 TestBean (org.springframework.beans.testfixture.beans.TestBean)121 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)44 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)31 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)29 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)23 Advisor (org.springframework.aop.Advisor)22 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)21 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)20 CountingBeforeAdvice (org.springframework.aop.testfixture.advice.CountingBeforeAdvice)19 Method (java.lang.reflect.Method)16 TimeStamped (org.springframework.core.testfixture.TimeStamped)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 TimestampIntroductionInterceptor (org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor)15 IOException (java.io.IOException)14 ProxyFactory (org.springframework.aop.framework.ProxyFactory)14 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)14 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)13 Advised (org.springframework.aop.framework.Advised)13