Sync Servlet mocks between spring-test & spring-web

This commit is contained in:
Sam Brannen
2015-07-19 20:23:51 +02:00
parent 6950d977c2
commit e9f64cf9ae
11 changed files with 217 additions and 79 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.mock.web;
import java.io.IOException;

View File

@@ -53,6 +53,8 @@ import javax.servlet.http.Part;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
/**
@@ -70,6 +72,7 @@ import org.springframework.util.StringUtils;
* @author Mark Fisher
* @author Chris Beams
* @author Sam Brannen
* @author Brian Clozel
* @since 1.0.2
*/
public class MockHttpServletRequest implements HttpServletRequest {
@@ -209,7 +212,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private boolean requestedSessionIdFromURL = false;
private final Map<String, Part> parts = new LinkedHashMap<String, Part>();
private final MultiValueMap<String, Part> parts = new LinkedMultiValueMap<String, Part>();
// ---------------------------------------------------------------------
@@ -1044,8 +1047,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
public StringBuffer getRequestURL() {
StringBuffer url = new StringBuffer(this.scheme).append("://").append(this.serverName);
if (this.serverPort > 0 && ((HTTP.equalsIgnoreCase(this.scheme) && this.serverPort != 80) ||
(HTTPS.equalsIgnoreCase(this.scheme) && this.serverPort != 443))) {
if (this.serverPort > 0
&& ((HTTP.equalsIgnoreCase(this.scheme) && this.serverPort != 80) || (HTTPS.equalsIgnoreCase(this.scheme) && this.serverPort != 443))) {
url.append(':').append(this.serverPort);
}
@@ -1157,17 +1160,21 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
public void addPart(Part part) {
this.parts.put(part.getName(), part);
this.parts.add(part.getName(), part);
}
@Override
public Part getPart(String name) throws IOException, IllegalStateException, ServletException {
return this.parts.get(name);
return this.parts.getFirst(name);
}
@Override
public Collection<Part> getParts() throws IOException, IllegalStateException, ServletException {
return this.parts.values();
List<Part> result = new LinkedList<Part>();
for(List<Part> list : this.parts.values()) {
result.addAll(list);
}
return result;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -45,13 +45,12 @@ import org.springframework.util.Assert;
* applications when testing custom JSP tags.
*
* <p>Note: Expects initialization via the constructor rather than via the
* {@code PageContext.initialize} method. Does not support writing to
* a JspWriter, request dispatching, and {@code handlePageException} calls.
* {@code PageContext.initialize} method. Does not support writing to a
* JspWriter, request dispatching, or {@code handlePageException} calls.
*
* @author Juergen Hoeller
* @since 1.0.2
*/
@SuppressWarnings("deprecation")
public class MockPageContext extends PageContext {
private final ServletContext servletContext;
@@ -287,6 +286,7 @@ public class MockPageContext extends PageContext {
}
@Override
@Deprecated
public javax.servlet.jsp.el.ExpressionEvaluator getExpressionEvaluator() {
return new MockExpressionEvaluator(this);
}
@@ -297,6 +297,7 @@ public class MockPageContext extends PageContext {
}
@Override
@Deprecated
public javax.servlet.jsp.el.VariableResolver getVariableResolver() {
return null;
}