polishing .beans tests
This commit is contained in:
parent
a0bf1b4ade
commit
62db6af879
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.beans.factory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static test.util.TestResourceUtils.qualifiedResource;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
|
|
@ -35,7 +36,7 @@ import org.springframework.beans.PropertyEditorRegistrar;
|
|||
import org.springframework.beans.PropertyEditorRegistry;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* @author Guillaume Poirier
|
||||
|
|
@ -46,17 +47,15 @@ import org.springframework.core.io.ClassPathResource;
|
|||
public final class ConcurrentBeanFactoryTests {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ConcurrentBeanFactoryTests.class);
|
||||
|
||||
private static final SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
|
||||
|
||||
private static final Date date1;
|
||||
|
||||
private static final Date date2;
|
||||
private static final Resource CONTEXT = qualifiedResource(ConcurrentBeanFactoryTests.class, "context.xml");
|
||||
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd");
|
||||
private static final Date DATE_1, DATE_2;
|
||||
|
||||
static {
|
||||
try {
|
||||
date1 = df.parse("2004/08/08");
|
||||
date2 = df.parse("2000/02/02");
|
||||
DATE_1 = DATE_FORMAT.parse("2004/08/08");
|
||||
DATE_2 = DATE_FORMAT.parse("2000/02/02");
|
||||
}
|
||||
catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
@ -71,10 +70,10 @@ public final class ConcurrentBeanFactoryTests {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("concurrent.xml", getClass()));
|
||||
XmlBeanFactory factory = new XmlBeanFactory(CONTEXT);
|
||||
factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
|
||||
public void registerCustomEditors(PropertyEditorRegistry registry) {
|
||||
registry.registerCustomEditor(Date.class, new CustomDateEditor((DateFormat) df.clone(), false));
|
||||
registry.registerCustomEditor(Date.class, new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false));
|
||||
}
|
||||
});
|
||||
this.factory = factory;
|
||||
|
|
@ -119,8 +118,8 @@ public final class ConcurrentBeanFactoryTests {
|
|||
ConcurrentBean b1 = (ConcurrentBean) factory.getBean("bean1");
|
||||
ConcurrentBean b2 = (ConcurrentBean) factory.getBean("bean2");
|
||||
|
||||
assertEquals(b1.getDate(), date1);
|
||||
assertEquals(b2.getDate(), date2);
|
||||
assertEquals(b1.getDate(), DATE_1);
|
||||
assertEquals(b2.getDate(), DATE_2);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ import org.springframework.beans.factory.BeanFactory;
|
|||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SingletonBeanFactoryLocator}.
|
||||
*
|
||||
* @author Colin Sampaleanu
|
||||
* @author Chris Beams
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -40,12 +40,14 @@ import test.beans.NestedTestBean;
|
|||
import test.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AutowiredAnnotationBeanPostProcessor}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Mark Fisher
|
||||
* @author Sam Brannen
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AutowiredAnnotationBeanPostProcessorTests {
|
||||
public final class AutowiredAnnotationBeanPostProcessorTests {
|
||||
|
||||
@Test
|
||||
public void testIncompleteBeanDefinition() {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.beans.factory.annotation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static test.util.TestResourceUtils.qualifiedResource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
|
|
@ -25,23 +26,24 @@ import org.springframework.beans.factory.support.AutowireCandidateResolver;
|
|||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CustomAutowireConfigurer}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class CustomAutowireConfigurerTests {
|
||||
|
||||
private static final String CONFIG_LOCATION =
|
||||
"classpath:org/springframework/beans/factory/annotation/customAutowireConfigurer.xml";
|
||||
public final class CustomAutowireConfigurerTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(CustomAutowireConfigurerTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
public void testCustomResolver() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
BeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
||||
reader.loadBeanDefinitions(CONFIG_LOCATION);
|
||||
reader.loadBeanDefinitions(CONTEXT);
|
||||
CustomAutowireConfigurer cac = new CustomAutowireConfigurer();
|
||||
CustomResolver customResolver = new CustomResolver();
|
||||
bf.setAutowireCandidateResolver(customResolver);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* 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.
|
||||
|
|
@ -22,7 +22,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link CommonsLogFactoryBean} class.
|
||||
* Unit tests for {@link CommonsLogFactoryBean}.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
|
|
@ -24,8 +26,7 @@ import java.util.HashMap;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.PropertyEditorRegistrar;
|
||||
|
|
@ -37,11 +38,15 @@ import org.springframework.beans.propertyeditors.CustomDateEditor;
|
|||
import test.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CustomEditorConfigurer}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 31.07.2004
|
||||
*/
|
||||
public class CustomEditorConfigurerTests extends TestCase {
|
||||
public final class CustomEditorConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void testCustomEditorConfigurerWithPropertyEditorRegistrar() throws ParseException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CustomEditorConfigurer cec = new CustomEditorConfigurer();
|
||||
|
|
@ -67,6 +72,7 @@ public class CustomEditorConfigurerTests extends TestCase {
|
|||
assertEquals(df.parse("2.12.1975"), tb2.getSomeMap().get("myKey"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditorConfigurerWithEditorClassName() throws ParseException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CustomEditorConfigurer cec = new CustomEditorConfigurer();
|
||||
|
|
@ -84,6 +90,7 @@ public class CustomEditorConfigurerTests extends TestCase {
|
|||
assertEquals(df.parse("2.12.1975"), tb.getDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditorConfigurerWithRequiredTypeArray() throws ParseException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CustomEditorConfigurer cec = new CustomEditorConfigurer();
|
||||
|
|
@ -101,6 +108,7 @@ public class CustomEditorConfigurerTests extends TestCase {
|
|||
assertEquals("test", tb.getStringArray()[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditorConfigurerWithUnresolvableEditor() throws ParseException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CustomEditorConfigurer cec = new CustomEditorConfigurer();
|
||||
|
|
@ -117,6 +125,7 @@ public class CustomEditorConfigurerTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEditorConfigurerWithIgnoredUnresolvableEditor() throws ParseException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
CustomEditorConfigurer cec = new CustomEditorConfigurer();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
|
@ -26,11 +27,13 @@ import org.junit.Test;
|
|||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CustomScopeConfigurer}.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class CustomScopeConfigurerTests {
|
||||
public final class CustomScopeConfigurerTests {
|
||||
|
||||
private static final String FOO_SCOPE = "fooScope";
|
||||
private ConfigurableListableBeanFactory factory;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
|
|
@ -16,22 +16,31 @@
|
|||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static test.util.TestResourceUtils.qualifiedResource;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import test.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link FieldRetrievingFactoryBean}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 31.07.2004
|
||||
*/
|
||||
public class FieldRetrievingFactoryBeanTests extends TestCase {
|
||||
public final class FieldRetrievingFactoryBeanTests {
|
||||
|
||||
private static final Resource CONTEXT =
|
||||
qualifiedResource(FieldRetrievingFactoryBeanTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
public void testStaticField() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
fr.setStaticField("java.sql.Connection.TRANSACTION_SERIALIZABLE");
|
||||
|
|
@ -39,6 +48,7 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
|
|||
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), fr.getObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticFieldWithWhitespace() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
fr.setStaticField(" java.sql.Connection.TRANSACTION_SERIALIZABLE ");
|
||||
|
|
@ -46,6 +56,7 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
|
|||
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), fr.getObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticFieldViaClassAndFieldName() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
fr.setTargetClass(Connection.class);
|
||||
|
|
@ -54,6 +65,7 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
|
|||
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), fr.getObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonStaticField() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
PublicFieldHolder target = new PublicFieldHolder();
|
||||
|
|
@ -63,6 +75,7 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
|
|||
assertEquals(target.publicField, fr.getObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNothingButBeanName() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
fr.setBeanName("java.sql.Connection.TRANSACTION_SERIALIZABLE");
|
||||
|
|
@ -70,6 +83,7 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
|
|||
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), fr.getObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJustTargetField() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
fr.setTargetField("TRANSACTION_SERIALIZABLE");
|
||||
|
|
@ -80,6 +94,7 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJustTargetClass() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
fr.setTargetClass(Connection.class);
|
||||
|
|
@ -90,6 +105,7 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJustTargetObject() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
fr.setTargetObject(new PublicFieldHolder());
|
||||
|
|
@ -100,6 +116,7 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithConstantOnClassWithPackageLevelVisibility() throws Exception {
|
||||
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
|
||||
fr.setBeanName("test.beans.PackageLevelVisibleBean.CONSTANT");
|
||||
|
|
@ -107,9 +124,10 @@ public class FieldRetrievingFactoryBeanTests extends TestCase {
|
|||
assertEquals("Wuby", fr.getObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanNameSyntaxWithBeanFactory() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("fieldRetrieving.xml", getClass()));
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
|
||||
TestBean testBean = (TestBean) bf.getBean("testBean");
|
||||
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[0]);
|
||||
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[1]);
|
||||
|
|
|
|||
|
|
@ -16,23 +16,28 @@
|
|||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
||||
import org.springframework.beans.support.ArgumentConvertingMethodInvoker;
|
||||
import org.springframework.util.MethodInvoker;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MethodInvokingFactoryBean}.
|
||||
*
|
||||
* @author Colin Sampaleanu
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 21.11.2003
|
||||
*/
|
||||
public class MethodInvokingFactoryBeanTests extends TestCase {
|
||||
public final class MethodInvokingFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testParameterValidation() throws Exception {
|
||||
String validationError = "improper validation of input properties";
|
||||
|
||||
|
|
@ -119,6 +124,7 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
mcfb.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetObjectType() throws Exception {
|
||||
TestClass1 tc1 = new TestClass1();
|
||||
MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean();
|
||||
|
|
@ -132,7 +138,7 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
mcfb.setTargetClass(TestClass1.class);
|
||||
mcfb.setTargetMethod("voidRetvalMethod");
|
||||
mcfb.afterPropertiesSet();
|
||||
Class objType = mcfb.getObjectType();
|
||||
Class<?> objType = mcfb.getObjectType();
|
||||
assertTrue(objType.equals(void.class));
|
||||
|
||||
// verify that we can call a method with args that are subtypes of the
|
||||
|
|
@ -141,7 +147,7 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
mcfb = new MethodInvokingFactoryBean();
|
||||
mcfb.setTargetClass(TestClass1.class);
|
||||
mcfb.setTargetMethod("supertypes");
|
||||
mcfb.setArguments(new Object[] {new ArrayList(), new ArrayList(), "hello"});
|
||||
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello"});
|
||||
mcfb.afterPropertiesSet();
|
||||
mcfb.getObjectType();
|
||||
|
||||
|
|
@ -160,6 +166,7 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetObject() throws Exception {
|
||||
// singleton, non-static
|
||||
TestClass1 tc1 = new TestClass1();
|
||||
|
|
@ -217,16 +224,17 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
mcfb = new MethodInvokingFactoryBean();
|
||||
mcfb.setTargetClass(TestClass1.class);
|
||||
mcfb.setTargetMethod("supertypes");
|
||||
mcfb.setArguments(new Object[] {new ArrayList(), new ArrayList(), "hello"});
|
||||
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello"});
|
||||
// should pass
|
||||
mcfb.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgumentConversion() throws Exception {
|
||||
MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean();
|
||||
mcfb.setTargetClass(TestClass1.class);
|
||||
mcfb.setTargetMethod("supertypes");
|
||||
mcfb.setArguments(new Object[] {new ArrayList(), new ArrayList(), "hello", "bogus"});
|
||||
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello", "bogus"});
|
||||
try {
|
||||
mcfb.afterPropertiesSet();
|
||||
fail("Matched method with wrong number of args");
|
||||
|
|
@ -251,14 +259,14 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
mcfb = new MethodInvokingFactoryBean();
|
||||
mcfb.setTargetClass(TestClass1.class);
|
||||
mcfb.setTargetMethod("supertypes2");
|
||||
mcfb.setArguments(new Object[] {new ArrayList(), new ArrayList(), "hello", "bogus"});
|
||||
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), "hello", "bogus"});
|
||||
mcfb.afterPropertiesSet();
|
||||
assertEquals("hello", mcfb.getObject());
|
||||
|
||||
mcfb = new MethodInvokingFactoryBean();
|
||||
mcfb.setTargetClass(TestClass1.class);
|
||||
mcfb.setTargetMethod("supertypes2");
|
||||
mcfb.setArguments(new Object[] {new ArrayList(), new ArrayList(), new Object()});
|
||||
mcfb.setArguments(new Object[] {new ArrayList<Object>(), new ArrayList<Object>(), new Object()});
|
||||
try {
|
||||
mcfb.afterPropertiesSet();
|
||||
fail("Matched method when shouldn't have matched");
|
||||
|
|
@ -268,6 +276,7 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeWithNullArgument() throws Exception {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.setTargetClass(TestClass1.class);
|
||||
|
|
@ -277,6 +286,7 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
methodInvoker.invoke();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeWithIntArgument() throws Exception {
|
||||
ArgumentConvertingMethodInvoker methodInvoker = new ArgumentConvertingMethodInvoker();
|
||||
methodInvoker.setTargetClass(TestClass1.class);
|
||||
|
|
@ -293,6 +303,7 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
methodInvoker.invoke();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeWithIntArguments() throws Exception {
|
||||
ArgumentConvertingMethodInvoker methodInvoker = new ArgumentConvertingMethodInvoker();
|
||||
methodInvoker.setTargetClass(TestClass1.class);
|
||||
|
|
@ -363,23 +374,23 @@ public class MethodInvokingFactoryBeanTests extends TestCase {
|
|||
public static void intArguments(int[] arg) {
|
||||
}
|
||||
|
||||
public static String supertypes(Collection c, Integer i) {
|
||||
public static String supertypes(Collection<?> c, Integer i) {
|
||||
return i.toString();
|
||||
}
|
||||
|
||||
public static String supertypes(Collection c, List l, String s) {
|
||||
public static String supertypes(Collection<?> c, List<?> l, String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String supertypes2(Collection c, List l, Integer i) {
|
||||
public static String supertypes2(Collection<?> c, List<?> l, Integer i) {
|
||||
return i.toString();
|
||||
}
|
||||
|
||||
public static String supertypes2(Collection c, List l, String s, Integer i) {
|
||||
public static String supertypes2(Collection<?> c, List<?> l, String s, Integer i) {
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String supertypes2(Collection c, List l, String s, String s2) {
|
||||
public static String supertypes2(Collection<?> c, List<?> l, String s, String s2) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* 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.
|
||||
|
|
@ -16,65 +16,72 @@
|
|||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static test.util.TestResourceUtils.qualifiedResource;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Unit tests for the ObjectFactoryCreatingFactoryBean class.
|
||||
* Unit tests for {@link ObjectFactoryCreatingFactoryBean}.
|
||||
*
|
||||
* @author Colin Sampaleanu
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
* @since 2004-05-11
|
||||
*/
|
||||
public final class ObjectFactoryCreatingFactoryBeanTests extends TestCase {
|
||||
public final class ObjectFactoryCreatingFactoryBeanTests {
|
||||
|
||||
private static final Resource CONTEXT =
|
||||
qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml");
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
this.beanFactory = new XmlBeanFactory(new ClassPathResource(
|
||||
"ObjectFactoryCreatingFactoryBeanTests.xml", getClass()));
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.beanFactory = new XmlBeanFactory(CONTEXT);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBasicOperation() throws BeansException {
|
||||
TestBean testBean = (TestBean) beanFactory.getBean("testBean");
|
||||
ObjectFactory objectFactory = testBean.getObjectFactory();
|
||||
ObjectFactory<?> objectFactory = testBean.getObjectFactory();
|
||||
|
||||
Date date1 = (Date) objectFactory.getObject();
|
||||
Date date2 = (Date) objectFactory.getObject();
|
||||
assertTrue(date1 != date2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotComplainWhenTargetBeanNameRefersToSingleton() throws Exception {
|
||||
final String targetBeanName = "singleton";
|
||||
final String expectedSingleton = "Alicia Keys";
|
||||
|
||||
MockControl mock = MockControl.createControl(BeanFactory.class);
|
||||
BeanFactory beanFactory = (BeanFactory) mock.getMock();
|
||||
beanFactory.getBean(targetBeanName);
|
||||
mock.setReturnValue(expectedSingleton);
|
||||
mock.replay();
|
||||
BeanFactory beanFactory = createMock(BeanFactory.class);
|
||||
expect(beanFactory.getBean(targetBeanName)).andReturn(expectedSingleton);
|
||||
replay(beanFactory);
|
||||
|
||||
ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean();
|
||||
factory.setTargetBeanName(targetBeanName);
|
||||
factory.setBeanFactory(beanFactory);
|
||||
factory.afterPropertiesSet();
|
||||
ObjectFactory objectFactory = (ObjectFactory) factory.getObject();
|
||||
ObjectFactory<?> objectFactory = (ObjectFactory<?>) factory.getObject();
|
||||
Object actualSingleton = objectFactory.getObject();
|
||||
assertSame(expectedSingleton, actualSingleton);
|
||||
|
||||
mock.verify();
|
||||
verify(beanFactory);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenTargetBeanNameIsNull() throws Exception {
|
||||
try {
|
||||
new ObjectFactoryCreatingFactoryBean().afterPropertiesSet();
|
||||
|
|
@ -83,6 +90,7 @@ public final class ObjectFactoryCreatingFactoryBeanTests extends TestCase {
|
|||
catch (IllegalArgumentException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenTargetBeanNameIsEmptyString() throws Exception {
|
||||
try {
|
||||
ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean();
|
||||
|
|
@ -93,6 +101,7 @@ public final class ObjectFactoryCreatingFactoryBeanTests extends TestCase {
|
|||
catch (IllegalArgumentException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenTargetBeanNameIsWhitespacedString() throws Exception {
|
||||
try {
|
||||
ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean();
|
||||
|
|
@ -103,6 +112,7 @@ public final class ObjectFactoryCreatingFactoryBeanTests extends TestCase {
|
|||
catch (IllegalArgumentException expected) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() throws Exception {
|
||||
assertEquals("Must be reporting that it creates ObjectFactory instances (as per class contract).",
|
||||
ObjectFactory.class, new ObjectFactoryCreatingFactoryBean().getObjectType());
|
||||
|
|
@ -111,14 +121,14 @@ public final class ObjectFactoryCreatingFactoryBeanTests extends TestCase {
|
|||
|
||||
public static class TestBean {
|
||||
|
||||
public ObjectFactory objectFactory;
|
||||
public ObjectFactory<?> objectFactory;
|
||||
|
||||
|
||||
public ObjectFactory getObjectFactory() {
|
||||
public ObjectFactory<?> getObjectFactory() {
|
||||
return objectFactory;
|
||||
}
|
||||
|
||||
public void setObjectFactory(ObjectFactory objectFactory) {
|
||||
public void setObjectFactory(ObjectFactory<?> objectFactory) {
|
||||
this.objectFactory = objectFactory;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* 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.
|
||||
|
|
@ -16,40 +16,46 @@
|
|||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static test.util.TestResourceUtils.qualifiedResource;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.core.JdkVersion;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PropertiesFactoryBean}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 01.11.2003
|
||||
*/
|
||||
public class PropertiesFactoryBeanTests extends TestCase {
|
||||
public final class PropertiesFactoryBeanTests {
|
||||
|
||||
private static final Class<?> CLASS = PropertiesFactoryBeanTests.class;
|
||||
private static final Resource TEST_PROPS = qualifiedResource(CLASS, "test.properties");
|
||||
private static final Resource TEST_PROPS_XML = qualifiedResource(CLASS, "test.properties.xml");
|
||||
|
||||
@Test
|
||||
public void testWithPropertiesFile() throws Exception {
|
||||
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
|
||||
pfb.setLocation(new ClassPathResource("/org/springframework/beans/factory/config/test.properties"));
|
||||
pfb.setLocation(TEST_PROPS);
|
||||
pfb.afterPropertiesSet();
|
||||
Properties props = (Properties) pfb.getObject();
|
||||
assertEquals("99", props.getProperty("tb.array[0].age"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithPropertiesXmlFile() throws Exception {
|
||||
// ignore for JDK < 1.5
|
||||
if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_15) {
|
||||
return;
|
||||
}
|
||||
|
||||
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
|
||||
pfb.setLocation(new ClassPathResource("/org/springframework/beans/factory/config/test-properties.xml"));
|
||||
pfb.setLocation(TEST_PROPS_XML);
|
||||
pfb.afterPropertiesSet();
|
||||
Properties props = (Properties) pfb.getObject();
|
||||
assertEquals("99", props.getProperty("tb.array[0].age"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithLocalProperties() throws Exception {
|
||||
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
|
||||
Properties localProps = new Properties();
|
||||
|
|
@ -60,9 +66,10 @@ public class PropertiesFactoryBeanTests extends TestCase {
|
|||
assertEquals("value2", props.getProperty("key2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithPropertiesFileAndLocalProperties() throws Exception {
|
||||
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
|
||||
pfb.setLocation(new ClassPathResource("/org/springframework/beans/factory/config/test.properties"));
|
||||
pfb.setLocation(TEST_PROPS);
|
||||
Properties localProps = new Properties();
|
||||
localProps.setProperty("key2", "value2");
|
||||
localProps.setProperty("tb.array[0].age", "0");
|
||||
|
|
@ -73,9 +80,10 @@ public class PropertiesFactoryBeanTests extends TestCase {
|
|||
assertEquals("value2", props.getProperty("key2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithPropertiesFileAndMultipleLocalProperties() throws Exception {
|
||||
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
|
||||
pfb.setLocation(new ClassPathResource("/org/springframework/beans/factory/config/test.properties"));
|
||||
pfb.setLocation(TEST_PROPS);
|
||||
|
||||
Properties props1 = new Properties();
|
||||
props1.setProperty("key2", "value2");
|
||||
|
|
@ -101,9 +109,10 @@ public class PropertiesFactoryBeanTests extends TestCase {
|
|||
assertEquals("man", props.getProperty("bat"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithPropertiesFileAndLocalPropertiesAndLocalOverride() throws Exception {
|
||||
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
|
||||
pfb.setLocation(new ClassPathResource("/org/springframework/beans/factory/config/test.properties"));
|
||||
pfb.setLocation(TEST_PROPS);
|
||||
Properties localProps = new Properties();
|
||||
localProps.setProperty("key2", "value2");
|
||||
localProps.setProperty("tb.array[0].age", "0");
|
||||
|
|
@ -115,10 +124,11 @@ public class PropertiesFactoryBeanTests extends TestCase {
|
|||
assertEquals("value2", props.getProperty("key2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithPrototype() throws Exception {
|
||||
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
|
||||
pfb.setSingleton(false);
|
||||
pfb.setLocation(new ClassPathResource("/org/springframework/beans/factory/config/test.properties"));
|
||||
pfb.setLocation(TEST_PROPS);
|
||||
Properties localProps = new Properties();
|
||||
localProps.setProperty("key2", "value2");
|
||||
pfb.setProperties(localProps);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
|
|
@ -16,22 +16,30 @@
|
|||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
import static test.util.TestResourceUtils.qualifiedResource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import test.beans.ITestBean;
|
||||
import test.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PropertyPathFactoryBean}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 04.10.2004
|
||||
*/
|
||||
public class PropertyPathFactoryBeanTests extends TestCase {
|
||||
public class PropertyPathFactoryBeanTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(PropertyPathFactoryBeanTests.class, "context.xml");
|
||||
|
||||
@Test
|
||||
public void testPropertyPathFactoryBeanWithSingletonResult() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
|
||||
assertEquals(new Integer(12), xbf.getBean("propertyPath1"));
|
||||
assertEquals(new Integer(11), xbf.getBean("propertyPath2"));
|
||||
assertEquals(new Integer(10), xbf.getBean("tb.age"));
|
||||
|
|
@ -43,8 +51,9 @@ public class PropertyPathFactoryBeanTests extends TestCase {
|
|||
assertEquals(99, ((TestBean) result1).getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPathFactoryBeanWithPrototypeResult() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
|
||||
assertNull(xbf.getType("tb.spouse"));
|
||||
assertEquals(TestBean.class, xbf.getType("propertyPath3"));
|
||||
Object result1 = xbf.getBean("tb.spouse");
|
||||
|
|
@ -61,14 +70,16 @@ public class PropertyPathFactoryBeanTests extends TestCase {
|
|||
assertTrue(result2 != result3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPathFactoryBeanWithNullResult() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
|
||||
assertNull(xbf.getType("tb.spouse.spouse"));
|
||||
assertNull(xbf.getBean("tb.spouse.spouse"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyPathFactoryBeanAsInnerBean() {
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("propertyPath.xml", getClass()));
|
||||
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
|
||||
TestBean spouse = (TestBean) xbf.getBean("otb.spouse");
|
||||
TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner");
|
||||
assertSame(spouse, tbWithInner.getSpouse());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
tb.array[0].age=99
|
||||
tb.list[1].name=test
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
|
||||
<properties version="1.0">
|
||||
|
||||
<entry key="tb.array[0].age">99</entry>
|
||||
<entry key="tb.list[1].name">test</entry>
|
||||
|
||||
</properties>
|
||||
|
|
@ -18,6 +18,7 @@ package org.springframework.beans.factory.config;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
|
||||
import static test.util.TestResourceUtils.qualifiedResource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -38,7 +39,6 @@ import org.springframework.beans.factory.support.ManagedList;
|
|||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.support.ManagedSet;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import test.beans.IndexedTestBean;
|
||||
|
|
@ -53,8 +53,13 @@ import test.beans.TestBean;
|
|||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class PropertyResourceConfigurerTests {
|
||||
public final class PropertyResourceConfigurerTests {
|
||||
|
||||
private static final Class<?> CLASS = PropertyResourceConfigurerTests.class;
|
||||
private static final Resource TEST_PROPS = qualifiedResource(CLASS, "test.properties");
|
||||
private static final Resource XTEST_PROPS = qualifiedResource(CLASS, "xtest.properties"); // does not exist
|
||||
private static final Resource TEST_PROPS_XML = qualifiedResource(CLASS, "test.properties.xml");
|
||||
|
||||
private DefaultListableBeanFactory factory;
|
||||
|
||||
@Before
|
||||
|
|
@ -205,7 +210,7 @@ public class PropertyResourceConfigurerTests {
|
|||
factory.registerBeanDefinition("tb", def);
|
||||
|
||||
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
|
||||
poc.setLocation(new ClassPathResource("org/springframework/beans/factory/config/test.properties"));
|
||||
poc.setLocation(TEST_PROPS);
|
||||
poc.postProcessBeanFactory(factory);
|
||||
|
||||
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
|
||||
|
|
@ -221,11 +226,7 @@ public class PropertyResourceConfigurerTests {
|
|||
factory.registerBeanDefinition("tb", def);
|
||||
|
||||
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
|
||||
poc.setLocations(new Resource[] {
|
||||
new ClassPathResource("org/springframework/beans/factory/config/test.properties"),
|
||||
new ClassPathResource("org/springframework/beans/factory/config/xtest.properties")
|
||||
}
|
||||
);
|
||||
poc.setLocations(new Resource[] { TEST_PROPS, XTEST_PROPS });
|
||||
poc.setIgnoreResourceNotFound(true);
|
||||
poc.postProcessBeanFactory(factory);
|
||||
|
||||
|
|
@ -242,7 +243,7 @@ public class PropertyResourceConfigurerTests {
|
|||
factory.registerBeanDefinition("tb", def);
|
||||
|
||||
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
|
||||
poc.setLocation(new ClassPathResource("org/springframework/beans/factory/config/test-properties.xml"));
|
||||
poc.setLocation(TEST_PROPS_XML);
|
||||
poc.postProcessBeanFactory(factory);
|
||||
|
||||
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
|
||||
|
|
|
|||
|
|
@ -31,11 +31,13 @@ import org.springframework.core.NestedCheckedException;
|
|||
import org.springframework.core.NestedRuntimeException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ServiceLocatorFactoryBean}.
|
||||
*
|
||||
* @author Colin Sampaleanu
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class ServiceLocatorFactoryBeanTests {
|
||||
public final class ServiceLocatorFactoryBeanTests {
|
||||
|
||||
private DefaultListableBeanFactory bf;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* 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.
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.beans.factory.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static test.util.TestResourceUtils.qualifiedResource;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
|
@ -26,6 +27,7 @@ import org.junit.Test;
|
|||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import test.beans.TestBean;
|
||||
|
||||
|
|
@ -36,7 +38,9 @@ import test.beans.TestBean;
|
|||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class SimpleScopeTests {
|
||||
public final class SimpleScopeTests {
|
||||
|
||||
private static final Resource CONTEXT = qualifiedResource(SimpleScopeTests.class, "context.xml");
|
||||
|
||||
private DefaultListableBeanFactory beanFactory;
|
||||
|
||||
|
|
@ -65,7 +69,7 @@ public class SimpleScopeTests {
|
|||
assertSame(scope, beanFactory.getRegisteredScope("myScope"));
|
||||
|
||||
XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(beanFactory);
|
||||
xbdr.loadBeanDefinitions("org/springframework/beans/factory/config/simpleScope.xml");
|
||||
xbdr.loadBeanDefinitions(CONTEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -18,10 +18,17 @@ package org.springframework.beans.factory.config;
|
|||
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
|
||||
/**
|
||||
* Shared test types for this package.
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
final class TestTypes {}
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class NoOpScope implements Scope {
|
||||
class NoOpScope implements Scope {
|
||||
|
||||
public Object get(String name, ObjectFactory<?> objectFactory) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
<util:property-path path="configuredBean.name"/>
|
||||
</property>
|
||||
<property name="someProperties">
|
||||
<util:properties location="classpath:/org/springframework/beans/factory/config/util.properties"/>
|
||||
<util:properties location="classpath:/org/springframework/beans/factory/xml/util.properties"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
|
@ -147,35 +147,35 @@
|
|||
</bean>
|
||||
|
||||
<util:properties id="myProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties"/>
|
||||
location="classpath:/org/springframework/beans/factory/xml/util.properties"/>
|
||||
|
||||
<util:properties id="myScopedProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties" scope="prototype"/>
|
||||
location="classpath:/org/springframework/beans/factory/xml/util.properties" scope="prototype"/>
|
||||
|
||||
<util:properties id="myLocalProperties">
|
||||
<prop key="foo2">bar2</prop>
|
||||
</util:properties>
|
||||
|
||||
<util:properties id="myMergedProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties">
|
||||
location="classpath:/org/springframework/beans/factory/xml/util.properties">
|
||||
<prop key="foo2">bar2</prop>
|
||||
</util:properties>
|
||||
|
||||
<util:properties id="defaultLocalOverrideProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties">
|
||||
location="classpath:/org/springframework/beans/factory/xml/util.properties">
|
||||
<prop key="foo">local</prop>
|
||||
<prop key="foo2">local2</prop>
|
||||
</util:properties>
|
||||
|
||||
<util:properties id="trueLocalOverrideProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties"
|
||||
location="classpath:/org/springframework/beans/factory/xml/util.properties"
|
||||
local-override="true">
|
||||
<prop key="foo">local</prop>
|
||||
<prop key="foo2">local2</prop>
|
||||
</util:properties>
|
||||
|
||||
<util:properties id="falseLocalOverrideProperties"
|
||||
location="classpath:/org/springframework/beans/factory/config/util.properties"
|
||||
location="classpath:/org/springframework/beans/factory/xml/util.properties"
|
||||
local-override="false">
|
||||
<prop key="foo">local</prop>
|
||||
<prop key="foo2">local2</prop>
|
||||
|
|
|
|||
Loading…
Reference in New Issue