MockHttpServletRequest exposes "HTTP/1.1" as default protocol
Issue: SPR-15232
(cherry picked from commit ed85337)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -27,7 +27,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -54,11 +53,21 @@ public class MockHttpServletRequestTests {
|
||||
|
||||
private static final String IF_MODIFIED_SINCE = "If-Modified-Since";
|
||||
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
private final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
|
||||
@Test
|
||||
public void content() throws IOException {
|
||||
public void protocolAndScheme() {
|
||||
assertEquals(MockHttpServletRequest.DEFAULT_PROTOCOL, request.getProtocol());
|
||||
assertEquals(MockHttpServletRequest.DEFAULT_SCHEME, request.getScheme());
|
||||
request.setProtocol("HTTP/2.0");
|
||||
request.setScheme("https");
|
||||
assertEquals("HTTP/2.0", request.getProtocol());
|
||||
assertEquals("https", request.getScheme());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContentAndGetInputStream() throws IOException {
|
||||
byte[] bytes = "body".getBytes(Charset.defaultCharset());
|
||||
request.setContent(bytes);
|
||||
assertEquals(bytes.length, request.getContentLength());
|
||||
@@ -109,9 +118,7 @@ public class MockHttpServletRequestTests {
|
||||
assertEquals("UTF-8", request.getCharacterEncoding());
|
||||
}
|
||||
|
||||
// SPR-12677
|
||||
|
||||
@Test
|
||||
@Test // SPR-12677
|
||||
public void setContentTypeHeaderWithMoreComplexCharsetSyntax() {
|
||||
String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";
|
||||
request.addHeader("Content-Type", contentType);
|
||||
@@ -157,7 +164,7 @@ public class MockHttpServletRequestTests {
|
||||
public void setMultipleParameters() {
|
||||
request.setParameter("key1", "value1");
|
||||
request.setParameter("key2", "value2");
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
Map<String, Object> params = new HashMap<>(2);
|
||||
params.put("key1", "newValue1");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.setParameters(params);
|
||||
@@ -175,7 +182,7 @@ public class MockHttpServletRequestTests {
|
||||
public void addMultipleParameters() {
|
||||
request.setParameter("key1", "value1");
|
||||
request.setParameter("key2", "value2");
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
Map<String, Object> params = new HashMap<>(2);
|
||||
params.put("key1", "newValue1");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.addParameters(params);
|
||||
@@ -193,7 +200,7 @@ public class MockHttpServletRequestTests {
|
||||
@Test
|
||||
public void removeAllParameters() {
|
||||
request.setParameter("key1", "value1");
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
Map<String, Object> params = new HashMap<>(2);
|
||||
params.put("key2", "value2");
|
||||
params.put("key3", new String[] { "value3A", "value3B" });
|
||||
request.addParameters(params);
|
||||
@@ -245,7 +252,7 @@ public class MockHttpServletRequestTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void setPreferredLocalesWithEmptyList() {
|
||||
request.setPreferredLocales(new ArrayList<Locale>());
|
||||
request.setPreferredLocales(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user