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

@@ -48,6 +48,8 @@ import org.springframework.beans.PropertyValue;
import org.springframework.beans.TestBean;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.TypeMismatchException;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor;
@@ -775,8 +777,12 @@ public class DefaultListableBeanFactoryTests extends TestCase {
public void testCustomEditor() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
lbf.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
public void registerCustomEditors(PropertyEditorRegistry registry) {
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
}
});
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue("myFloat", "1,1");
lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, pvs));
@@ -786,8 +792,12 @@ public class DefaultListableBeanFactoryTests extends TestCase {
public void testCustomEditorWithBeanReference() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
lbf.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
public void registerCustomEditors(PropertyEditorRegistry registry) {
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
}
});
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue("myFloat", new RuntimeBeanReference("myFloat"));
lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, pvs));

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.
@@ -34,6 +34,10 @@ public class NoOpScope implements Scope {
public void registerDestructionCallback(String name, Runnable callback) {
}
public Object resolveContextualObject(String key) {
return null;
}
public String getConversationId() {
return null;
}

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.
@@ -64,6 +64,10 @@ public class SimpleMapScope implements Scope, Serializable {
this.callbacks.add(callback);
}
public Object resolveContextualObject(String key) {
return null;
}
public void close() {
for (Iterator it = this.callbacks.iterator(); it.hasNext();) {
Runnable runnable = (Runnable) it.next();

View File

@@ -32,6 +32,8 @@ import junit.framework.TestCase;
import org.springframework.beans.GenericBean;
import org.springframework.beans.GenericIntegerBean;
import org.springframework.beans.GenericSetOfIntegerBean;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.core.io.ClassPathResource;
@@ -341,7 +343,11 @@ public class BeanFactoryGenericsTests extends TestCase {
public void testGenericMapWithCollectionValueConstructor() throws MalformedURLException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
}
});
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
Map input = new HashMap();
@@ -486,7 +492,11 @@ public class BeanFactoryGenericsTests extends TestCase {
public void testGenericMapWithCollectionValueFactoryMethod() throws MalformedURLException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
}
});
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setFactoryMethodName("createInstance");

View File

@@ -1,94 +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.jmx.access;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jmx.AbstractJmxTests;
import org.springframework.jmx.IJmxTestBean;
import org.springframework.jmx.support.ObjectNameManager;
/**
* Tests creation of JMX MBean proxies.
*
* @author Rob Harrop
*/
public class CommonsAttributesMBeanProxyFactoryBeanTests extends AbstractJmxTests {
private static final String OBJECT_NAME = "bean:name=testBean1";
protected ObjectName getObjectName() throws Exception {
return ObjectNameManager.getInstance(OBJECT_NAME);
}
public void testProxyFactory() throws Exception {
MBeanProxyFactoryBean fb = getProxyFactory();
fb.setProxyInterface(IJmxTestBean.class);
fb.afterPropertiesSet();
IJmxTestBean bean = (IJmxTestBean) fb.getObject();
assertNotNull("Proxy should not be null", bean);
}
public void testInvalidJdkProxy() throws Exception {
MBeanProxyFactoryBean fb = getProxyFactory();
try {
fb.afterPropertiesSet();
fail("Should not be able to create JDK proxy with no proxy interfaces");
}
catch (Exception ex) {
// expected
}
}
public void testWithLocatedMBeanServer() throws Exception {
MBeanProxyFactoryBean fb = new MBeanProxyFactoryBean();
fb.setProxyInterface(IJmxTestBean.class);
fb.setObjectName(OBJECT_NAME);
fb.afterPropertiesSet();
IJmxTestBean proxy = (IJmxTestBean)fb.getObject();
assertNotNull("Proxy should not be null", proxy);
assertEquals("Incorrect name value", "TEST", proxy.getName());
}
public void testProxyFactoryBeanWithAutodetect() throws Exception {
try {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryBean.xml", getClass()));
bf.preInstantiateSingletons();
}
catch (BeanCreationException ex) {
if (ex.getCause().getClass() == MBeanInfoRetrievalException.class) {
fail("MBeanProxyFactoryBean should be ignored by MBeanExporter when running autodetect process");
}
else {
throw ex;
}
}
}
private MBeanProxyFactoryBean getProxyFactory() throws MalformedObjectNameException {
MBeanProxyFactoryBean fb = new MBeanProxyFactoryBean();
fb.setServer(getServer());
fb.setObjectName(OBJECT_NAME);
return fb;
}
}

