KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > context > support > StaticApplicationContextTests


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.support;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.Locale JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.springframework.beans.MutablePropertyValues;
24 import org.springframework.beans.TestBean;
25 import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
26 import org.springframework.context.ACATest;
27 import org.springframework.context.AbstractApplicationContextTests;
28 import org.springframework.context.BeanThatListens;
29 import org.springframework.context.ConfigurableApplicationContext;
30 import org.springframework.core.io.ClassPathResource;
31
32 /**
33  * Tests for static application context.
34  *
35  * @author Rod Johnson
36  */

37 public class StaticApplicationContextTests extends AbstractApplicationContextTests {
38
39     protected StaticApplicationContext sac;
40
41     /** Run for each test */
42     protected ConfigurableApplicationContext createContext() throws Exception JavaDoc {
43         StaticApplicationContext parent = new StaticApplicationContext();
44         Map JavaDoc m = new HashMap JavaDoc();
45         m.put("name", "Roderick");
46         parent.registerPrototype("rod", TestBean.class, new MutablePropertyValues(m));
47         m.put("name", "Albert");
48         parent.registerPrototype("father", TestBean.class, new MutablePropertyValues(m));
49         parent.refresh();
50         parent.addListener(parentListener) ;
51
52         parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1");
53
54         this.sac = new StaticApplicationContext(parent);
55         sac.registerSingleton("beanThatListens", BeanThatListens.class, new MutablePropertyValues());
56         sac.registerSingleton("aca", ACATest.class, new MutablePropertyValues());
57         sac.registerPrototype("aca-prototype", ACATest.class, new MutablePropertyValues());
58         PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory());
59         reader.loadBeanDefinitions(new ClassPathResource("testBeans.properties", getClass()));
60         sac.refresh();
61         sac.addListener(listener);
62
63         sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2");
64
65         return sac;
66     }
67
68     /** Overridden */
69     public void testCount() {
70         assertCount(15);
71     }
72
73 }
74
Popular Tags