Polishing
This commit is contained in:
parent
14e249aee3
commit
a07dc80d72
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.aop.framework.autoproxy;
|
package org.springframework.aop.framework.autoproxy;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import test.mixin.Lockable;
|
import test.mixin.Lockable;
|
||||||
import test.mixin.LockedException;
|
import test.mixin.LockedException;
|
||||||
|
|
@ -40,42 +39,36 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class BeanNameAutoProxyCreatorTests {
|
class BeanNameAutoProxyCreatorTests {
|
||||||
|
|
||||||
private BeanFactory beanFactory;
|
// Note that we need an ApplicationContext, not just a BeanFactory,
|
||||||
|
// for post-processing and hence auto-proxying to work.
|
||||||
|
private final BeanFactory beanFactory = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||||
@BeforeEach
|
|
||||||
public void setup() {
|
|
||||||
// Note that we need an ApplicationContext, not just a BeanFactory,
|
|
||||||
// for post-processing and hence auto-proxying to work.
|
|
||||||
beanFactory = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoProxy() {
|
void noProxy() {
|
||||||
TestBean tb = (TestBean) beanFactory.getBean("noproxy");
|
TestBean tb = (TestBean) beanFactory.getBean("noproxy");
|
||||||
assertThat(AopUtils.isAopProxy(tb)).isFalse();
|
assertThat(AopUtils.isAopProxy(tb)).isFalse();
|
||||||
assertThat(tb.getName()).isEqualTo("noproxy");
|
assertThat(tb.getName()).isEqualTo("noproxy");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJdkProxyWithExactNameMatch() {
|
void proxyWithExactNameMatch() {
|
||||||
ITestBean tb = (ITestBean) beanFactory.getBean("onlyJdk");
|
ITestBean tb = (ITestBean) beanFactory.getBean("onlyJdk");
|
||||||
jdkAssertions(tb, 1);
|
jdkAssertions(tb, 1);
|
||||||
assertThat(tb.getName()).isEqualTo("onlyJdk");
|
assertThat(tb.getName()).isEqualTo("onlyJdk");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJdkProxyWithDoubleProxying() {
|
void proxyWithDoubleProxying() {
|
||||||
ITestBean tb = (ITestBean) beanFactory.getBean("doubleJdk");
|
ITestBean tb = (ITestBean) beanFactory.getBean("doubleJdk");
|
||||||
jdkAssertions(tb, 2);
|
jdkAssertions(tb, 2);
|
||||||
assertThat(tb.getName()).isEqualTo("doubleJdk");
|
assertThat(tb.getName()).isEqualTo("doubleJdk");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJdkIntroduction() {
|
void jdkIntroduction() {
|
||||||
ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk");
|
ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk");
|
||||||
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
|
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
|
||||||
assertThat(nop.getCount()).isEqualTo(0);
|
assertThat(nop.getCount()).isEqualTo(0);
|
||||||
|
|
@ -110,7 +103,7 @@ public class BeanNameAutoProxyCreatorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
|
void jdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
|
||||||
ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk");
|
ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk");
|
||||||
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
|
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
|
||||||
assertThat(nop.getCount()).as("NOP should not have done any work yet").isEqualTo(0);
|
assertThat(nop.getCount()).as("NOP should not have done any work yet").isEqualTo(0);
|
||||||
|
|
@ -118,8 +111,7 @@ public class BeanNameAutoProxyCreatorTests {
|
||||||
int age = 5;
|
int age = 5;
|
||||||
tb.setAge(age);
|
tb.setAge(age);
|
||||||
assertThat(tb.getAge()).isEqualTo(age);
|
assertThat(tb.getAge()).isEqualTo(age);
|
||||||
boolean condition = tb instanceof TimeStamped;
|
assertThat(tb).as("Introduction was made").isInstanceOf(TimeStamped.class);
|
||||||
assertThat(condition).as("Introduction was made").isTrue();
|
|
||||||
assertThat(((TimeStamped) tb).getTimeStamp()).isEqualTo(0);
|
assertThat(((TimeStamped) tb).getTimeStamp()).isEqualTo(0);
|
||||||
assertThat(nop.getCount()).isEqualTo(3);
|
assertThat(nop.getCount()).isEqualTo(3);
|
||||||
|
|
||||||
|
|
@ -144,21 +136,21 @@ public class BeanNameAutoProxyCreatorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJdkProxyWithWildcardMatch() {
|
void proxyWithWildcardMatch() {
|
||||||
ITestBean tb = (ITestBean) beanFactory.getBean("jdk1");
|
ITestBean tb = (ITestBean) beanFactory.getBean("jdk1");
|
||||||
jdkAssertions(tb, 1);
|
jdkAssertions(tb, 1);
|
||||||
assertThat(tb.getName()).isEqualTo("jdk1");
|
assertThat(tb.getName()).isEqualTo("jdk1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCglibProxyWithWildcardMatch() {
|
void cglibProxyWithWildcardMatch() {
|
||||||
TestBean tb = (TestBean) beanFactory.getBean("cglib1");
|
TestBean tb = (TestBean) beanFactory.getBean("cglib1");
|
||||||
cglibAssertions(tb);
|
cglibAssertions(tb);
|
||||||
assertThat(tb.getName()).isEqualTo("cglib1");
|
assertThat(tb.getName()).isEqualTo("cglib1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithFrozenProxy() {
|
void withFrozenProxy() {
|
||||||
ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean");
|
ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean");
|
||||||
assertThat(((Advised)testBean).isFrozen()).isTrue();
|
assertThat(((Advised)testBean).isFrozen()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
@ -195,25 +187,16 @@ public class BeanNameAutoProxyCreatorTests {
|
||||||
|
|
||||||
class CreatesTestBean implements FactoryBean<Object> {
|
class CreatesTestBean implements FactoryBean<Object> {
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.springframework.beans.factory.FactoryBean#getObject()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Object getObject() throws Exception {
|
public Object getObject() throws Exception {
|
||||||
return new TestBean();
|
return new TestBean();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
return TestBean.class;
|
return TestBean.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSingleton() {
|
public boolean isSingleton() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -4,38 +4,28 @@
|
||||||
<beans>
|
<beans>
|
||||||
|
|
||||||
<bean id="frozenProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
|
<bean id="frozenProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
|
||||||
<property name="beanNames" value="frozenBean"/>
|
<property name="beanNames" value="frozenBean" />
|
||||||
<property name="frozen" value="true"/>
|
<property name="frozen" value="true" />
|
||||||
<property name="interceptorNames" value="nopInterceptor"/>
|
<property name="interceptorNames" value="nopInterceptor" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="_jdkBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
|
<bean id="_jdkBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
|
||||||
<description>
|
<description>Automatically proxies using JDK dynamic proxies</description>
|
||||||
Automatically proxies using JDK dynamic proxies
|
<property name="beanNames" value="jdk*,onlyJdk,doubleJdk" />
|
||||||
</description>
|
<property name="interceptorNames" value="nopInterceptor" />
|
||||||
<property name="beanNames"><value>jdk*,onlyJdk,doubleJdk</value></property>
|
|
||||||
<property name="interceptorNames">
|
|
||||||
<list>
|
|
||||||
<value>nopInterceptor</value>
|
|
||||||
</list>
|
|
||||||
</property>
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="doubleJdkBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
|
<bean id="doubleJdkBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
|
||||||
<property name="beanNames" value="doubleJdk"/>
|
<property name="beanNames" value="doubleJdk" />
|
||||||
<property name="interceptorNames" value="nopInterceptor"/>
|
<property name="interceptorNames" value="nopInterceptor" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="_cglibBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
|
<bean id="_cglibBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
|
||||||
<property name="beanNames">
|
<property name="beanNames" value="cglib*" />
|
||||||
<value>
|
<property name="proxyTargetClass">
|
||||||
cglib*
|
<description>Use the inherited ProxyConfig property to force CGLIB proxying</description>
|
||||||
</value>
|
<value>true</value>
|
||||||
</property>
|
</property>
|
||||||
<property name="proxyTargetClass">
|
|
||||||
<description>Use the inherited ProxyConfig property to force CGLIB proxying</description>
|
|
||||||
<value>true</value>
|
|
||||||
</property>
|
|
||||||
<property name="interceptorNames">
|
<property name="interceptorNames">
|
||||||
<description>Interceptors and Advisors to apply automatically</description>
|
<description>Interceptors and Advisors to apply automatically</description>
|
||||||
<list>
|
<list>
|
||||||
|
|
@ -49,14 +39,14 @@
|
||||||
<description>
|
<description>
|
||||||
Illustrates a JDK introduction
|
Illustrates a JDK introduction
|
||||||
</description>
|
</description>
|
||||||
<property name="beanNames"><value>*introductionUsingJdk</value></property>
|
<property name="beanNames" value="*introductionUsingJdk" />
|
||||||
<property name="interceptorNames">
|
<property name="interceptorNames">
|
||||||
<list>
|
<list>
|
||||||
<value>introductionNopInterceptor</value>
|
<value>introductionNopInterceptor</value>
|
||||||
<value>timestampIntroduction</value>
|
<value>timestampIntroduction</value>
|
||||||
<value>lockableAdvisor</value>
|
<value>lockableAdvisor</value>
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="timestampIntroduction" class="org.springframework.aop.testfixture.advice.TimestampIntroductionAdvisor"/>
|
<bean id="timestampIntroduction" class="org.springframework.aop.testfixture.advice.TimestampIntroductionAdvisor"/>
|
||||||
|
|
@ -74,11 +64,11 @@
|
||||||
<bean id="introductionNopInterceptor" class="org.springframework.aop.testfixture.interceptor.NopInterceptor"/>
|
<bean id="introductionNopInterceptor" class="org.springframework.aop.testfixture.interceptor.NopInterceptor"/>
|
||||||
|
|
||||||
<bean id="introductionUsingJdk" class="org.springframework.beans.testfixture.beans.TestBean">
|
<bean id="introductionUsingJdk" class="org.springframework.beans.testfixture.beans.TestBean">
|
||||||
<property name="name"><value>introductionUsingJdk</value></property>
|
<property name="name" value="introductionUsingJdk" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="second-introductionUsingJdk" class="org.springframework.beans.testfixture.beans.TestBean">
|
<bean id="second-introductionUsingJdk" class="org.springframework.beans.testfixture.beans.TestBean">
|
||||||
<property name="name"><value>second-introductionUsingJdk</value></property>
|
<property name="name" value="second-introductionUsingJdk" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
@ -89,7 +79,7 @@
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="jdk1" class="org.springframework.beans.testfixture.beans.TestBean">
|
<bean id="jdk1" class="org.springframework.beans.testfixture.beans.TestBean">
|
||||||
<property name="name"><value>jdk1</value></property>
|
<property name="name" value="jdk1" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="frozen" class="org.springframework.beans.testfixture.beans.TestBean">
|
<bean id="frozen" class="org.springframework.beans.testfixture.beans.TestBean">
|
||||||
|
|
@ -99,19 +89,19 @@
|
||||||
<alias name="frozen" alias="frozenBean"/>
|
<alias name="frozen" alias="frozenBean"/>
|
||||||
|
|
||||||
<bean id="cglib1" class="org.springframework.beans.testfixture.beans.TestBean">
|
<bean id="cglib1" class="org.springframework.beans.testfixture.beans.TestBean">
|
||||||
<property name="name"><value>cglib1</value></property>
|
<property name="name" value="cglib1" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="onlyJdk" class="org.springframework.beans.testfixture.beans.TestBean">
|
<bean id="onlyJdk" class="org.springframework.beans.testfixture.beans.TestBean">
|
||||||
<property name="name"><value>onlyJdk</value></property>
|
<property name="name" value="onlyJdk" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="doubleJdk" class="org.springframework.beans.testfixture.beans.TestBean">
|
<bean id="doubleJdk" class="org.springframework.beans.testfixture.beans.TestBean">
|
||||||
<property name="name"><value>doubleJdk</value></property>
|
<property name="name" value="doubleJdk" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="noproxy" class="org.springframework.beans.testfixture.beans.TestBean">
|
<bean id="noproxy" class="org.springframework.beans.testfixture.beans.TestBean">
|
||||||
<property name="name"><value>noproxy</value></property>
|
<property name="name" value="noproxy" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue