KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > context > access > ContextSingletonBeanFactoryLocatorTests


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.context.access;
18
19 import org.springframework.beans.factory.access.BeanFactoryLocator;
20 import org.springframework.beans.factory.access.SingletonBeanFactoryLocatorTests;
21 import org.springframework.context.support.ClassPathXmlApplicationContext;
22 import org.springframework.util.ClassUtils;
23
24 /**
25  * @author Colin Sampaleanu
26  */

27 public class ContextSingletonBeanFactoryLocatorTests extends SingletonBeanFactoryLocatorTests {
28
29     public void testBaseBeanFactoryDefs() {
30         // just test the base BeanFactory/AppContext defs we are going to work
31
// with in other tests
32
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
33                 new String JavaDoc[] {"/org/springframework/beans/factory/access/beans1.xml",
34                               "/org/springframework/beans/factory/access/beans2.xml"});
35     }
36
37     public void testBasicFunctionality() {
38         
39         // just use definition file from the SingletonBeanFactoryLocator test, since it's
40
// completely valid
41
ContextSingletonBeanFactoryLocator facLoc = new ContextSingletonBeanFactoryLocator(
42                 "classpath*:" + ClassUtils.addResourcePathToPackagePath(
43                 SingletonBeanFactoryLocatorTests.class, "ref1.xml"));
44         
45         basicFunctionalityTest(facLoc);
46     }
47     
48     // this test can run multiple times, but due to static keyed lookup of the locators,
49
// 2nd and subsequent calls will actuall get back same locator instance. This is not
50
// an issue really, since the contained beanfactories will still be loaded and released
51
public void testGetInstance() {
52         
53         // try with and without 'classpath*:' prefix, and with 'classpath:' prefix
54
BeanFactoryLocator facLoc = ContextSingletonBeanFactoryLocator.getInstance(
55                 ClassUtils.addResourcePathToPackagePath(
56                 SingletonBeanFactoryLocatorTests.class, "ref1.xml"));
57         getInstanceTest1(facLoc);
58         
59         facLoc = ContextSingletonBeanFactoryLocator.getInstance(
60                 "classpath*:" + ClassUtils.addResourcePathToPackagePath(
61                 SingletonBeanFactoryLocatorTests.class, "ref1.xml"));
62         getInstanceTest2(facLoc);
63
64         // this will actually get another locator instance, as the key is the resource name
65
facLoc = ContextSingletonBeanFactoryLocator.getInstance(
66                 "classpath:" + ClassUtils.addResourcePathToPackagePath(
67                 SingletonBeanFactoryLocatorTests.class, "ref1.xml"));
68         getInstanceTest3(facLoc);
69     }
70 }
71
Popular Tags