Browse Source

Add missing test cases in XmlBeanFactoryTests

Closes gh-24189
pull/24212/head
lixiaolong11000 5 years ago committed by Sam Brannen
parent
commit
bee2b7cd73
  1. 40
      spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
  2. 22
      spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-reftypes.xml

40
spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java

@ -536,6 +536,46 @@ public class XmlBeanFactoryTests { @@ -536,6 +536,46 @@ public class XmlBeanFactoryTests {
assertThat(complexEgo.getSpouse().getSpouse() == complexEgo).as("Correct circular reference").isTrue();
}
@Test
public void testCircularReferencesWithConstructor() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("jenny_constructor"))
.matches(ex -> ex.contains(BeanCurrentlyInCreationException.class));
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("david_constructor"))
.matches(ex -> ex.contains(BeanCurrentlyInCreationException.class));
}
@Test
public void testCircularReferencesWithPrototype() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("jenny_prototype"))
.matches(ex -> ex.contains(BeanCurrentlyInCreationException.class));
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("david_prototype"))
.matches(ex -> ex.contains(BeanCurrentlyInCreationException.class));
}
@Test
public void testCircularReferencesWithDependOn() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
reader.loadBeanDefinitions(REFTYPES_CONTEXT);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("jenny_depends_on"));
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
xbf.getBean("david_depends_on"));
}
@Test
public void testCircularReferenceWithFactoryBeanFirst() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();

22
spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-reftypes.xml

@ -14,6 +14,28 @@ @@ -14,6 +14,28 @@
<property name="spouse" ref="jenny"/>
</bean>
<bean id="jenny_constructor" class="org.springframework.tests.sample.beans.TestBean">
<constructor-arg index="1"><ref bean="david_constructor"/></constructor-arg>
</bean>
<bean id="david_constructor" class="org.springframework.tests.sample.beans.TestBean">
<constructor-arg index="1"><ref bean="jenny_constructor"/></constructor-arg>
</bean>
<bean id="jenny_prototype" class="org.springframework.tests.sample.beans.TestBean" scope="prototype">
<property name="spouse"><ref bean="david_prototype"/></property>
</bean>
<bean id="david_prototype" class="org.springframework.tests.sample.beans.TestBean" scope="prototype">
<property name="spouse"><ref bean="jenny_prototype"/></property>
</bean>
<bean id="jenny_depends_on" class="org.springframework.tests.sample.beans.TestBean" depends-on="david_depends_on">
</bean>
<bean id="david_depends_on" class="org.springframework.tests.sample.beans.TestBean" depends-on="jenny_depends_on">
</bean>
<bean id="jenks" class="org.springframework.tests.sample.beans.TestBean" scope="prototype">
<property name="name"><value>Andrew</value></property>
<property name="age"><value>36</value></property>

Loading…
Cancel
Save