View File

@@ -1,45 +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="jmxAdapter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=proxyTestBean1">
<ref local="testBean"/>
</entry>
</map>
</property>
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
<property name="attributeSource">
<bean class="org.springframework.jmx.export.metadata.AttributesJmxAttributeSource">
<property name="attributes">
<bean class="org.springframework.metadata.commons.CommonsAttributes"/>
</property>
</bean>
</property>
</bean>
</property>
</bean>
<bean id="proxyBean" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
<property name="proxyInterface">
<value>org.springframework.jmx.IJmxTestBean</value>
</property>
<property name="objectName">
<value>bean:name=proxyTestBean1</value>
</property>
</bean>
<bean id="testBean" class="org.springframework.jmx.JmxTestBean">
<property name="name">
<value>TEST</value>
</property>
<property name="age">
<value>100</value>
</property>
</bean>
</beans>

View File

@@ -21,7 +21,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.management.Attribute;
import javax.management.InstanceNotFoundException;
import javax.management.JMException;

View File

@@ -1,140 +0,0 @@
/*
* Copyright 2002-2007 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.test.context.junit4;
import static org.junit.Assert.assertEquals;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.internal.runners.TestClass;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Timed;
import org.springframework.test.context.TestContextManager;
/**
* Unit test for {@link SpringMethodRoadie} which focuses on proper support of
* the {@link Repeat @Repeat} annotation.
*
* @author Sam Brannen
* @since 2.5
*/
@RunWith(Parameterized.class)
public class RepeatedSpringMethodRoadieTests {
protected final String methodName;
protected final int expectedNumInvocations;
protected final MockControl notifierMockControl = MockClassControl.createNiceControl(RunNotifier.class);
protected final RunNotifier notifier = (RunNotifier) this.notifierMockControl.getMock();
protected final MockControl descriptionMockControl = MockClassControl.createNiceControl(Description.class);
protected final Description description = (Description) this.descriptionMockControl.getMock();
protected final MockControl testContextManagerMockControl = MockClassControl.createNiceControl(TestContextManager.class);
protected final TestContextManager testContextManager = (TestContextManager) this.testContextManagerMockControl.getMock();
public RepeatedSpringMethodRoadieTests(final String methodName, final int expectedNumInvocations) throws Exception {
this.methodName = methodName;
this.expectedNumInvocations = expectedNumInvocations;
}
@Parameters
public static Collection<Object[]> repetitionData() {
return Arrays.asList(new Object[][] { { "testNonAnnotated", 1 }, { "testNegativeRepeatValue", 1 },
{ "testDefaultRepeatValue", 1 }, { "testRepeatedFiveTimes", 5 } });
}
@Test
public void assertRepetitions() throws Exception {
final Class<RepeatedTestCase> clazz = RepeatedTestCase.class;
final TestClass testClass = new TestClass(clazz);
final RepeatedTestCase testInstance = clazz.newInstance();
final Method method = clazz.getMethod(this.methodName, (Class[]) null);
final SpringTestMethod testMethod = new SpringTestMethod(method, testClass);
new SpringMethodRoadie(this.testContextManager, testInstance, testMethod, this.notifier, this.description).run();
assertEquals("Verifying number of @Test invocations for test method [" + this.methodName + "].",
this.expectedNumInvocations, testInstance.invocationCount);
assertEquals("Verifying number of @Before invocations for test method [" + this.methodName + "].",
this.expectedNumInvocations, testInstance.beforeCount);
assertEquals("Verifying number of @After invocations for test method [" + this.methodName + "].",
this.expectedNumInvocations, testInstance.afterCount);
}
protected static class RepeatedTestCase {
int beforeCount = 0;
int afterCount = 0;
int invocationCount = 0;
@Before
protected void setUp() throws Exception {
this.beforeCount++;
}
@After
protected void tearDown() throws Exception {
this.afterCount++;
}
@Test
@Timed(millis = 10000)
public void testNonAnnotated() {
this.invocationCount++;
}
@Test
@Repeat(-5)
@Timed(millis = 10000)
public void testNegativeRepeatValue() {
this.invocationCount++;
}
@Test
@Repeat
@Timed(millis = 10000)
public void testDefaultRepeatValue() {
this.invocationCount++;
}
@Test
@Repeat(5)
@Timed(millis = 10000)
public void testRepeatedFiveTimes() {
this.invocationCount++;
}
}
}

