Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
[ch10] GenericApplicationContext / XmlBeanDefinitionReader Test
Browse files Browse the repository at this point in the history
  • Loading branch information
dhsim86 committed Nov 3, 2018
1 parent a107787 commit dd0128b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/resources/ch10/bean-definition-reader-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="hello" class="ch10.springbook._00.Hello">
<property name="name" value="Spring" />
<property name="printer" ref="printer" />
</bean>

<bean id="printer" class="ch10.springbook._00.StringPrinter" />

</beans>
17 changes: 17 additions & 0 deletions src/test/java/ch10/springbook/_00/ApplicationContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.StaticApplicationContext;

import static org.hamcrest.core.Is.is;
Expand Down Expand Up @@ -50,4 +52,19 @@ public void registerBeanWithDependency() {
assertThat(sc.getBean("printer").toString(), is("Hello Spring"));
}

@Test
public void genericApplicationContextTest() {
GenericApplicationContext ac = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);

reader.loadBeanDefinitions("ch10/bean-definition-reader-test.xml");

ac.refresh();

Hello hello = ac.getBean("hello", Hello.class);
hello.print();

assertThat(ac.getBean("printer").toString(), is("Hello Spring"));
}

}

0 comments on commit dd0128b

Please sign in to comment.