1 16 17 package org.springframework.context.support; 18 19 import java.util.HashMap ; 20 import java.util.Locale ; 21 import java.util.Map ; 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 37 public class StaticApplicationContextTests extends AbstractApplicationContextTests { 38 39 protected StaticApplicationContext sac; 40 41 42 protected ConfigurableApplicationContext createContext() throws Exception { 43 StaticApplicationContext parent = new StaticApplicationContext(); 44 Map m = new HashMap (); 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 69 public void testCount() { 70 assertCount(15); 71 } 72 73 } 74 | Popular Tags |