moving unit tests from .testsuite -> .context.support
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Alef Arendsen
|
||||
*/
|
||||
public class Assembler implements TestIF {
|
||||
|
||||
private Service service;
|
||||
private Logic l;
|
||||
private String name;
|
||||
|
||||
public void setService(Service service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public void setLogic(Logic l) {
|
||||
this.l = l;
|
||||
}
|
||||
|
||||
public void setBeanName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
}
|
||||
|
||||
public void output() {
|
||||
System.out.println("Bean " + name);
|
||||
l.output();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 org.springframework.context.MessageSource;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class AutowiredService {
|
||||
|
||||
private MessageSource messageSource;
|
||||
|
||||
public void setMessageSource(MessageSource messageSource) {
|
||||
if (this.messageSource != null) {
|
||||
throw new IllegalArgumentException("MessageSource should not be set twice");
|
||||
}
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
public MessageSource getMessageSource() {
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,371 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.ResourceTestBean;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.CannotLoadBeanClassException;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ClassPathXmlApplicationContextTests extends TestCase {
|
||||
|
||||
public void testSingleConfigLocation() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/context/support/simpleContext.xml");
|
||||
assertTrue(ctx.containsBean("someMessageSource"));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testMultipleConfigLocations() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
new String[] {
|
||||
"/org/springframework/context/support/test/contextB.xml",
|
||||
"/org/springframework/context/support/test/contextC.xml",
|
||||
"/org/springframework/context/support/test/contextA.xml"});
|
||||
assertTrue(ctx.containsBean("service"));
|
||||
assertTrue(ctx.containsBean("logicOne"));
|
||||
assertTrue(ctx.containsBean("logicTwo"));
|
||||
Service service = (Service) ctx.getBean("service");
|
||||
ctx.refresh();
|
||||
assertTrue(service.isProperlyDestroyed());
|
||||
service = (Service) ctx.getBean("service");
|
||||
ctx.close();
|
||||
assertTrue(service.isProperlyDestroyed());
|
||||
}
|
||||
|
||||
public void testConfigLocationPattern() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/context/support/test/context*.xml");
|
||||
assertTrue(ctx.containsBean("service"));
|
||||
assertTrue(ctx.containsBean("logicOne"));
|
||||
assertTrue(ctx.containsBean("logicTwo"));
|
||||
Service service = (Service) ctx.getBean("service");
|
||||
ctx.close();
|
||||
assertTrue(service.isProperlyDestroyed());
|
||||
}
|
||||
|
||||
public void testSingleConfigLocationWithClass() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"simpleContext.xml", getClass());
|
||||
assertTrue(ctx.containsBean("someMessageSource"));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testAliasWithPlaceholder() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
new String[] {
|
||||
"/org/springframework/context/support/test/contextB.xml",
|
||||
"/org/springframework/context/support/test/aliased-contextC.xml",
|
||||
"/org/springframework/context/support/test/contextA.xml"});
|
||||
assertTrue(ctx.containsBean("service"));
|
||||
assertTrue(ctx.containsBean("logicOne"));
|
||||
assertTrue(ctx.containsBean("logicTwo"));
|
||||
ctx.refresh();
|
||||
}
|
||||
|
||||
public void testContextWithInvalidValueType() throws IOException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
new String[] {"/org/springframework/context/support/invalidValueType.xml"}, false);
|
||||
try {
|
||||
context.refresh();
|
||||
fail("Should have thrown BeanCreationException");
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
assertTrue(ex.contains(TypeMismatchException.class));
|
||||
assertTrue(ex.toString().indexOf("someMessageSource") != -1);
|
||||
assertTrue(ex.toString().indexOf("useCodeAsDefaultMessage") != -1);
|
||||
checkExceptionFromInvalidValueType(ex);
|
||||
checkExceptionFromInvalidValueType(new ExceptionInInitializerError(ex));
|
||||
assertFalse(context.isActive());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkExceptionFromInvalidValueType(Throwable ex) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ex.printStackTrace(new PrintStream(baos));
|
||||
String dump = FileCopyUtils.copyToString(
|
||||
new InputStreamReader(new ByteArrayInputStream(baos.toByteArray())));
|
||||
assertTrue(dump.indexOf("someMessageSource") != -1);
|
||||
assertTrue(dump.indexOf("useCodeAsDefaultMessage") != -1);
|
||||
}
|
||||
|
||||
public void testContextWithInvalidLazyClass() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"invalidClass.xml", getClass());
|
||||
assertTrue(ctx.containsBean("someMessageSource"));
|
||||
try {
|
||||
ctx.getBean("someMessageSource");
|
||||
fail("Should have thrown CannotLoadBeanClassException");
|
||||
}
|
||||
catch (CannotLoadBeanClassException ex) {
|
||||
assertTrue(ex.contains(ClassNotFoundException.class));
|
||||
}
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testContextWithClassNameThatContainsPlaceholder() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"classWithPlaceholder.xml", getClass());
|
||||
assertTrue(ctx.containsBean("someMessageSource"));
|
||||
assertTrue(ctx.getBean("someMessageSource") instanceof StaticMessageSource);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testMultipleConfigLocationsWithClass() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
new String[] {"test/contextB.xml", "test/contextC.xml", "test/contextA.xml"}, getClass());
|
||||
assertTrue(ctx.containsBean("service"));
|
||||
assertTrue(ctx.containsBean("logicOne"));
|
||||
assertTrue(ctx.containsBean("logicTwo"));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testFactoryBeanAndApplicationListener() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/context/support/test/context*.xml");
|
||||
ctx.getBeanFactory().registerSingleton("manualFBAAL", new FactoryBeanAndApplicationListener());
|
||||
assertEquals(2, ctx.getBeansOfType(ApplicationListener.class).size());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testMessageSourceAware() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/context/support/test/context*.xml");
|
||||
MessageSource messageSource = (MessageSource) ctx.getBean("messageSource");
|
||||
Service service1 = (Service) ctx.getBean("service");
|
||||
assertEquals(ctx, service1.getMessageSource());
|
||||
Service service2 = (Service) ctx.getBean("service2");
|
||||
assertEquals(ctx, service2.getMessageSource());
|
||||
AutowiredService autowiredService1 = (AutowiredService) ctx.getBean("autowiredService");
|
||||
assertEquals(messageSource, autowiredService1.getMessageSource());
|
||||
AutowiredService autowiredService2 = (AutowiredService) ctx.getBean("autowiredService2");
|
||||
assertEquals(messageSource, autowiredService2.getMessageSource());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testResourceArrayPropertyEditor() throws IOException {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/context/support/test/context*.xml");
|
||||
Service service = (Service) ctx.getBean("service");
|
||||
assertEquals(3, service.getResources().length);
|
||||
List resources = Arrays.asList(service.getResources());
|
||||
assertTrue(resources.contains(
|
||||
new FileSystemResource(new ClassPathResource("/org/springframework/context/support/test/contextA.xml").getFile())));
|
||||
assertTrue(resources.contains(
|
||||
new FileSystemResource(new ClassPathResource("/org/springframework/context/support/test/contextB.xml").getFile())));
|
||||
assertTrue(resources.contains(
|
||||
new FileSystemResource(new ClassPathResource("/org/springframework/context/support/test/contextC.xml").getFile())));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testChildWithProxy() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/context/support/test/context*.xml");
|
||||
ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(
|
||||
new String[] {"/org/springframework/context/support/childWithProxy.xml"}, ctx);
|
||||
assertTrue(AopUtils.isAopProxy(child.getBean("assemblerOne")));
|
||||
assertTrue(AopUtils.isAopProxy(child.getBean("assemblerTwo")));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testAliasForParentContext() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/context/support/simpleContext.xml");
|
||||
assertTrue(ctx.containsBean("someMessageSource"));
|
||||
|
||||
ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(
|
||||
new String[] {"/org/springframework/context/support/aliasForParent.xml"}, ctx);
|
||||
assertTrue(child.containsBean("someMessageSource"));
|
||||
assertTrue(child.containsBean("yourMessageSource"));
|
||||
assertTrue(child.containsBean("myMessageSource"));
|
||||
assertTrue(child.isSingleton("someMessageSource"));
|
||||
assertTrue(child.isSingleton("yourMessageSource"));
|
||||
assertTrue(child.isSingleton("myMessageSource"));
|
||||
assertEquals(StaticMessageSource.class, child.getType("someMessageSource"));
|
||||
assertEquals(StaticMessageSource.class, child.getType("yourMessageSource"));
|
||||
assertEquals(StaticMessageSource.class, child.getType("myMessageSource"));
|
||||
|
||||
Object someMs = child.getBean("someMessageSource");
|
||||
Object yourMs = child.getBean("yourMessageSource");
|
||||
Object myMs = child.getBean("myMessageSource");
|
||||
assertSame(someMs, yourMs);
|
||||
assertSame(someMs, myMs);
|
||||
|
||||
String[] aliases = child.getAliases("someMessageSource");
|
||||
assertEquals(2, aliases.length);
|
||||
assertEquals("myMessageSource", aliases[0]);
|
||||
assertEquals("yourMessageSource", aliases[1]);
|
||||
aliases = child.getAliases("myMessageSource");
|
||||
assertEquals(2, aliases.length);
|
||||
assertEquals("someMessageSource", aliases[0]);
|
||||
assertEquals("yourMessageSource", aliases[1]);
|
||||
|
||||
child.close();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testAliasThatOverridesParent() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/context/support/simpleContext.xml");
|
||||
Object someMs = ctx.getBean("someMessageSource");
|
||||
|
||||
ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(
|
||||
new String[] {"/org/springframework/context/support/aliasThatOverridesParent.xml"}, ctx);
|
||||
Object myMs = child.getBean("myMessageSource");
|
||||
Object someMs2 = child.getBean("someMessageSource");
|
||||
assertSame(myMs, someMs2);
|
||||
assertNotSame(someMs, someMs2);
|
||||
assertOneMessageSourceOnly(child, myMs);
|
||||
}
|
||||
|
||||
public void testAliasThatOverridesEarlierBean() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
new String[] {"/org/springframework/context/support/simpleContext.xml",
|
||||
"/org/springframework/context/support/aliasThatOverridesParent.xml"});
|
||||
Object myMs = ctx.getBean("myMessageSource");
|
||||
Object someMs2 = ctx.getBean("someMessageSource");
|
||||
assertSame(myMs, someMs2);
|
||||
assertOneMessageSourceOnly(ctx, myMs);
|
||||
}
|
||||
|
||||
private void assertOneMessageSourceOnly(ClassPathXmlApplicationContext ctx, Object myMessageSource) {
|
||||
String[] beanNamesForType = ctx.getBeanNamesForType(StaticMessageSource.class);
|
||||
assertEquals(1, beanNamesForType.length);
|
||||
assertEquals("myMessageSource", beanNamesForType[0]);
|
||||
beanNamesForType = ctx.getBeanNamesForType(StaticMessageSource.class, true, true);
|
||||
assertEquals(1, beanNamesForType.length);
|
||||
assertEquals("myMessageSource", beanNamesForType[0]);
|
||||
beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ctx, StaticMessageSource.class);
|
||||
assertEquals(1, beanNamesForType.length);
|
||||
assertEquals("myMessageSource", beanNamesForType[0]);
|
||||
beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ctx, StaticMessageSource.class, true, true);
|
||||
assertEquals(1, beanNamesForType.length);
|
||||
assertEquals("myMessageSource", beanNamesForType[0]);
|
||||
|
||||
Map beansOfType = ctx.getBeansOfType(StaticMessageSource.class);
|
||||
assertEquals(1, beansOfType.size());
|
||||
assertSame(myMessageSource, beansOfType.values().iterator().next());
|
||||
beansOfType = ctx.getBeansOfType(StaticMessageSource.class, true, true);
|
||||
assertEquals(1, beansOfType.size());
|
||||
assertSame(myMessageSource, beansOfType.values().iterator().next());
|
||||
beansOfType = BeanFactoryUtils.beansOfTypeIncludingAncestors(ctx, StaticMessageSource.class);
|
||||
assertEquals(1, beansOfType.size());
|
||||
assertSame(myMessageSource, beansOfType.values().iterator().next());
|
||||
beansOfType = BeanFactoryUtils.beansOfTypeIncludingAncestors(ctx, StaticMessageSource.class, true, true);
|
||||
assertEquals(1, beansOfType.size());
|
||||
assertSame(myMessageSource, beansOfType.values().iterator().next());
|
||||
}
|
||||
|
||||
public void testResourceAndInputStream() throws IOException {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext("/org/springframework/beans/factory/xml/resource.xml") {
|
||||
public Resource getResource(String location) {
|
||||
if ("classpath:org/springframework/beans/factory/xml/test.properties".equals(location)) {
|
||||
return new ClassPathResource("test.properties", ClassPathXmlApplicationContextTests.class);
|
||||
}
|
||||
return super.getResource(location);
|
||||
}
|
||||
};
|
||||
ResourceTestBean resource1 = (ResourceTestBean) ctx.getBean("resource1");
|
||||
ResourceTestBean resource2 = (ResourceTestBean) ctx.getBean("resource2");
|
||||
assertTrue(resource1.getResource() instanceof ClassPathResource);
|
||||
StringWriter writer = new StringWriter();
|
||||
FileCopyUtils.copy(new InputStreamReader(resource1.getResource().getInputStream()), writer);
|
||||
assertEquals("contexttest", writer.toString());
|
||||
writer = new StringWriter();
|
||||
FileCopyUtils.copy(new InputStreamReader(resource1.getInputStream()), writer);
|
||||
assertEquals("contexttest", writer.toString());
|
||||
writer = new StringWriter();
|
||||
FileCopyUtils.copy(new InputStreamReader(resource2.getResource().getInputStream()), writer);
|
||||
assertEquals("contexttest", writer.toString());
|
||||
writer = new StringWriter();
|
||||
FileCopyUtils.copy(new InputStreamReader(resource2.getInputStream()), writer);
|
||||
assertEquals("contexttest", writer.toString());
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testGenericApplicationContextWithXmlBeanDefinitions() {
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("test/contextB.xml", getClass()));
|
||||
reader.loadBeanDefinitions(new ClassPathResource("test/contextC.xml", getClass()));
|
||||
reader.loadBeanDefinitions(new ClassPathResource("test/contextA.xml", getClass()));
|
||||
ctx.refresh();
|
||||
assertTrue(ctx.containsBean("service"));
|
||||
assertTrue(ctx.containsBean("logicOne"));
|
||||
assertTrue(ctx.containsBean("logicTwo"));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testGenericApplicationContextWithXmlBeanDefinitionsAndClassLoaderNull() {
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
ctx.setClassLoader(null);
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("test/contextB.xml", getClass()));
|
||||
reader.loadBeanDefinitions(new ClassPathResource("test/contextC.xml", getClass()));
|
||||
reader.loadBeanDefinitions(new ClassPathResource("test/contextA.xml", getClass()));
|
||||
ctx.refresh();
|
||||
assertEquals(ObjectUtils.identityToString(ctx), ctx.getId());
|
||||
assertEquals(ObjectUtils.identityToString(ctx), ctx.getDisplayName());
|
||||
assertTrue(ctx.containsBean("service"));
|
||||
assertTrue(ctx.containsBean("logicOne"));
|
||||
assertTrue(ctx.containsBean("logicTwo"));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
public void testGenericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId() {
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
ctx.setId("testContext");
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
|
||||
reader.loadBeanDefinitions(new ClassPathResource("test/contextB.xml", getClass()));
|
||||
reader.loadBeanDefinitions(new ClassPathResource("test/contextC.xml", getClass()));
|
||||
reader.loadBeanDefinitions(new ClassPathResource("test/contextA.xml", getClass()));
|
||||
ctx.refresh();
|
||||
assertEquals("testContext", ctx.getId());
|
||||
assertEquals("testContext", ctx.getDisplayName());
|
||||
assertTrue(ctx.containsBean("service"));
|
||||
assertTrue(ctx.containsBean("logicOne"));
|
||||
assertTrue(ctx.containsBean("logicTwo"));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.springframework.context.support;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 06.10.2004
|
||||
*/
|
||||
public class FactoryBeanAndApplicationListener implements FactoryBean, ApplicationListener {
|
||||
|
||||
public Object getObject() throws Exception {
|
||||
return "";
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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 org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
|
||||
|
||||
public class Logic implements BeanNameAware {
|
||||
|
||||
private Log log = LogFactory.getLog(Logic.class);
|
||||
private String name;
|
||||
private Assembler a;
|
||||
|
||||
public void setAssembler(Assembler a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
|
||||
*/
|
||||
public void setBeanName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void output() {
|
||||
System.out.println("Bean " + name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,270 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.context.MessageSourceResolvable;
|
||||
import org.springframework.context.NoSuchMessageException;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.core.JdkVersion;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 03.02.2004
|
||||
*/
|
||||
public class ResourceBundleMessageSourceTests extends TestCase {
|
||||
|
||||
public void testMessageAccessWithDefaultMessageSource() {
|
||||
doTestMessageAccess(false, true, false, false, false);
|
||||
}
|
||||
|
||||
public void testMessageAccessWithDefaultMessageSourceAndMessageFormat() {
|
||||
doTestMessageAccess(false, true, false, false, true);
|
||||
}
|
||||
|
||||
public void testMessageAccessWithDefaultMessageSourceAndFallbackToGerman() {
|
||||
doTestMessageAccess(false, true, true, true, false);
|
||||
}
|
||||
|
||||
public void testMessageAccessWithReloadableMessageSource() {
|
||||
doTestMessageAccess(true, true, false, false, false);
|
||||
}
|
||||
|
||||
public void testMessageAccessWithReloadableMessageSourceAndMessageFormat() {
|
||||
doTestMessageAccess(true, true, false, false, true);
|
||||
}
|
||||
|
||||
public void testMessageAccessWithReloadableMessageSourceAndFallbackToGerman() {
|
||||
doTestMessageAccess(true, true, true, true, false);
|
||||
}
|
||||
|
||||
public void testMessageAccessWithReloadableMessageSourceAndFallbackTurnedOff() {
|
||||
doTestMessageAccess(true, false, false, false, false);
|
||||
}
|
||||
|
||||
public void testMessageAccessWithReloadableMessageSourceAndFallbackTurnedOffAndFallbackToGerman() {
|
||||
doTestMessageAccess(true, false, true, true, false);
|
||||
}
|
||||
|
||||
protected void doTestMessageAccess(
|
||||
boolean reloadable, boolean fallbackToSystemLocale,
|
||||
boolean expectGermanFallback, boolean useCodeAsDefaultMessage, boolean alwaysUseMessageFormat) {
|
||||
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
if (reloadable) {
|
||||
StaticApplicationContext parent = new StaticApplicationContext();
|
||||
parent.refresh();
|
||||
ac.setParent(parent);
|
||||
}
|
||||
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
String basepath = "org/springframework/context/support/";
|
||||
String[] basenames = null;
|
||||
if (reloadable) {
|
||||
basenames = new String[] {
|
||||
"classpath:" + basepath + "messages",
|
||||
"classpath:" + basepath + "more-messages"};
|
||||
}
|
||||
else {
|
||||
basenames = new String[] {
|
||||
basepath + "messages",
|
||||
basepath + "more-messages"};
|
||||
}
|
||||
pvs.addPropertyValue("basenames", basenames);
|
||||
if (!fallbackToSystemLocale) {
|
||||
pvs.addPropertyValue("fallbackToSystemLocale", Boolean.FALSE);
|
||||
}
|
||||
if (useCodeAsDefaultMessage) {
|
||||
pvs.addPropertyValue("useCodeAsDefaultMessage", Boolean.TRUE);
|
||||
}
|
||||
if (alwaysUseMessageFormat) {
|
||||
pvs.addPropertyValue("alwaysUseMessageFormat", Boolean.TRUE);
|
||||
}
|
||||
Class clazz = reloadable ?
|
||||
(Class) ReloadableResourceBundleMessageSource.class : ResourceBundleMessageSource.class;
|
||||
ac.registerSingleton("messageSource", clazz, pvs);
|
||||
ac.refresh();
|
||||
|
||||
Locale.setDefault(expectGermanFallback ? Locale.GERMAN : Locale.CANADA);
|
||||
assertEquals("message1", ac.getMessage("code1", null, Locale.ENGLISH));
|
||||
assertEquals(fallbackToSystemLocale && expectGermanFallback ? "nachricht2" : "message2",
|
||||
ac.getMessage("code2", null, Locale.ENGLISH));
|
||||
|
||||
assertEquals("nachricht2", ac.getMessage("code2", null, Locale.GERMAN));
|
||||
assertEquals("nochricht2", ac.getMessage("code2", null, new Locale("DE", "at")));
|
||||
assertEquals("noochricht2", ac.getMessage("code2", null, new Locale("DE", "at", "oo")));
|
||||
|
||||
if (reloadable && JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) {
|
||||
assertEquals("nachricht2xml", ac.getMessage("code2", null, Locale.GERMANY));
|
||||
}
|
||||
|
||||
MessageSourceAccessor accessor = new MessageSourceAccessor(ac);
|
||||
LocaleContextHolder.setLocale(new Locale("DE", "at"));
|
||||
try {
|
||||
assertEquals("nochricht2", accessor.getMessage("code2"));
|
||||
}
|
||||
finally {
|
||||
LocaleContextHolder.setLocale(null);
|
||||
}
|
||||
|
||||
assertEquals("message3", ac.getMessage("code3", null, Locale.ENGLISH));
|
||||
MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable("code3");
|
||||
assertEquals("message3", ac.getMessage(resolvable, Locale.ENGLISH));
|
||||
resolvable = new DefaultMessageSourceResolvable(new String[] {"code4", "code3"});
|
||||
assertEquals("message3", ac.getMessage(resolvable, Locale.ENGLISH));
|
||||
|
||||
assertEquals("message3", ac.getMessage("code3", null, Locale.ENGLISH));
|
||||
resolvable = new DefaultMessageSourceResolvable(new String[] {"code4", "code3"});
|
||||
assertEquals("message3", ac.getMessage(resolvable, Locale.ENGLISH));
|
||||
|
||||
Object[] args = new Object[] {"Hello", new DefaultMessageSourceResolvable(new String[] {"code1"})};
|
||||
assertEquals("Hello, message1", ac.getMessage("hello", args, Locale.ENGLISH));
|
||||
|
||||
// test default message without and with args
|
||||
assertEquals("default", ac.getMessage(null, null, "default", Locale.ENGLISH));
|
||||
assertEquals("default", ac.getMessage(null, args, "default", Locale.ENGLISH));
|
||||
assertEquals("{0}, default", ac.getMessage(null, null, "{0}, default", Locale.ENGLISH));
|
||||
assertEquals("Hello, default", ac.getMessage(null, args, "{0}, default", Locale.ENGLISH));
|
||||
|
||||
// test resolvable with default message, without and with args
|
||||
resolvable = new DefaultMessageSourceResolvable(null, null, "default");
|
||||
assertEquals("default", ac.getMessage(resolvable, Locale.ENGLISH));
|
||||
resolvable = new DefaultMessageSourceResolvable(null, args, "default");
|
||||
assertEquals("default", ac.getMessage(resolvable, Locale.ENGLISH));
|
||||
resolvable = new DefaultMessageSourceResolvable(null, null, "{0}, default");
|
||||
assertEquals("{0}, default", ac.getMessage(resolvable, Locale.ENGLISH));
|
||||
resolvable = new DefaultMessageSourceResolvable(null, args, "{0}, default");
|
||||
assertEquals("Hello, default", ac.getMessage(resolvable, Locale.ENGLISH));
|
||||
|
||||
// test message args
|
||||
assertEquals("Arg1, Arg2", ac.getMessage("hello", new Object[] {"Arg1", "Arg2"}, Locale.ENGLISH));
|
||||
assertEquals("{0}, {1}", ac.getMessage("hello", null, Locale.ENGLISH));
|
||||
|
||||
if (alwaysUseMessageFormat) {
|
||||
assertEquals("I'm", ac.getMessage("escaped", null, Locale.ENGLISH));
|
||||
}
|
||||
else {
|
||||
assertEquals("I''m", ac.getMessage("escaped", null, Locale.ENGLISH));
|
||||
}
|
||||
assertEquals("I'm", ac.getMessage("escaped", new Object[] {"some arg"}, Locale.ENGLISH));
|
||||
|
||||
try {
|
||||
assertEquals("code4", ac.getMessage("code4", null, Locale.GERMAN));
|
||||
if (!useCodeAsDefaultMessage) {
|
||||
fail("Should have thrown NoSuchMessageException");
|
||||
}
|
||||
}
|
||||
catch (NoSuchMessageException ex) {
|
||||
if (useCodeAsDefaultMessage) {
|
||||
fail("Should have returned code as default message");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testDefaultApplicationContextMessageSource() {
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
ac.refresh();
|
||||
assertEquals("default", ac.getMessage("code1", null, "default", Locale.ENGLISH));
|
||||
assertEquals("default value", ac.getMessage("code1", new Object[] {"value"}, "default {0}", Locale.ENGLISH));
|
||||
}
|
||||
|
||||
public void testResourceBundleMessageSourceStandalone() {
|
||||
ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
|
||||
ms.setBasename("org/springframework/context/support/messages");
|
||||
assertEquals("message1", ms.getMessage("code1", null, Locale.ENGLISH));
|
||||
assertEquals("nachricht2", ms.getMessage("code2", null, Locale.GERMAN));
|
||||
}
|
||||
|
||||
public void testResourceBundleMessageSourceWithWhitespaceInBasename() {
|
||||
ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
|
||||
ms.setBasename(" org/springframework/context/support/messages ");
|
||||
assertEquals("message1", ms.getMessage("code1", null, Locale.ENGLISH));
|
||||
assertEquals("nachricht2", ms.getMessage("code2", null, Locale.GERMAN));
|
||||
}
|
||||
|
||||
public void testReloadableResourceBundleMessageSourceStandalone() {
|
||||
ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
|
||||
ms.setBasename("org/springframework/context/support/messages");
|
||||
assertEquals("message1", ms.getMessage("code1", null, Locale.ENGLISH));
|
||||
assertEquals("nachricht2", ms.getMessage("code2", null, Locale.GERMAN));
|
||||
}
|
||||
|
||||
public void testReloadableResourceBundleMessageSourceWithWhitespaceInBasename() {
|
||||
ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
|
||||
ms.setBasename(" org/springframework/context/support/messages ");
|
||||
assertEquals("message1", ms.getMessage("code1", null, Locale.ENGLISH));
|
||||
assertEquals("nachricht2", ms.getMessage("code2", null, Locale.GERMAN));
|
||||
}
|
||||
|
||||
public void testReloadableResourceBundleMessageSourceWithDefaultCharset() {
|
||||
ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
|
||||
ms.setBasename("org/springframework/context/support/messages");
|
||||
ms.setDefaultEncoding("ISO-8859-1");
|
||||
assertEquals("message1", ms.getMessage("code1", null, Locale.ENGLISH));
|
||||
assertEquals("nachricht2", ms.getMessage("code2", null, Locale.GERMAN));
|
||||
}
|
||||
|
||||
public void testReloadableResourceBundleMessageSourceWithInappropriateDefaultCharset() {
|
||||
ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
|
||||
ms.setBasename("org/springframework/context/support/messages");
|
||||
ms.setDefaultEncoding("unicode");
|
||||
Properties fileCharsets = new Properties();
|
||||
fileCharsets.setProperty("org/springframework/context/support/messages_de", "unicode");
|
||||
ms.setFileEncodings(fileCharsets);
|
||||
ms.setFallbackToSystemLocale(false);
|
||||
try {
|
||||
ms.getMessage("code1", null, Locale.ENGLISH);
|
||||
fail("Should have thrown NoSuchMessageException");
|
||||
}
|
||||
catch (NoSuchMessageException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testReloadableResourceBundleMessageSourceWithInappropriateEnglishCharset() {
|
||||
ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
|
||||
ms.setBasename("org/springframework/context/support/messages");
|
||||
ms.setFallbackToSystemLocale(false);
|
||||
Properties fileCharsets = new Properties();
|
||||
fileCharsets.setProperty("org/springframework/context/support/messages", "unicode");
|
||||
ms.setFileEncodings(fileCharsets);
|
||||
try {
|
||||
ms.getMessage("code1", null, Locale.ENGLISH);
|
||||
fail("Should have thrown NoSuchMessageException");
|
||||
}
|
||||
catch (NoSuchMessageException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testReloadableResourceBundleMessageSourceWithInappropriateGermanCharset() {
|
||||
ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
|
||||
ms.setBasename("org/springframework/context/support/messages");
|
||||
ms.setFallbackToSystemLocale(false);
|
||||
Properties fileCharsets = new Properties();
|
||||
fileCharsets.setProperty("org/springframework/context/support/messages_de", "unicode");
|
||||
ms.setFileEncodings(fileCharsets);
|
||||
assertEquals("message1", ms.getMessage("code1", null, Locale.ENGLISH));
|
||||
assertEquals("message2", ms.getMessage("code2", null, Locale.GERMAN));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2006 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 org.springframework.beans.factory.BeanCreationNotAllowedException;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.MessageSourceAware;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Alef Arendsen
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class Service implements ApplicationContextAware, MessageSourceAware, DisposableBean {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private MessageSource messageSource;
|
||||
|
||||
private Resource[] resources;
|
||||
|
||||
private boolean properlyDestroyed = false;
|
||||
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public void setMessageSource(MessageSource messageSource) {
|
||||
if (this.messageSource != null) {
|
||||
throw new IllegalArgumentException("MessageSource should not be set twice");
|
||||
}
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
public MessageSource getMessageSource() {
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
public void setResources(Resource[] resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
public Resource[] getResources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
|
||||
public void destroy() {
|
||||
this.properlyDestroyed = true;
|
||||
Thread thread = new Thread() {
|
||||
public void run() {
|
||||
Assert.isTrue(applicationContext.getBean("messageSource") instanceof StaticMessageSource);
|
||||
try {
|
||||
applicationContext.getBean("service2");
|
||||
// Should have thrown BeanCreationNotAllowedException
|
||||
properlyDestroyed = false;
|
||||
}
|
||||
catch (BeanCreationNotAllowedException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
try {
|
||||
thread.join();
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isProperlyDestroyed() {
|
||||
return properlyDestroyed;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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.ACATester;
|
||||
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", ACATester.class, new MutablePropertyValues());
|
||||
sac.registerPrototype("aca-prototype", ACATester.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++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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.ACATester;
|
||||
import org.springframework.context.AbstractApplicationContextTests;
|
||||
import org.springframework.context.BeanThatListens;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
* Tests for static application context.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class StaticApplicationContextTests 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.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", ACATester.class, new MutablePropertyValues());
|
||||
sac.registerPrototype("aca-prototype", ACATester.class, new MutablePropertyValues());
|
||||
PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory());
|
||||
reader.loadBeanDefinitions(new ClassPathResource("testBeans.properties", getClass()));
|
||||
sac.refresh();
|
||||
sac.addListener(listener);
|
||||
|
||||
sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2");
|
||||
|
||||
return sac;
|
||||
}
|
||||
|
||||
/** Overridden */
|
||||
public void testCount() {
|
||||
assertCount(15);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
||||
import org.springframework.context.ACATester;
|
||||
import org.springframework.context.AbstractApplicationContextTests;
|
||||
import org.springframework.context.BeanThatListens;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.MessageSourceResolvable;
|
||||
import org.springframework.context.NoSuchMessageException;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class StaticMessageSourceTests extends AbstractApplicationContextTests {
|
||||
|
||||
protected static final String MSG_TXT1_US =
|
||||
"At '{1,time}' on \"{1,date}\", there was \"{2}\" on planet {0,number,integer}.";
|
||||
protected static final String MSG_TXT1_UK =
|
||||
"At '{1,time}' on \"{1,date}\", there was \"{2}\" on station number {0,number,integer}.";
|
||||
protected static final String MSG_TXT2_US =
|
||||
"This is a test message in the message catalog with no args.";
|
||||
protected static final String MSG_TXT3_US =
|
||||
"This is another test message in the message catalog with no args.";
|
||||
|
||||
protected StaticApplicationContext sac;
|
||||
|
||||
/** Overridden */
|
||||
public void testCount() {
|
||||
// These are only checked for current Ctx (not parent ctx)
|
||||
assertCount(15);
|
||||
}
|
||||
|
||||
public void testMessageSource() throws NoSuchMessageException {
|
||||
// Do nothing here since super is looking for errorCodes we
|
||||
// do NOT have in the Context
|
||||
}
|
||||
|
||||
public void testGetMessageWithDefaultPassedInAndFoundInMsgCatalog() {
|
||||
// Try with Locale.US
|
||||
assertTrue("valid msg from staticMsgSource with default msg passed in returned msg from msg catalog for Locale.US",
|
||||
sac.getMessage("message.format.example2", null, "This is a default msg if not found in MessageSource.", Locale.US)
|
||||
.equals("This is a test message in the message catalog with no args."));
|
||||
}
|
||||
|
||||
public void testGetMessageWithDefaultPassedInAndNotFoundInMsgCatalog() {
|
||||
// Try with Locale.US
|
||||
assertTrue("bogus msg from staticMsgSource with default msg passed in returned default msg for Locale.US",
|
||||
sac.getMessage("bogus.message", null, "This is a default msg if not found in MessageSource.", Locale.US)
|
||||
.equals("This is a default msg if not found in MessageSource."));
|
||||
}
|
||||
|
||||
/**
|
||||
* We really are testing the AbstractMessageSource class here.
|
||||
* The underlying implementation uses a hashMap to cache messageFormats
|
||||
* once a message has been asked for. This test is an attempt to
|
||||
* make sure the cache is being used properly.
|
||||
* @see org.springframework.context.support.AbstractMessageSource for more details.
|
||||
*/
|
||||
public void testGetMessageWithMessageAlreadyLookedFor() {
|
||||
Object[] arguments = {
|
||||
new Integer(7), new Date(System.currentTimeMillis()),
|
||||
"a disturbance in the Force"
|
||||
};
|
||||
|
||||
// The first time searching, we don't care about for this test
|
||||
// Try with Locale.US
|
||||
sac.getMessage("message.format.example1", arguments, Locale.US);
|
||||
|
||||
// Now msg better be as expected
|
||||
assertTrue("2nd search within MsgFormat cache returned expected message for Locale.US",
|
||||
sac.getMessage("message.format.example1", arguments, Locale.US).indexOf(
|
||||
"there was \"a disturbance in the Force\" on planet 7.") != -1);
|
||||
|
||||
Object[] newArguments = {
|
||||
new Integer(8), new Date(System.currentTimeMillis()),
|
||||
"a disturbance in the Force"
|
||||
};
|
||||
|
||||
// Now msg better be as expected even with different args
|
||||
assertTrue("2nd search within MsgFormat cache with different args returned expected message for Locale.US",
|
||||
sac.getMessage("message.format.example1", newArguments, Locale.US)
|
||||
.indexOf("there was \"a disturbance in the Force\" on planet 8.") != -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Example taken from the javadocs for the java.text.MessageFormat class
|
||||
*/
|
||||
public void testGetMessageWithNoDefaultPassedInAndFoundInMsgCatalog() {
|
||||
Object[] arguments = {
|
||||
new Integer(7), new Date(System.currentTimeMillis()),
|
||||
"a disturbance in the Force"
|
||||
};
|
||||
|
||||
/*
|
||||
Try with Locale.US
|
||||
Since the msg has a time value in it, we will use String.indexOf(...)
|
||||
to just look for a substring without the time. This is because it is
|
||||
possible that by the time we store a time variable in this method
|
||||
and the time the ResourceBundleMessageSource resolves the msg the
|
||||
minutes of the time might not be the same.
|
||||
*/
|
||||
assertTrue("msg from staticMsgSource for Locale.US substituting args for placeholders is as expected",
|
||||
sac.getMessage("message.format.example1", arguments, Locale.US)
|
||||
.indexOf("there was \"a disturbance in the Force\" on planet 7.") != -1);
|
||||
|
||||
// Try with Locale.UK
|
||||
assertTrue("msg from staticMsgSource for Locale.UK substituting args for placeholders is as expected",
|
||||
sac.getMessage("message.format.example1", arguments, Locale.UK)
|
||||
.indexOf("there was \"a disturbance in the Force\" on station number 7.") != -1);
|
||||
|
||||
// Try with Locale.US - Use a different test msg that requires no args
|
||||
assertTrue("msg from staticMsgSource for Locale.US that requires no args is as expected",
|
||||
sac.getMessage("message.format.example2", null, Locale.US)
|
||||
.equals("This is a test message in the message catalog with no args."));
|
||||
}
|
||||
|
||||
public void testGetMessageWithNoDefaultPassedInAndNotFoundInMsgCatalog() {
|
||||
// Expecting an exception
|
||||
try {
|
||||
// Try with Locale.US
|
||||
sac.getMessage("bogus.message", null, Locale.US);
|
||||
|
||||
fail("bogus msg from staticMsgSource for Locale.US without default msg should have thrown exception");
|
||||
}
|
||||
catch (NoSuchMessageException tExcept) {
|
||||
assertTrue("bogus msg from staticMsgSource for Locale.US without default msg threw expected exception", true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testMessageSourceResolvable() {
|
||||
// first code valid
|
||||
String[] codes1 = new String[] {"message.format.example3", "message.format.example2"};
|
||||
MessageSourceResolvable resolvable1 = new DefaultMessageSourceResolvable(codes1, null, "default");
|
||||
try {
|
||||
assertTrue("correct message retrieved", MSG_TXT3_US.equals(sac.getMessage(resolvable1, Locale.US)));
|
||||
}
|
||||
catch (NoSuchMessageException ex) {
|
||||
fail("Should not throw NoSuchMessageException");
|
||||
}
|
||||
|
||||
// only second code valid
|
||||
String[] codes2 = new String[] {"message.format.example99", "message.format.example2"};
|
||||
MessageSourceResolvable resolvable2 = new DefaultMessageSourceResolvable(codes2, null, "default");
|
||||
try {
|
||||
assertTrue("correct message retrieved", MSG_TXT2_US.equals(sac.getMessage(resolvable2, Locale.US)));
|
||||
}
|
||||
catch (NoSuchMessageException ex) {
|
||||
fail("Should not throw NoSuchMessageException");
|
||||
}
|
||||
|
||||
// no code valid, but default given
|
||||
String[] codes3 = new String[] {"message.format.example99", "message.format.example98"};
|
||||
MessageSourceResolvable resolvable3 = new DefaultMessageSourceResolvable(codes3, null, "default");
|
||||
try {
|
||||
assertTrue("correct message retrieved", "default".equals(sac.getMessage(resolvable3, Locale.US)));
|
||||
}
|
||||
catch (NoSuchMessageException ex) {
|
||||
fail("Should not throw NoSuchMessageException");
|
||||
}
|
||||
|
||||
// no code valid, no default
|
||||
String[] codes4 = new String[] {"message.format.example99", "message.format.example98"};
|
||||
MessageSourceResolvable resolvable4 = new DefaultMessageSourceResolvable(codes4);
|
||||
try {
|
||||
sac.getMessage(resolvable4, Locale.US);
|
||||
fail("Should have thrown NoSuchMessageException");
|
||||
}
|
||||
catch (NoSuchMessageException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
/** Run for each test */
|
||||
protected ConfigurableApplicationContext createContext() throws Exception {
|
||||
StaticApplicationContext parent = new StaticApplicationContext();
|
||||
|
||||
Map m = new HashMap();
|
||||
m.put("name", "Roderick");
|
||||
parent.registerPrototype("rod", org.springframework.beans.TestBean.class, new MutablePropertyValues(m));
|
||||
m.put("name", "Albert");
|
||||
parent.registerPrototype("father", org.springframework.beans.TestBean.class, new MutablePropertyValues(m));
|
||||
|
||||
parent.refresh();
|
||||
parent.addListener(parentListener);
|
||||
|
||||
this.sac = new StaticApplicationContext(parent);
|
||||
|
||||
sac.registerSingleton("beanThatListens", BeanThatListens.class, new MutablePropertyValues());
|
||||
|
||||
sac.registerSingleton("aca", ACATester.class, new MutablePropertyValues());
|
||||
|
||||
sac.registerPrototype("aca-prototype", ACATester.class, new MutablePropertyValues());
|
||||
|
||||
PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory());
|
||||
reader.loadBeanDefinitions(new ClassPathResource("testBeans.properties", getClass()));
|
||||
sac.refresh();
|
||||
sac.addListener(listener);
|
||||
|
||||
StaticMessageSource messageSource = sac.getStaticMessageSource();
|
||||
Map usMessages = new HashMap(3);
|
||||
usMessages.put("message.format.example1", MSG_TXT1_US);
|
||||
usMessages.put("message.format.example2", MSG_TXT2_US);
|
||||
usMessages.put("message.format.example3", MSG_TXT3_US);
|
||||
messageSource.addMessages(usMessages, Locale.US);
|
||||
messageSource.addMessage("message.format.example1", Locale.UK, MSG_TXT1_UK);
|
||||
|
||||
return sac;
|
||||
}
|
||||
|
||||
public void testNestedMessageSourceWithParamInChild() {
|
||||
StaticMessageSource source = new StaticMessageSource();
|
||||
StaticMessageSource parent = new StaticMessageSource();
|
||||
source.setParentMessageSource(parent);
|
||||
|
||||
source.addMessage("param", Locale.ENGLISH, "value");
|
||||
parent.addMessage("with.param", Locale.ENGLISH, "put {0} here");
|
||||
|
||||
MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(
|
||||
new String[] {"with.param"}, new Object[] {new DefaultMessageSourceResolvable("param")});
|
||||
|
||||
assertEquals("put value here", source.getMessage(resolvable, Locale.ENGLISH));
|
||||
}
|
||||
|
||||
public void testNestedMessageSourceWithParamInParent() {
|
||||
StaticMessageSource source = new StaticMessageSource();
|
||||
StaticMessageSource parent = new StaticMessageSource();
|
||||
source.setParentMessageSource(parent);
|
||||
|
||||
parent.addMessage("param", Locale.ENGLISH, "value");
|
||||
source.addMessage("with.param", Locale.ENGLISH, "put {0} here");
|
||||
|
||||
MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(
|
||||
new String[] {"with.param"}, new Object[] {new DefaultMessageSourceResolvable("param")});
|
||||
|
||||
assertEquals("put value here", source.getMessage(resolvable, Locale.ENGLISH));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public interface TestIF {
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<alias name="someMessageSource" alias="myMessageSource"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<alias name="myMessageSource" alias="someMessageSource"/>
|
||||
|
||||
<bean id="myMessageSource" class="org.springframework.context.support.StaticMessageSource"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean name="assemblerOne" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager"><ref bean="transactionManager"/></property>
|
||||
<property name="target"><ref parent="assemblerOne"/></property>
|
||||
<property name="proxyTargetClass"><value>true</value></property>
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="test">PROPAGATION_REQUIRED</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean name="assemblerTwo" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager"><ref bean="transactionManager"/></property>
|
||||
<property name="target"><ref parent="assemblerTwo"/></property>
|
||||
<property name="proxyTargetClass"><value>true</value></property>
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="test">PROPAGATION_REQUIRED</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="properties">
|
||||
<props>
|
||||
<prop key="msClass">StaticMessageSource</prop>
|
||||
<prop key="msScope">singleton</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="someMessageSource" class="org.springframework.context.support.${msClass}" scope="${msScope}"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="someMessageSource" class="org.springframework.context.support.StaticMessageSourc" lazy-init="true"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="someMessageSource" class="org.springframework.context.support.StaticMessageSource">
|
||||
<property name="useCodeAsDefaultMessage" value="xxx"/>
|
||||
<property name="alwaysUseMessageFormat" value="yyy"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,5 +0,0 @@
|
||||
code1 = mess\
|
||||
age1
|
||||
code2=message2
|
||||
hello={0}, {1}
|
||||
escaped=I''m
|
||||
@@ -1 +0,0 @@
|
||||
code2=nachricht2
|
||||
@@ -1 +0,0 @@
|
||||
code2=nochricht2
|
||||
@@ -1 +0,0 @@
|
||||
code2=noochricht2
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
|
||||
<properties version="1.0">
|
||||
|
||||
<entry key="code2">nachricht2xml</entry>
|
||||
|
||||
</properties>
|
||||
@@ -1 +0,0 @@
|
||||
code3=message3
|
||||
@@ -1,2 +0,0 @@
|
||||
wrappedAssemblerOne.proxyTargetClass=true
|
||||
wrappedAssemblerTwo.proxyTargetClass=true
|
||||
@@ -1,3 +0,0 @@
|
||||
targetName=wrappedAssemblerOne
|
||||
logicName=logicTwo
|
||||
realLogicName=realLogic
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="someMessageSource" name="yourMessageSource"
|
||||
class="org.springframework.context.support.StaticMessageSource"/>
|
||||
|
||||
<bean class="org.springframework.context.support.ClassPathXmlApplicationContext" lazy-init="true">
|
||||
<constructor-arg value="someNonExistentFile.xml"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1 +0,0 @@
|
||||
contexttest
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:property-placeholder location="org/springframework/context/support/placeholder.properties"/>
|
||||
|
||||
<bean name="realLogic" class="org.springframework.context.support.Logic">
|
||||
<!--<property name="assembler"><ref bean="assemblerOne"/></property>-->
|
||||
<property name="assembler"><ref bean="myTarget"/></property>
|
||||
</bean>
|
||||
|
||||
<alias name="${targetName}" alias="myTarget"/>
|
||||
|
||||
<alias name="${realLogicName}" alias="${logicName}"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<import resource="import1.xml"/>
|
||||
|
||||
<import resource="classpath:org/springframework/context/support/test/*/import2.xml"/>
|
||||
|
||||
<context:property-override location="org/springframework/context/support/override.properties"/>
|
||||
|
||||
<bean id="messageSource" class="org.springframework.context.support.StaticMessageSource"/>
|
||||
|
||||
<bean class="org.springframework.context.support.FactoryBeanAndApplicationListener"/>
|
||||
|
||||
<bean name="service" class="org.springframework.context.support.Service" dependency-check="objects">
|
||||
<property name="resources" value="/org/springframework/context/support/test/context*.xml"/>
|
||||
</bean>
|
||||
|
||||
<bean name="service2" class="org.springframework.context.support.Service" autowire="byName" depends-on="service">
|
||||
<property name="resources" value="/org/springframework/context/support/test/context*.xml"/>
|
||||
</bean>
|
||||
|
||||
<bean name="autowiredService" class="org.springframework.context.support.AutowiredService" autowire="byName"/>
|
||||
|
||||
<bean name="autowiredService2" class="org.springframework.context.support.AutowiredService" autowire="byType"/>
|
||||
|
||||
<bean name="transactionManager" class="org.springframework.transaction.CallCountingTransactionManager"/>
|
||||
|
||||
<bean name="wrappedAssemblerOne" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager" ref="transactionManager"/>
|
||||
<property name="target" ref="assemblerOne"/>
|
||||
<property name="proxyTargetClass" value="xxx"/>
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="test">PROPAGATION_REQUIRED</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean name="wrappedAssemblerTwo" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
|
||||
<property name="transactionManager" ref="transactionManager"/>
|
||||
<property name="target" ref="assemblerTwo"/>
|
||||
<property name="proxyTargetClass" value="yyy"/>
|
||||
<property name="transactionAttributes">
|
||||
<props>
|
||||
<prop key="test">PROPAGATION_REQUIRED</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean name="logicOne" class="org.springframework.context.support.Logic">
|
||||
<!--<property name="assembler"><ref bean="assemblerTwo"/></property>-->
|
||||
<property name="assembler"><ref bean="wrappedAssemblerTwo"/></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:property-placeholder location="org/springframework/context/support/placeholder.properties"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
<bean name="logicTwo" class="org.springframework.context.support.Logic">
|
||||
<!--<property name="assembler"><ref bean="assemblerOne"/></property>-->
|
||||
<property name="assembler"><ref bean="${targetName}"/></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean name="assemblerOne" class="org.springframework.context.support.Assembler">
|
||||
<property name="service"><ref bean="service"/></property>
|
||||
<property name="logic"><ref bean="logicOne"/></property>
|
||||
</bean>
|
||||
|
||||
<bean name="inheritingAssemblerOne" parent="assemblerTwo">
|
||||
<property name="logic"><ref bean="logicOne"/></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean name="assemblerTwo" parent="assemblerOne">
|
||||
<property name="logic"><ref bean="logicTwo"/></property>
|
||||
</bean>
|
||||
|
||||
<!-- Returns void (null) -->
|
||||
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
|
||||
<property name="staticMethod" value="java.lang.System.gc"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,42 +0,0 @@
|
||||
# this must only be used for ApplicationContexts, some classes are only appropriate for application contexts
|
||||
|
||||
rod.(class)=org.springframework.beans.TestBean
|
||||
rod.name=Rod
|
||||
rod.age=31
|
||||
|
||||
roderick.(parent)=rod
|
||||
roderick.name=Roderick
|
||||
|
||||
kerry.(class)=org.springframework.beans.TestBean
|
||||
kerry.name=Kerry
|
||||
kerry.age=34
|
||||
kerry.spouse(ref)=rod
|
||||
|
||||
kathy.(class)=org.springframework.beans.TestBean
|
||||
kathy.(singleton)=false
|
||||
|
||||
typeMismatch.(class)=org.springframework.beans.TestBean
|
||||
typeMismatch.name=typeMismatch
|
||||
typeMismatch.age=34x
|
||||
typeMismatch.spouse(ref)=rod
|
||||
typeMismatch.(singleton)=false
|
||||
|
||||
validEmpty.(class)=org.springframework.beans.TestBean
|
||||
|
||||
listenerVeto.(class)=org.springframework.beans.TestBean
|
||||
|
||||
typeMismatch.name=typeMismatch
|
||||
typeMismatch.age=34x
|
||||
typeMismatch.spouse(ref)=rod
|
||||
|
||||
singletonFactory.(class)=org.springframework.beans.factory.DummyFactory
|
||||
singletonFactory.singleton=true
|
||||
|
||||
prototypeFactory.(class)=org.springframework.beans.factory.DummyFactory
|
||||
prototypeFactory.singleton=false
|
||||
|
||||
mustBeInitialized.(class)=org.springframework.beans.factory.MustBeInitialized
|
||||
|
||||
lifecycle.(class)=org.springframework.context.LifecycleContextBean
|
||||
|
||||
lifecyclePostProcessor.(class)=org.springframework.beans.factory.LifecycleBean$PostProcessor
|
||||
Reference in New Issue
Block a user