View File

@@ -49,8 +49,6 @@ StandardJUnit4FeaturesTests.class,
StandardJUnit4FeaturesSpringRunnerTests.class,
RepeatedSpringMethodRoadieTests.class,
EnabledAndIgnoredSpringRunnerTests.class,
HardCodedProfileValueSourceSpringRunnerTests.class,

View File

@@ -1,413 +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.web.bind;
import javax.servlet.ServletException;
import junit.framework.TestCase;
import org.springframework.mock.web.MockHttpServletRequest;
/**
* @author Juergen Hoeller
* @since 06.08.2003
*/
public class RequestUtilsTests extends TestCase {
public void testRejectMethod() throws ServletRequestBindingException {
String methodGet = "GET";
String methodPost = "POST";
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod(methodPost);
try {
RequestUtils.rejectRequestMethod(request, methodGet);
} catch (ServletException ex) {
fail("Shouldn't have thrown ServletException");
}
try {
RequestUtils.rejectRequestMethod(request, methodPost);
fail("Should have thrown ServletException");
} catch (ServletException ex) {
}
}
public void testIntParameter() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param1", "5");
request.addParameter("param2", "e");
request.addParameter("paramEmpty", "");
assertEquals(RequestUtils.getIntParameter(request, "param1"), new Integer(5));
assertEquals(RequestUtils.getIntParameter(request, "param1", 6), 5);
assertEquals(RequestUtils.getRequiredIntParameter(request, "param1"), 5);
assertEquals(RequestUtils.getIntParameter(request, "param2", 6), 6);
try {
RequestUtils.getRequiredIntParameter(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
assertEquals(RequestUtils.getIntParameter(request, "param3"), null);
assertEquals(RequestUtils.getIntParameter(request, "param3", 6), 6);
try {
RequestUtils.getRequiredIntParameter(request, "param3");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
try {
RequestUtils.getRequiredIntParameter(request, "paramEmpty");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testIntParameters() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param", new String[] {"1", "2", "3"});
request.addParameter("param2", "1");
request.addParameter("param2", "2");
request.addParameter("param2", "bogus");
int[] array = new int[] { 1, 2, 3 };
int[] values = RequestUtils.getRequiredIntParameters(request, "param");
assertEquals(3, values.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], values[i]);
}
try {
RequestUtils.getRequiredIntParameters(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testLongParameter() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param1", "5");
request.addParameter("param2", "e");
request.addParameter("paramEmpty", "");
assertEquals(RequestUtils.getLongParameter(request, "param1"), new Long(5L));
assertEquals(RequestUtils.getLongParameter(request, "param1", 6L), 5L);
assertEquals(RequestUtils.getRequiredIntParameter(request, "param1"), 5L);
assertEquals(RequestUtils.getLongParameter(request, "param2", 6L), 6L);
try {
RequestUtils.getRequiredLongParameter(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
assertEquals(RequestUtils.getLongParameter(request, "param3"), null);
assertEquals(RequestUtils.getLongParameter(request, "param3", 6L), 6L);
try {
RequestUtils.getRequiredLongParameter(request, "param3");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
try {
RequestUtils.getRequiredLongParameter(request, "paramEmpty");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testLongParameters() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("param", new String[] {"1", "2", "3"});
request.setParameter("param2", "0");
request.setParameter("param2", "1");
request.addParameter("param2", "2");
request.addParameter("param2", "bogus");
long[] array = new long[] { 1L, 2L, 3L };
long[] values = RequestUtils.getRequiredLongParameters(request, "param");
assertEquals(3, values.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], values[i]);
}
try {
RequestUtils.getRequiredLongParameters(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
request.setParameter("param2", new String[] {"1", "2"});
values = RequestUtils.getRequiredLongParameters(request, "param2");
assertEquals(2, values.length);
assertEquals(1, values[0]);
assertEquals(2, values[1]);
request.removeParameter("param2");
try {
RequestUtils.getRequiredLongParameters(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testFloatParameter() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param1", "5.5");
request.addParameter("param2", "e");
request.addParameter("paramEmpty", "");
assertTrue(RequestUtils.getFloatParameter(request, "param1").equals(new Float(5.5f)));
assertTrue(RequestUtils.getFloatParameter(request, "param1", 6.5f) == 5.5f);
assertTrue(RequestUtils.getRequiredFloatParameter(request, "param1") == 5.5f);
assertTrue(RequestUtils.getFloatParameter(request, "param2", 6.5f) == 6.5f);
try {
RequestUtils.getRequiredFloatParameter(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
assertTrue(RequestUtils.getFloatParameter(request, "param3") == null);
assertTrue(RequestUtils.getFloatParameter(request, "param3", 6.5f) == 6.5f);
try {
RequestUtils.getRequiredFloatParameter(request, "param3");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
try {
RequestUtils.getRequiredFloatParameter(request, "paramEmpty");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testFloatParameters() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param", new String[] {"1.5", "2.5", "3"});
request.addParameter("param2", "1.5");
request.addParameter("param2", "2");
request.addParameter("param2", "bogus");
float[] array = new float[] { 1.5F, 2.5F, 3 };
float[] values = RequestUtils.getRequiredFloatParameters(request, "param");
assertEquals(3, values.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], values[i], 0);
}
try {
RequestUtils.getRequiredFloatParameters(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testDoubleParameter() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param1", "5.5");
request.addParameter("param2", "e");
request.addParameter("paramEmpty", "");
assertTrue(RequestUtils.getDoubleParameter(request, "param1").equals(new Double(5.5)));
assertTrue(RequestUtils.getDoubleParameter(request, "param1", 6.5) == 5.5);
assertTrue(RequestUtils.getRequiredDoubleParameter(request, "param1") == 5.5);
assertTrue(RequestUtils.getDoubleParameter(request, "param2", 6.5) == 6.5);
try {
RequestUtils.getRequiredDoubleParameter(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
assertTrue(RequestUtils.getDoubleParameter(request, "param3") == null);
assertTrue(RequestUtils.getDoubleParameter(request, "param3", 6.5) == 6.5);
try {
RequestUtils.getRequiredDoubleParameter(request, "param3");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
try {
RequestUtils.getRequiredDoubleParameter(request, "paramEmpty");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testDoubleParameters() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param", new String[] {"1.5", "2.5", "3"});
request.addParameter("param2", "1.5");
request.addParameter("param2", "2");
request.addParameter("param2", "bogus");
double[] array = new double[] { 1.5, 2.5, 3 };
double[] values = RequestUtils.getRequiredDoubleParameters(request, "param");
assertEquals(3, values.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], values[i], 0);
}
try {
RequestUtils.getRequiredDoubleParameters(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testBooleanParameter() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param1", "true");
request.addParameter("param2", "e");
request.addParameter("param4", "yes");
request.addParameter("param5", "1");
request.addParameter("paramEmpty", "");
assertTrue(RequestUtils.getBooleanParameter(request, "param1").equals(Boolean.TRUE));
assertTrue(RequestUtils.getBooleanParameter(request, "param1", false));
assertTrue(RequestUtils.getRequiredBooleanParameter(request, "param1"));
assertFalse(RequestUtils.getBooleanParameter(request, "param2", true));
assertFalse(RequestUtils.getRequiredBooleanParameter(request, "param2"));
assertTrue(RequestUtils.getBooleanParameter(request, "param3") == null);
assertTrue(RequestUtils.getBooleanParameter(request, "param3", true));
try {
RequestUtils.getRequiredBooleanParameter(request, "param3");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
assertTrue(RequestUtils.getBooleanParameter(request, "param4", false));
assertTrue(RequestUtils.getRequiredBooleanParameter(request, "param4"));
assertTrue(RequestUtils.getBooleanParameter(request, "param5", false));
assertTrue(RequestUtils.getRequiredBooleanParameter(request, "param5"));
try {
RequestUtils.getRequiredBooleanParameter(request, "paramEmpty");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testBooleanParameters() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param", new String[] {"true", "yes", "off", "1", "bogus"});
request.addParameter("param2", "false");
request.addParameter("param2", "true");
request.addParameter("param2", "");
boolean[] array = new boolean[] { true, true, false, true, false };
boolean[] values = RequestUtils.getRequiredBooleanParameters(request, "param");
assertEquals(5, values.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], values[i]);
}
try {
RequestUtils.getRequiredBooleanParameters(request, "param2");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
public void testStringParameter() throws ServletRequestBindingException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("param1", "str");
request.addParameter("paramEmpty", "");
assertEquals(RequestUtils.getStringParameter(request, "param1"), "str");
assertEquals(RequestUtils.getStringParameter(request, "param1", "string"), "str");
assertEquals(RequestUtils.getRequiredStringParameter(request, "param1"), "str");
assertEquals(RequestUtils.getStringParameter(request, "param3"), null);
assertEquals(RequestUtils.getStringParameter(request, "param3", "string"), "string");
try {
RequestUtils.getRequiredStringParameter(request, "param3");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
try {
RequestUtils.getStringParameter(request, "paramEmpty");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
try {
RequestUtils.getRequiredStringParameter(request, "paramEmpty");
fail("Should have thrown ServletRequestBindingException");
}
catch (ServletRequestBindingException ex) {
// expected
}
}
}

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.
@@ -103,24 +103,6 @@ public class ContextLoaderTests extends TestCase {
assertEquals("customizeContext() should have been called.", expectedContents, buffer.toString());
}
public void testContextLoaderServletWithDefaultContext() throws Exception {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
"/org/springframework/web/context/WEB-INF/applicationContext.xml");
HttpServlet servlet = new ContextLoaderServlet();
ServletConfig config = new MockServletConfig(sc, "test");
servlet.init(config);
WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
assertTrue("Correct WebApplicationContext exposed in ServletContext",
context instanceof XmlWebApplicationContext);
LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
assertTrue("Not destroyed", !lb.isDestroyed());
assertFalse(context.containsBean("beans1.bean1"));
assertFalse(context.containsBean("beans1.bean2"));
servlet.destroy();
assertTrue("Destroyed", lb.isDestroyed());
}
public void testContextLoaderWithDefaultContextAndParent() throws Exception {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,

View File

@@ -35,7 +35,6 @@ import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.mvc.LastModified;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.mvc.throwaway.ThrowawayController;
import org.springframework.web.servlet.support.RequestContextUtils;
import org.springframework.web.servlet.theme.AbstractThemeResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@@ -56,8 +55,6 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
registerSingleton("/locale.do", LocaleChecker.class);
registerPrototype("/throwaway.do", TestThrowawayController.class);
addMessage("test", Locale.ENGLISH, "test message");
addMessage("test", Locale.CANADA, "Canadian & test message");
addMessage("testArgs", Locale.ENGLISH, "test {0} message {1}");
@@ -118,24 +115,4 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
}
}
public static class TestThrowawayController implements ThrowawayController {
public static int counter = 0;
private int myInt;
public TestThrowawayController() {
counter++;
}
public void setMyInt(int myInt) {
this.myInt = myInt;
}
public ModelAndView execute() throws Exception {
return new ModelAndView("view" + this.myInt);
}
}
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2002-2005 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.
* 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.
@@ -118,21 +118,4 @@ public class Log4jWebConfigurerTests extends TestCase {
assertTrue(MockLog4jAppender.closeCalled);
}
public void testLog4jConfigServlet() throws ServletException {
Log4jConfigServlet servlet = new Log4jConfigServlet();
MockServletContext sc = new MockServletContext("", new FileSystemResourceLoader());
sc.addInitParameter(Log4jWebConfigurer.CONFIG_LOCATION_PARAM,
"test/org/springframework/util/testlog4j.properties");
servlet.init(new MockServletConfig(sc));
try {
doTestLogOutput();
}
finally {
servlet.destroy();
}
assertTrue(MockLog4jAppender.closeCalled);
}
}