EL container integration; support for contextual objects; removal of deprecated Spring 2.0 functionality; Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-20 02:10:53 +00:00
parent 369821dd66
commit 347f34c68a
281 changed files with 6120 additions and 9903 deletions

View File

@@ -169,7 +169,7 @@ public class BeanUtilsTests extends TestCase {
}
public void testResolveSimpleSignature() throws Exception {
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomething", null);
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomething");
assertSignatureEquals(desiredMethod, "doSomething");
assertSignatureEquals(desiredMethod, "doSomething()");
}
@@ -205,7 +205,7 @@ public class BeanUtilsTests extends TestCase {
public void testResolveOverloadedSignature() throws Exception {
// test resolve with no args
Method desiredMethod = MethodSignatureBean.class.getMethod("overloaded", null);
Method desiredMethod = MethodSignatureBean.class.getMethod("overloaded");
assertSignatureEquals(desiredMethod, "overloaded()");
// resolve with single arg

View File

@@ -35,7 +35,6 @@ import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.commons.logging.LogFactory;
import org.hibernate.FlushMode;
@@ -55,20 +54,6 @@ import org.springframework.util.StringUtils;
*/
public class BeanWrapperTests extends TestCase {
public void testSetWrappedInstanceOfSameClass() throws Exception {
TestBean tb = new TestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
assertTrue(bw.isReadableProperty("age"));
tb.setAge(11);
TestBean tb2 = new TestBean();
bw.setWrappedInstance(tb2);
bw.setPropertyValue("age", new Integer(14));
assertTrue("2nd changed", tb2.getAge() == 14);
assertTrue("1 didn't change", tb.getAge() == 11);
}
public void testIsReadablePropertyNotReadable() {
NoRead nr = new NoRead();
BeanWrapper bw = new BeanWrapperImpl(nr);
@@ -165,17 +150,6 @@ public class BeanWrapperTests extends TestCase {
assertEquals(String.class, bw.getPropertyType("map[key0]"));
}
public void testSetWrappedInstanceOfDifferentClass() {
ThrowsException tex = new ThrowsException();
BeanWrapper bw = new BeanWrapperImpl(tex);
TestBean tb2 = new TestBean();
bw.setWrappedInstance(tb2);
bw.setPropertyValue("age", new Integer(14));
assertTrue("2nd changed", tb2.getAge() == 14);
}
public void testGetterThrowsException() {
GetterBean gb = new GetterBean();
BeanWrapper bw = new BeanWrapperImpl(gb);
@@ -369,11 +343,11 @@ public class BeanWrapperTests extends TestCase {
EnumTester et = new EnumTester();
BeanWrapper bw = new BeanWrapperImpl(et);
bw.setPropertyValue("flushMode", "NEVER");
Assert.assertEquals(FlushMode.NEVER, et.getFlushMode());
bw.setPropertyValue("flushMode", "MANUAL");
assertEquals(FlushMode.MANUAL, et.getFlushMode());
bw.setPropertyValue("flushMode", " AUTO ");
Assert.assertEquals(FlushMode.AUTO, et.getFlushMode());
assertEquals(FlushMode.AUTO, et.getFlushMode());
try {
bw.setPropertyValue("flushMode", "EVER");
@@ -796,36 +770,6 @@ public class BeanWrapperTests extends TestCase {
"Lewisham".equals(kbw.getPropertyValue("spouse.spouse.spouse.spouse.company")));
}
public void testNewWrappedInstancePropertyValuesGet() {
BeanWrapper bw = new BeanWrapperImpl();
TestBean t = new TestBean("Tony", 50);
bw.setWrappedInstance(t);
assertEquals("Bean wrapper returns wrong property value",
new Integer(t.getAge()), bw.getPropertyValue("age"));
TestBean u = new TestBean("Udo", 30);
bw.setWrappedInstance(u);
assertEquals("Bean wrapper returns cached property value",
new Integer(u.getAge()), bw.getPropertyValue("age"));
}
public void testNewWrappedInstanceNestedPropertyValuesGet() {
BeanWrapper bw = new BeanWrapperImpl();
TestBean t = new TestBean("Tony", 50);
t.setSpouse(new TestBean("Sue", 40));
bw.setWrappedInstance(t);
assertEquals("Bean wrapper returns wrong nested property value",
new Integer(t.getSpouse().getAge()), bw.getPropertyValue("spouse.age"));
TestBean u = new TestBean("Udo", 30);
u.setSpouse(new TestBean("Vera", 20));
bw.setWrappedInstance(u);
assertEquals("Bean wrapper returns cached nested property value",
new Integer(u.getSpouse().getAge()), bw.getPropertyValue("spouse.age"));
}
public void testNullObject() {
try {
new BeanWrapperImpl((Object) null);
@@ -1160,7 +1104,7 @@ public class BeanWrapperTests extends TestCase {
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.setPropertyValue("someProperty", "someValue");
assertEquals("someValue", bw.getPropertyValue("someProperty"));
Assert.assertEquals("someValue", bean.getSomeProperty());
assertEquals("someValue", bean.getSomeProperty());
}
public void testErrorMessageOfNestedProperty() {

View File

@@ -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,6 +16,7 @@
package org.springframework.beans.factory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
@@ -28,6 +29,8 @@ import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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;
@@ -59,14 +62,17 @@ public class ConcurrentBeanFactoryTests extends TestCase {
private BeanFactory factory;
private Set set = Collections.synchronizedSet(new HashSet());
private final Set set = Collections.synchronizedSet(new HashSet());
private Throwable ex = null;
protected void setUp() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("concurrent.xml", getClass()));
CustomDateEditor editor = new CustomDateEditor(df, false);
factory.registerCustomEditor(Date.class, editor);
factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Date.class, new CustomDateEditor((DateFormat) df.clone(), false));
}
});
this.factory = factory;
}

View File

@@ -28,6 +28,8 @@ import junit.framework.TestCase;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -39,13 +41,16 @@ import org.springframework.beans.propertyeditors.CustomDateEditor;
*/
public class CustomEditorConfigurerTests extends TestCase {
public void testCustomEditorConfigurerWithRequiredTypeAsClassName() throws ParseException {
public void testCustomEditorConfigurerWithPropertyEditorRegistrar() throws ParseException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CustomEditorConfigurer cec = new CustomEditorConfigurer();
Map editors = new HashMap();
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
editors.put(Date.class.getName(), new CustomDateEditor(df, true));
cec.setCustomEditors(editors);
final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
cec.setPropertyEditorRegistrars(new PropertyEditorRegistrar[] {
new PropertyEditorRegistrar() {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
}
}});
cec.postProcessBeanFactory(bf);
MutablePropertyValues pvs = new MutablePropertyValues();
@@ -61,45 +66,11 @@ public class CustomEditorConfigurerTests extends TestCase {
assertEquals(df.parse("2.12.1975"), tb2.getSomeMap().get("myKey"));
}
public void testCustomEditorConfigurerWithRequiredTypeAsClass() throws ParseException {
public void testCustomEditorConfigurerWithEditorClassName() throws ParseException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CustomEditorConfigurer cec = new CustomEditorConfigurer();
Map editors = new HashMap();
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
editors.put(Date.class, new CustomDateEditor(df, true));
cec.setCustomEditors(editors);
cec.postProcessBeanFactory(bf);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue("date", "2.12.1975");
bf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs));
TestBean tb = (TestBean) bf.getBean("tb");
assertEquals(df.parse("2.12.1975"), tb.getDate());
}
public void testCustomEditorConfigurerWithEditorAsClassName() throws ParseException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CustomEditorConfigurer cec = new CustomEditorConfigurer();
Map editors = new HashMap();
editors.put(Date.class, MyDateEditor.class.getName());
cec.setCustomEditors(editors);
cec.postProcessBeanFactory(bf);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue("date", "2.12.1975");
bf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs));
TestBean tb = (TestBean) bf.getBean("tb");
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
assertEquals(df.parse("2.12.1975"), tb.getDate());
}
public void testCustomEditorConfigurerWithEditorAsClass() throws ParseException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CustomEditorConfigurer cec = new CustomEditorConfigurer();
Map editors = new HashMap();
editors.put(Date.class, MyDateEditor.class);
Map<String, String> editors = new HashMap<String, String>();
editors.put(Date.class.getName(), MyDateEditor.class.getName());
cec.setCustomEditors(editors);
cec.postProcessBeanFactory(bf);
@@ -115,12 +86,8 @@ public class CustomEditorConfigurerTests extends TestCase {
public void testCustomEditorConfigurerWithRequiredTypeArray() throws ParseException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CustomEditorConfigurer cec = new CustomEditorConfigurer();
Map editors = new HashMap();
editors.put("java.lang.String[]", new PropertyEditorSupport() {
public void setAsText(String text) {
setValue(new String[] {"test"});
}
});
Map<String, String> editors = new HashMap<String, String>();
editors.put("java.lang.String[]", MyTestEditor.class.getName());
cec.setCustomEditors(editors);
cec.postProcessBeanFactory(bf);
@@ -136,8 +103,8 @@ public class CustomEditorConfigurerTests extends TestCase {
public void testCustomEditorConfigurerWithUnresolvableEditor() throws ParseException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CustomEditorConfigurer cec = new CustomEditorConfigurer();
Map editors = new HashMap();
editors.put(Date.class, "MyNonExistingEditor");
Map<String, String> editors = new HashMap<String, String>();
editors.put(Date.class.getName(), "MyNonExistingEditor");
editors.put("MyNonExistingType", "MyNonExistingEditor");
cec.setCustomEditors(editors);
try {
@@ -152,8 +119,8 @@ public class CustomEditorConfigurerTests extends TestCase {
public void testCustomEditorConfigurerWithIgnoredUnresolvableEditor() throws ParseException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CustomEditorConfigurer cec = new CustomEditorConfigurer();
Map editors = new HashMap();
editors.put(Date.class, "MyNonExistingEditor");
Map<String, String> editors = new HashMap<String, String>();
editors.put(Date.class.getName(), "MyNonExistingEditor");
editors.put("MyNonExistingType", "MyNonExistingEditor");
cec.setCustomEditors(editors);
cec.setIgnoreUnresolvableEditors(true);
@@ -168,4 +135,12 @@ public class CustomEditorConfigurerTests extends TestCase {
}
}
public static class MyTestEditor extends PropertyEditorSupport {
public void setAsText(String text) {
setValue(new String[] {"test"});
}
}
}