@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2019 the original author or authors .
* Copyright 2002 - 202 1 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,20 +45,20 @@ public class ServletServerHttpRequestTests {
@@ -45,20 +45,20 @@ public class ServletServerHttpRequestTests {
@BeforeEach
public void create ( ) {
void create ( ) {
mockRequest = new MockHttpServletRequest ( ) ;
request = new ServletServerHttpRequest ( mockRequest ) ;
}
@Test
public void getMethod ( ) {
void getMethod ( ) {
mockRequest . setMethod ( "POST" ) ;
assertThat ( request . getMethod ( ) ) . as ( "Invalid method" ) . isEqualTo ( HttpMethod . POST ) ;
}
@Test
public void getUriForSimplePath ( ) throws URISyntaxException {
void getUriForSimplePath ( ) throws URISyntaxException {
URI uri = new URI ( "https://example.com/path" ) ;
mockRequest . setScheme ( uri . getScheme ( ) ) ;
mockRequest . setServerName ( uri . getHost ( ) ) ;
@ -69,7 +69,7 @@ public class ServletServerHttpRequestTests {
@@ -69,7 +69,7 @@ public class ServletServerHttpRequestTests {
}
@Test
public void getUriWithQueryString ( ) throws URISyntaxException {
void getUriWithQueryString ( ) throws URISyntaxException {
URI uri = new URI ( "https://example.com/path?query" ) ;
mockRequest . setScheme ( uri . getScheme ( ) ) ;
mockRequest . setServerName ( uri . getHost ( ) ) ;
@ -80,7 +80,7 @@ public class ServletServerHttpRequestTests {
@@ -80,7 +80,7 @@ public class ServletServerHttpRequestTests {
}
@Test // SPR-16414
public void getUriWithQueryParam ( ) throws URISyntaxException {
void getUriWithQueryParam ( ) throws URISyntaxException {
mockRequest . setScheme ( "https" ) ;
mockRequest . setServerPort ( 443 ) ;
mockRequest . setServerName ( "example.com" ) ;
@ -90,7 +90,7 @@ public class ServletServerHttpRequestTests {
@@ -90,7 +90,7 @@ public class ServletServerHttpRequestTests {
}
@Test // SPR-16414
public void getUriWithMalformedQueryParam ( ) throws URISyntaxException {
void getUriWithMalformedQueryParam ( ) throws URISyntaxException {
mockRequest . setScheme ( "https" ) ;
mockRequest . setServerPort ( 443 ) ;
mockRequest . setServerName ( "example.com" ) ;
@ -100,7 +100,7 @@ public class ServletServerHttpRequestTests {
@@ -100,7 +100,7 @@ public class ServletServerHttpRequestTests {
}
@Test // SPR-13876
public void getUriWithEncoding ( ) throws URISyntaxException {
void getUriWithEncoding ( ) throws URISyntaxException {
URI uri = new URI ( "https://example.com/%E4%B8%AD%E6%96%87" +
"?redirect=https%3A%2F%2Fgithub.com%2Fspring-projects%2Fspring-framework" ) ;
mockRequest . setScheme ( uri . getScheme ( ) ) ;
@ -112,7 +112,7 @@ public class ServletServerHttpRequestTests {
@@ -112,7 +112,7 @@ public class ServletServerHttpRequestTests {
}
@Test
public void getHeaders ( ) {
void getHeaders ( ) {
String headerName = "MyHeader" ;
String headerValue1 = "value1" ;
String headerValue2 = "value2" ;
@ -132,7 +132,7 @@ public class ServletServerHttpRequestTests {
@@ -132,7 +132,7 @@ public class ServletServerHttpRequestTests {
}
@Test
public void getHeadersWithEmptyContentTypeAndEncoding ( ) {
void getHeadersWithEmptyContentTypeAndEncoding ( ) {
String headerName = "MyHeader" ;
String headerValue1 = "value1" ;
String headerValue2 = "value2" ;
@ -152,8 +152,8 @@ public class ServletServerHttpRequestTests {
@@ -152,8 +152,8 @@ public class ServletServerHttpRequestTests {
}
@Test
public void getBody ( ) throws IOException {
byte [ ] content = "Hello World" . getBytes ( "UTF-8" ) ;
void getBody ( ) throws IOException {
byte [ ] content = "Hello World" . getBytes ( StandardCharsets . UTF_8 ) ;
mockRequest . setContent ( content ) ;
byte [ ] result = FileCopyUtils . copyToByteArray ( request . getBody ( ) ) ;
@ -161,16 +161,17 @@ public class ServletServerHttpRequestTests {
@@ -161,16 +161,17 @@ public class ServletServerHttpRequestTests {
}
@Test
public void getFormBody ( ) throws IOException {
void getFormBody ( ) throws IOException {
// Charset (SPR-8676)
mockRequest . setContentType ( "application/x-www-form-urlencoded; charset=UTF-8" ) ;
mockRequest . setMethod ( "POST" ) ;
mockRequest . addParameter ( "name 1" , "value 1" ) ;
mockRequest . addParameter ( "name 2" , new String [ ] { "value 2+1" , "value 2+2" } ) ;
mockRequest . addParameter ( "name 2" , "value 2+1" , "value 2+2" ) ;
mockRequest . addParameter ( "name 3" , ( String ) null ) ;
byte [ ] result = FileCopyUtils . copyToByteArray ( request . getBody ( ) ) ;
byte [ ] content = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3" . getBytes ( "UTF-8" ) ;
byte [ ] content = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3" . getBytes (
StandardCharsets . UTF_8 ) ;
assertThat ( result ) . as ( "Invalid content returned" ) . isEqualTo ( content ) ;
}