|
Spring Framework example source code file (StaticApplicationContextMulticasterTests.java)
The Spring Framework StaticApplicationContextMulticasterTests.java source code/* * Copyright 2002-2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.context.support; import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.TestBean; import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; import org.springframework.context.ACATest; import org.springframework.context.AbstractApplicationContextTests; import org.springframework.context.ApplicationEvent; import org.springframework.context.BeanThatListens; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.event.SimpleApplicationEventMulticaster; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.EncodedResource; /** * Tests for static application context with custom application event multicaster. * * @author Juergen Hoeller */ public class StaticApplicationContextMulticasterTests extends AbstractApplicationContextTests { protected StaticApplicationContext sac; /** Run for each test */ protected ConfigurableApplicationContext createContext() throws Exception { StaticApplicationContext parent = new StaticApplicationContext(); Map m = new HashMap(); m.put("name", "Roderick"); parent.registerPrototype("rod", TestBean.class, new MutablePropertyValues(m)); m.put("name", "Albert"); parent.registerPrototype("father", TestBean.class, new MutablePropertyValues(m)); parent.registerSingleton(StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, TestApplicationEventMulticaster.class, null); parent.refresh(); parent.addListener(parentListener) ; parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1"); this.sac = new StaticApplicationContext(parent); sac.registerSingleton("beanThatListens", BeanThatListens.class, new MutablePropertyValues()); sac.registerSingleton("aca", ACATest.class, new MutablePropertyValues()); sac.registerPrototype("aca-prototype", ACATest.class, new MutablePropertyValues()); PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory()); Resource resource = new ClassPathResource("testBeans.properties", getClass()); reader.loadBeanDefinitions(new EncodedResource(resource, "ISO-8859-1")); sac.refresh(); sac.addListener(listener); sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2"); return sac; } /** Overridden */ public void testCount() { assertCount(15); } public void testEvents() throws Exception { TestApplicationEventMulticaster.counter = 0; super.testEvents(); assertEquals(1, TestApplicationEventMulticaster.counter); } public static class TestApplicationEventMulticaster extends SimpleApplicationEventMulticaster { private static int counter = 0; public void multicastEvent(ApplicationEvent event) { super.multicastEvent(event); counter++; } } } Other Spring Framework examples (source code examples)Here is a short list of links related to this Spring Framework StaticApplicationContextMulticasterTests.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.