KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > config > PropertyPathFactoryBeanTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.beans.factory.config;
18
19 import junit.framework.TestCase;
20
21 import org.springframework.beans.ITestBean;
22 import org.springframework.beans.TestBean;
23 import org.springframework.beans.factory.xml.XmlBeanFactory;
24 import org.springframework.core.io.ClassPathResource;
25
26 /**
27  * @author Juergen Hoeller
28  * @since 04.10.2004
29  */

30 public class PropertyPathFactoryBeanTests extends TestCase {
31
32     public void testPropertyPathFactoryBeanWithSingletonResult() {
33         XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass()));
34         assertEquals(new Integer JavaDoc(12), xbf.getBean("propertyPath1"));
35         assertEquals(new Integer JavaDoc(11), xbf.getBean("propertyPath2"));
36         assertEquals(new Integer JavaDoc(10), xbf.getBean("tb.age"));
37         assertEquals(ITestBean.class, xbf.getType("otb.spouse"));
38         Object JavaDoc result1 = xbf.getBean("otb.spouse");
39         Object JavaDoc result2 = xbf.getBean("otb.spouse");
40         assertTrue(result1 instanceof TestBean);
41         assertTrue(result1 == result2);
42         assertEquals(99, ((TestBean) result1).getAge());
43     }
44
45     public void testPropertyPathFactoryBeanWithPrototypeResult() {
46         XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass()));
47         assertNull(xbf.getType("tb.spouse"));
48         assertEquals(TestBean.class, xbf.getType("propertyPath3"));
49         Object JavaDoc result1 = xbf.getBean("tb.spouse");
50         Object JavaDoc result2 = xbf.getBean("propertyPath3");
51         Object JavaDoc result3 = xbf.getBean("propertyPath3");
52         assertTrue(result1 instanceof TestBean);
53         assertTrue(result2 instanceof TestBean);
54         assertTrue(result3 instanceof TestBean);
55         assertEquals(11, ((TestBean) result1).getAge());
56         assertEquals(11, ((TestBean) result2).getAge());
57         assertEquals(11, ((TestBean) result3).getAge());
58         assertTrue(result1 != result2);
59         assertTrue(result1 != result3);
60         assertTrue(result2 != result3);
61     }
62
63     public void testBeanReferenceFactoryBean() {
64         XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass()));
65
66         TestBean tb = (TestBean) xbf.getBean("tbAlias");
67         assertEquals(10, tb.getAge());
68         assertEquals(TestBean.class, xbf.getType("tbAlias"));
69         assertFalse(xbf.isSingleton("tbAlias"));
70
71         Object JavaDoc otb = xbf.getBean("otb");
72         assertEquals(otb, xbf.getBean("otbAlias"));
73         assertEquals(TestBean.class, xbf.getType("otbAlias"));
74         assertTrue(xbf.isSingleton("otbAlias"));
75     }
76
77 }
78
Popular Tags