|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -22,6 +22,7 @@ import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
@ -39,12 +40,14 @@ public class ServletServerHttpRequestTests { |
|
|
|
|
|
|
|
|
|
|
|
private MockHttpServletRequest mockRequest; |
|
|
|
private MockHttpServletRequest mockRequest; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
public void create() throws Exception { |
|
|
|
public void create() throws Exception { |
|
|
|
mockRequest = new MockHttpServletRequest(); |
|
|
|
mockRequest = new MockHttpServletRequest(); |
|
|
|
request = new ServletServerHttpRequest(mockRequest); |
|
|
|
request = new ServletServerHttpRequest(mockRequest); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getMethod() throws Exception { |
|
|
|
public void getMethod() throws Exception { |
|
|
|
mockRequest.setMethod("POST"); |
|
|
|
mockRequest.setMethod("POST"); |
|
|
|
@ -65,8 +68,8 @@ public class ServletServerHttpRequestTests { |
|
|
|
public void getHeaders() throws Exception { |
|
|
|
public void getHeaders() throws Exception { |
|
|
|
String headerName = "MyHeader"; |
|
|
|
String headerName = "MyHeader"; |
|
|
|
String headerValue1 = "value1"; |
|
|
|
String headerValue1 = "value1"; |
|
|
|
mockRequest.addHeader(headerName, headerValue1); |
|
|
|
|
|
|
|
String headerValue2 = "value2"; |
|
|
|
String headerValue2 = "value2"; |
|
|
|
|
|
|
|
mockRequest.addHeader(headerName, headerValue1); |
|
|
|
mockRequest.addHeader(headerName, headerValue2); |
|
|
|
mockRequest.addHeader(headerName, headerValue2); |
|
|
|
mockRequest.setContentType("text/plain"); |
|
|
|
mockRequest.setContentType("text/plain"); |
|
|
|
mockRequest.setCharacterEncoding("UTF-8"); |
|
|
|
mockRequest.setCharacterEncoding("UTF-8"); |
|
|
|
@ -82,6 +85,26 @@ public class ServletServerHttpRequestTests { |
|
|
|
headers.getContentType()); |
|
|
|
headers.getContentType()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void getHeadersWithEmptyContentTypeAndEncoding() throws Exception { |
|
|
|
|
|
|
|
String headerName = "MyHeader"; |
|
|
|
|
|
|
|
String headerValue1 = "value1"; |
|
|
|
|
|
|
|
String headerValue2 = "value2"; |
|
|
|
|
|
|
|
mockRequest.addHeader(headerName, headerValue1); |
|
|
|
|
|
|
|
mockRequest.addHeader(headerName, headerValue2); |
|
|
|
|
|
|
|
mockRequest.setContentType(""); |
|
|
|
|
|
|
|
mockRequest.setCharacterEncoding(""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpHeaders headers = request.getHeaders(); |
|
|
|
|
|
|
|
assertNotNull("No HttpHeaders returned", headers); |
|
|
|
|
|
|
|
assertTrue("Invalid headers returned", headers.containsKey(headerName)); |
|
|
|
|
|
|
|
List<String> headerValues = headers.get(headerName); |
|
|
|
|
|
|
|
assertEquals("Invalid header values returned", 2, headerValues.size()); |
|
|
|
|
|
|
|
assertTrue("Invalid header values returned", headerValues.contains(headerValue1)); |
|
|
|
|
|
|
|
assertTrue("Invalid header values returned", headerValues.contains(headerValue2)); |
|
|
|
|
|
|
|
assertNull(headers.getContentType()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getBody() throws Exception { |
|
|
|
public void getBody() throws Exception { |
|
|
|
byte[] content = "Hello World".getBytes("UTF-8"); |
|
|
|
byte[] content = "Hello World".getBytes("UTF-8"); |
|
|
|
@ -105,4 +128,4 @@ public class ServletServerHttpRequestTests { |
|
|
|
assertArrayEquals("Invalid content returned", content, result); |
|
|
|
assertArrayEquals("Invalid content returned", content, result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|