Renamed ShortcutTests to SimplePropertyNamespaceHandlerTests
This commit is contained in:
parent
52d3440266
commit
1b6c4929ad
|
|
@ -16,22 +16,25 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import org.junit.Test;
|
||||||
|
import test.beans.ITestBean;
|
||||||
|
import test.beans.TestBean;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
import test.beans.ITestBean;
|
|
||||||
import test.beans.TestBean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
public class ShortcutTests extends TestCase {
|
public class SimplePropertyNamespaceHandlerTests {
|
||||||
|
|
||||||
public void testSimpleBeanConfigured() throws Exception {
|
@Test
|
||||||
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("shortcutTests.xml", getClass()));
|
public void simpleBeanConfigured() throws Exception {
|
||||||
|
XmlBeanFactory beanFactory =
|
||||||
|
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
|
||||||
ITestBean rob = (TestBean) beanFactory.getBean("rob");
|
ITestBean rob = (TestBean) beanFactory.getBean("rob");
|
||||||
ITestBean sally = (TestBean) beanFactory.getBean("sally");
|
ITestBean sally = (TestBean) beanFactory.getBean("sally");
|
||||||
assertEquals("Rob Harrop", rob.getName());
|
assertEquals("Rob Harrop", rob.getName());
|
||||||
|
|
@ -39,27 +42,26 @@ public class ShortcutTests extends TestCase {
|
||||||
assertEquals(rob.getSpouse(), sally);
|
assertEquals(rob.getSpouse(), sally);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInnerBeanConfigured() throws Exception {
|
@Test
|
||||||
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("shortcutTests.xml", getClass()));
|
public void innerBeanConfigured() throws Exception {
|
||||||
|
XmlBeanFactory beanFactory =
|
||||||
|
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
|
||||||
TestBean sally = (TestBean) beanFactory.getBean("sally2");
|
TestBean sally = (TestBean) beanFactory.getBean("sally2");
|
||||||
ITestBean rob = (TestBean) sally.getSpouse();
|
ITestBean rob = sally.getSpouse();
|
||||||
assertEquals("Rob Harrop", rob.getName());
|
assertEquals("Rob Harrop", rob.getName());
|
||||||
assertEquals(24, rob.getAge());
|
assertEquals(24, rob.getAge());
|
||||||
assertEquals(rob.getSpouse(), sally);
|
assertEquals(rob.getSpouse(), sally);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithPropertyDefinedTwice() throws Exception {
|
@Test(expected = BeanDefinitionStoreException.class)
|
||||||
try {
|
public void withPropertyDefinedTwice() throws Exception {
|
||||||
new XmlBeanFactory(new ClassPathResource("shortcutTestsWithErrors.xml", getClass()));
|
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTestsWithErrors.xml", getClass()));
|
||||||
fail("Should not be able to load a file with property specified twice.");
|
|
||||||
}
|
|
||||||
catch (BeanDefinitionStoreException e) {
|
|
||||||
// success
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertyWithNameEndingInRef() throws Exception {
|
@Test
|
||||||
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("shortcutTests.xml", getClass()));
|
public void propertyWithNameEndingInRef() throws Exception {
|
||||||
|
XmlBeanFactory beanFactory =
|
||||||
|
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
|
||||||
ITestBean sally = (TestBean) beanFactory.getBean("derivedSally");
|
ITestBean sally = (TestBean) beanFactory.getBean("derivedSally");
|
||||||
assertEquals("r", sally.getSpouse().getName());
|
assertEquals("r", sally.getSpouse().getName());
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||||
|
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||||
|
xmlns:p="http://www.springframework.org/schema/p"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||||
|
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||||
|
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||||
|
|
||||||
|
<bean id="rob" class="org.springframework.beans.TestBean" p:name="Rob Harrop" p:spouse-ref="sally">
|
||||||
|
<property name="name" value="Rob Harrop"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="sally" class="org.springframework.beans.TestBean" p:name="Sally Greenwood" p:spouse-ref="rob"/>
|
||||||
|
|
||||||
|
</beans>
|
||||||
Loading…
Reference in New Issue