Search in sources :

Example 16 with CountingBeforeAdvice

use of org.springframework.aop.testfixture.advice.CountingBeforeAdvice in project spring-framework by spring-projects.

the class ProxyFactoryBeanTests method testGetObjectTypeWithDirectTarget.

@Test
public void testGetObjectTypeWithDirectTarget() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS));
    // We have a counting before advice here
    CountingBeforeAdvice cba = (CountingBeforeAdvice) bf.getBean("countingBeforeAdvice");
    assertThat(cba.getCalls()).isEqualTo(0);
    ITestBean tb = (ITestBean) bf.getBean("directTarget");
    assertThat(tb.getName().equals("Adam")).isTrue();
    assertThat(cba.getCalls()).isEqualTo(1);
    ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&directTarget");
    assertThat(TestBean.class.isAssignableFrom(pfb.getObjectType())).as("Has correct object type").isTrue();
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) CountingBeforeAdvice(org.springframework.aop.testfixture.advice.CountingBeforeAdvice) Test(org.junit.jupiter.api.Test)

Example 17 with CountingBeforeAdvice

use of org.springframework.aop.testfixture.advice.CountingBeforeAdvice in project spring-framework by spring-projects.

the class SelectivePrototypeTargetSourceCreator method testWithOptimizedProxy.

@Test
public void testWithOptimizedProxy() throws Exception {
    BeanFactory beanFactory = new ClassPathXmlApplicationContext(OPTIMIZED_CONTEXT, CLASS);
    ITestBean testBean = (ITestBean) beanFactory.getBean("optimizedTestBean");
    assertThat(AopUtils.isAopProxy(testBean)).isTrue();
    CountingBeforeAdvice beforeAdvice = (CountingBeforeAdvice) beanFactory.getBean("countingAdvice");
    testBean.setAge(23);
    testBean.getAge();
    assertThat(beforeAdvice.getCalls()).as("Incorrect number of calls to proxy").isEqualTo(2);
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeanFactory(org.springframework.beans.factory.BeanFactory) CountingBeforeAdvice(org.springframework.aop.testfixture.advice.CountingBeforeAdvice) Test(org.junit.jupiter.api.Test)

Aggregations

CountingBeforeAdvice (org.springframework.aop.testfixture.advice.CountingBeforeAdvice)17 Test (org.junit.jupiter.api.Test)16 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)13 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)11 TestBean (org.springframework.beans.testfixture.beans.TestBean)11 Advisor (org.springframework.aop.Advisor)7 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)7 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)7 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)6 StaticMethodMatcherPointcutAdvisor (org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor)3 LockMixinAdvisor (test.mixin.LockMixinAdvisor)3 Method (java.lang.reflect.Method)2 NameMatchMethodPointcut (org.springframework.aop.support.NameMatchMethodPointcut)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Assertions.assertThatIOException (org.assertj.core.api.Assertions.assertThatIOException)1 MethodBeforeAdvice (org.springframework.aop.MethodBeforeAdvice)1