Suppress warnings, remove unused code, etc.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -32,13 +32,14 @@ import static org.springframework.http.ContentDisposition.builder;
|
||||
* @author Sebastien Deleuze
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ContentDispositionTests {
|
||||
class ContentDispositionTests {
|
||||
|
||||
private static DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME;
|
||||
|
||||
|
||||
@Test
|
||||
public void parse() {
|
||||
@SuppressWarnings("deprecation")
|
||||
void parse() {
|
||||
assertThat(parse("form-data; name=\"foo\"; filename=\"foo.txt\"; size=123"))
|
||||
.isEqualTo(builder("form-data")
|
||||
.name("foo")
|
||||
@@ -48,7 +49,7 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFilenameUnquoted() {
|
||||
void parseFilenameUnquoted() {
|
||||
assertThat(parse("form-data; filename=unquoted"))
|
||||
.isEqualTo(builder("form-data")
|
||||
.filename("unquoted")
|
||||
@@ -56,7 +57,7 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test // SPR-16091
|
||||
public void parseFilenameWithSemicolon() {
|
||||
void parseFilenameWithSemicolon() {
|
||||
assertThat(parse("attachment; filename=\"filename with ; semicolon.txt\""))
|
||||
.isEqualTo(builder("attachment")
|
||||
.filename("filename with ; semicolon.txt")
|
||||
@@ -64,7 +65,7 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEncodedFilename() {
|
||||
void parseEncodedFilename() {
|
||||
assertThat(parse("form-data; name=\"name\"; filename*=UTF-8''%E4%B8%AD%E6%96%87.txt"))
|
||||
.isEqualTo(builder("form-data")
|
||||
.name("name")
|
||||
@@ -73,7 +74,7 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test // gh-24112
|
||||
public void parseEncodedFilenameWithPaddedCharset() {
|
||||
void parseEncodedFilenameWithPaddedCharset() {
|
||||
assertThat(parse("attachment; filename*= UTF-8''some-file.zip"))
|
||||
.isEqualTo(builder("attachment")
|
||||
.filename("some-file.zip", StandardCharsets.UTF_8)
|
||||
@@ -81,7 +82,7 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEncodedFilenameWithoutCharset() {
|
||||
void parseEncodedFilenameWithoutCharset() {
|
||||
assertThat(parse("form-data; name=\"name\"; filename*=test.txt"))
|
||||
.isEqualTo(builder("form-data")
|
||||
.name("name")
|
||||
@@ -90,13 +91,13 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEncodedFilenameWithInvalidCharset() {
|
||||
void parseEncodedFilenameWithInvalidCharset() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> parse("form-data; name=\"name\"; filename*=UTF-16''test.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEncodedFilenameWithInvalidName() {
|
||||
void parseEncodedFilenameWithInvalidName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> parse("form-data; name=\"name\"; filename*=UTF-8''%A"));
|
||||
|
||||
@@ -105,8 +106,8 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test // gh-23077
|
||||
public void parseWithEscapedQuote() {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
void parseWithEscapedQuote() {
|
||||
BiConsumer<String, String> tester = (description, filename) ->
|
||||
assertThat(parse("form-data; name=\"file\"; filename=\"" + filename + "\"; size=123"))
|
||||
.as(description)
|
||||
@@ -126,7 +127,8 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithExtraSemicolons() {
|
||||
@SuppressWarnings("deprecation")
|
||||
void parseWithExtraSemicolons() {
|
||||
assertThat(parse("form-data; name=\"foo\";; ; filename=\"foo.txt\"; size=123"))
|
||||
.isEqualTo(builder("form-data")
|
||||
.name("foo")
|
||||
@@ -136,7 +138,8 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseDates() {
|
||||
@SuppressWarnings("deprecation")
|
||||
void parseDates() {
|
||||
ZonedDateTime creationTime = ZonedDateTime.parse("Mon, 12 Feb 2007 10:15:30 -0500", formatter);
|
||||
ZonedDateTime modificationTime = ZonedDateTime.parse("Tue, 13 Feb 2007 10:15:30 -0500", formatter);
|
||||
ZonedDateTime readTime = ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter);
|
||||
@@ -154,7 +157,8 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseIgnoresInvalidDates() {
|
||||
@SuppressWarnings("deprecation")
|
||||
void parseIgnoresInvalidDates() {
|
||||
ZonedDateTime readTime = ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter);
|
||||
|
||||
assertThat(
|
||||
@@ -168,17 +172,17 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEmpty() {
|
||||
void parseEmpty() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> parse(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseNoType() {
|
||||
void parseNoType() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> parse(";"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInvalidParameter() {
|
||||
void parseInvalidParameter() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> parse("foo;bar"));
|
||||
}
|
||||
|
||||
@@ -188,7 +192,8 @@ public class ContentDispositionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void format() {
|
||||
@SuppressWarnings("deprecation")
|
||||
void format() {
|
||||
assertThat(
|
||||
builder("form-data")
|
||||
.name("foo")
|
||||
@@ -199,7 +204,7 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatWithEncodedFilename() {
|
||||
void formatWithEncodedFilename() {
|
||||
assertThat(
|
||||
builder("form-data")
|
||||
.name("name")
|
||||
@@ -209,7 +214,7 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatWithEncodedFilenameUsingUsAscii() {
|
||||
void formatWithEncodedFilenameUsingUsAscii() {
|
||||
assertThat(
|
||||
builder("form-data")
|
||||
.name("name")
|
||||
@@ -220,7 +225,7 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test // gh-24220
|
||||
public void formatWithFilenameWithQuotes() {
|
||||
void formatWithFilenameWithQuotes() {
|
||||
|
||||
BiConsumer<String, String> tester = (input, output) -> {
|
||||
|
||||
@@ -255,7 +260,7 @@ public class ContentDispositionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatWithEncodedFilenameUsingInvalidCharset() {
|
||||
void formatWithEncodedFilenameUsingInvalidCharset() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
builder("form-data")
|
||||
.name("name")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -59,7 +59,7 @@ public class HttpHeadersTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void getOrEmpty() {
|
||||
void getOrEmpty() {
|
||||
String key = "FOO";
|
||||
|
||||
assertThat(headers.get(key)).isNull();
|
||||
@@ -74,14 +74,14 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirst() {
|
||||
void getFirst() {
|
||||
headers.add(HttpHeaders.CACHE_CONTROL, "max-age=1000, public");
|
||||
headers.add(HttpHeaders.CACHE_CONTROL, "s-maxage=1000");
|
||||
assertThat(headers.getFirst(HttpHeaders.CACHE_CONTROL)).isEqualTo("max-age=1000, public");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accept() {
|
||||
void accept() {
|
||||
MediaType mediaType1 = new MediaType("text", "html");
|
||||
MediaType mediaType2 = new MediaType("text", "plain");
|
||||
List<MediaType> mediaTypes = new ArrayList<>(2);
|
||||
@@ -93,7 +93,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test // SPR-9655
|
||||
public void acceptWithMultipleHeaderValues() {
|
||||
void acceptWithMultipleHeaderValues() {
|
||||
headers.add("Accept", "text/html");
|
||||
headers.add("Accept", "text/plain");
|
||||
List<MediaType> expected = Arrays.asList(new MediaType("text", "html"), new MediaType("text", "plain"));
|
||||
@@ -101,7 +101,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test // SPR-14506
|
||||
public void acceptWithMultipleCommaSeparatedHeaderValues() {
|
||||
void acceptWithMultipleCommaSeparatedHeaderValues() {
|
||||
headers.add("Accept", "text/html,text/pdf");
|
||||
headers.add("Accept", "text/plain,text/csv");
|
||||
List<MediaType> expected = Arrays.asList(new MediaType("text", "html"), new MediaType("text", "pdf"),
|
||||
@@ -110,7 +110,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptCharsets() {
|
||||
void acceptCharsets() {
|
||||
Charset charset1 = StandardCharsets.UTF_8;
|
||||
Charset charset2 = StandardCharsets.ISO_8859_1;
|
||||
List<Charset> charsets = new ArrayList<>(2);
|
||||
@@ -122,13 +122,13 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptCharsetWildcard() {
|
||||
void acceptCharsetWildcard() {
|
||||
headers.set("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
|
||||
assertThat(headers.getAcceptCharset()).as("Invalid Accept header").isEqualTo(Arrays.asList(StandardCharsets.ISO_8859_1, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allow() {
|
||||
void allow() {
|
||||
EnumSet<HttpMethod> methods = EnumSet.of(HttpMethod.GET, HttpMethod.POST);
|
||||
headers.setAllow(methods);
|
||||
assertThat(headers.getAllow()).as("Invalid Allow header").isEqualTo(methods);
|
||||
@@ -136,7 +136,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentLength() {
|
||||
void contentLength() {
|
||||
long length = 42L;
|
||||
headers.setContentLength(length);
|
||||
assertThat(headers.getContentLength()).as("Invalid Content-Length header").isEqualTo(length);
|
||||
@@ -144,7 +144,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentType() {
|
||||
void contentType() {
|
||||
MediaType contentType = new MediaType("text", "html", StandardCharsets.UTF_8);
|
||||
headers.setContentType(contentType);
|
||||
assertThat(headers.getContentType()).as("Invalid Content-Type header").isEqualTo(contentType);
|
||||
@@ -152,7 +152,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void location() throws URISyntaxException {
|
||||
void location() throws URISyntaxException {
|
||||
URI location = new URI("https://www.example.com/hotels");
|
||||
headers.setLocation(location);
|
||||
assertThat(headers.getLocation()).as("Invalid Location header").isEqualTo(location);
|
||||
@@ -160,7 +160,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eTag() {
|
||||
void eTag() {
|
||||
String eTag = "\"v2.6\"";
|
||||
headers.setETag(eTag);
|
||||
assertThat(headers.getETag()).as("Invalid ETag header").isEqualTo(eTag);
|
||||
@@ -168,7 +168,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void host() {
|
||||
void host() {
|
||||
InetSocketAddress host = InetSocketAddress.createUnresolved("localhost", 8080);
|
||||
headers.setHost(host);
|
||||
assertThat(headers.getHost()).as("Invalid Host header").isEqualTo(host);
|
||||
@@ -176,7 +176,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hostNoPort() {
|
||||
void hostNoPort() {
|
||||
InetSocketAddress host = InetSocketAddress.createUnresolved("localhost", 0);
|
||||
headers.setHost(host);
|
||||
assertThat(headers.getHost()).as("Invalid Host header").isEqualTo(host);
|
||||
@@ -184,7 +184,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv6Host() {
|
||||
void ipv6Host() {
|
||||
InetSocketAddress host = InetSocketAddress.createUnresolved("[::1]", 0);
|
||||
headers.setHost(host);
|
||||
assertThat(headers.getHost()).as("Invalid Host header").isEqualTo(host);
|
||||
@@ -192,13 +192,13 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void illegalETag() {
|
||||
void illegalETag() {
|
||||
String eTag = "v2.6";
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifMatch() {
|
||||
void ifMatch() {
|
||||
String ifMatch = "\"v2.6\"";
|
||||
headers.setIfMatch(ifMatch);
|
||||
assertThat(headers.getIfMatch().get(0)).as("Invalid If-Match header").isEqualTo(ifMatch);
|
||||
@@ -206,13 +206,13 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifMatchIllegalHeader() {
|
||||
void ifMatchIllegalHeader() {
|
||||
headers.setIfMatch("Illegal");
|
||||
assertThatIllegalArgumentException().isThrownBy(headers::getIfMatch);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifMatchMultipleHeaders() {
|
||||
void ifMatchMultipleHeaders() {
|
||||
headers.add(HttpHeaders.IF_MATCH, "\"v2,0\"");
|
||||
headers.add(HttpHeaders.IF_MATCH, "W/\"v2,1\", \"v2,2\"");
|
||||
assertThat(headers.get(HttpHeaders.IF_MATCH).get(0)).as("Invalid If-Match header").isEqualTo("\"v2,0\"");
|
||||
@@ -221,7 +221,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifNoneMatch() {
|
||||
void ifNoneMatch() {
|
||||
String ifNoneMatch = "\"v2.6\"";
|
||||
headers.setIfNoneMatch(ifNoneMatch);
|
||||
assertThat(headers.getIfNoneMatch().get(0)).as("Invalid If-None-Match header").isEqualTo(ifNoneMatch);
|
||||
@@ -229,7 +229,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifNoneMatchWildCard() {
|
||||
void ifNoneMatchWildCard() {
|
||||
String ifNoneMatch = "*";
|
||||
headers.setIfNoneMatch(ifNoneMatch);
|
||||
assertThat(headers.getIfNoneMatch().get(0)).as("Invalid If-None-Match header").isEqualTo(ifNoneMatch);
|
||||
@@ -237,7 +237,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifNoneMatchList() {
|
||||
void ifNoneMatchList() {
|
||||
String ifNoneMatch1 = "\"v2.6\"";
|
||||
String ifNoneMatch2 = "\"v2.7\", \"v2.8\"";
|
||||
List<String> ifNoneMatchList = new ArrayList<>(2);
|
||||
@@ -249,7 +249,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void date() {
|
||||
void date() {
|
||||
Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20);
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("CET"));
|
||||
long date = calendar.getTimeInMillis();
|
||||
@@ -263,13 +263,13 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateInvalid() {
|
||||
void dateInvalid() {
|
||||
headers.set("Date", "Foo Bar Baz");
|
||||
assertThatIllegalArgumentException().isThrownBy(headers::getDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateOtherLocale() {
|
||||
void dateOtherLocale() {
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(new Locale("nl", "nl"));
|
||||
@@ -286,7 +286,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastModified() {
|
||||
void lastModified() {
|
||||
Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20);
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("CET"));
|
||||
long date = calendar.getTimeInMillis();
|
||||
@@ -296,7 +296,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expiresLong() {
|
||||
void expiresLong() {
|
||||
Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20);
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("CET"));
|
||||
long date = calendar.getTimeInMillis();
|
||||
@@ -306,7 +306,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expiresZonedDateTime() {
|
||||
void expiresZonedDateTime() {
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.of(2008, 12, 18, 10, 20, 0, 0, ZoneId.of("GMT"));
|
||||
headers.setExpires(zonedDateTime);
|
||||
assertThat(headers.getExpires()).as("Invalid Expires header").isEqualTo(zonedDateTime.toInstant().toEpochMilli());
|
||||
@@ -314,13 +314,13 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test // SPR-10648 (example is from INT-3063)
|
||||
public void expiresInvalidDate() {
|
||||
void expiresInvalidDate() {
|
||||
headers.set("Expires", "-1");
|
||||
assertThat(headers.getExpires()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifModifiedSince() {
|
||||
void ifModifiedSince() {
|
||||
Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20);
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("CET"));
|
||||
long date = calendar.getTimeInMillis();
|
||||
@@ -330,7 +330,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test // SPR-14144
|
||||
public void invalidIfModifiedSinceHeader() {
|
||||
void invalidIfModifiedSinceHeader() {
|
||||
headers.set(HttpHeaders.IF_MODIFIED_SINCE, "0");
|
||||
assertThat(headers.getIfModifiedSince()).isEqualTo(-1);
|
||||
|
||||
@@ -342,7 +342,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pragma() {
|
||||
void pragma() {
|
||||
String pragma = "no-cache";
|
||||
headers.setPragma(pragma);
|
||||
assertThat(headers.getPragma()).as("Invalid Pragma header").isEqualTo(pragma);
|
||||
@@ -350,35 +350,36 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheControl() {
|
||||
void cacheControl() {
|
||||
headers.setCacheControl("no-cache");
|
||||
assertThat(headers.getCacheControl()).as("Invalid Cache-Control header").isEqualTo("no-cache");
|
||||
assertThat(headers.getFirst("cache-control")).as("Invalid Cache-Control header").isEqualTo("no-cache");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheControlBuilder() {
|
||||
void cacheControlBuilder() {
|
||||
headers.setCacheControl(CacheControl.noCache());
|
||||
assertThat(headers.getCacheControl()).as("Invalid Cache-Control header").isEqualTo("no-cache");
|
||||
assertThat(headers.getFirst("cache-control")).as("Invalid Cache-Control header").isEqualTo("no-cache");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheControlEmpty() {
|
||||
void cacheControlEmpty() {
|
||||
headers.setCacheControl(CacheControl.empty());
|
||||
assertThat(headers.getCacheControl()).as("Invalid Cache-Control header").isNull();
|
||||
assertThat(headers.getFirst("cache-control")).as("Invalid Cache-Control header").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheControlAllValues() {
|
||||
void cacheControlAllValues() {
|
||||
headers.add(HttpHeaders.CACHE_CONTROL, "max-age=1000, public");
|
||||
headers.add(HttpHeaders.CACHE_CONTROL, "s-maxage=1000");
|
||||
assertThat(headers.getCacheControl()).isEqualTo("max-age=1000, public, s-maxage=1000");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentDisposition() {
|
||||
@SuppressWarnings("deprecation")
|
||||
void contentDisposition() {
|
||||
ContentDisposition disposition = headers.getContentDisposition();
|
||||
assertThat(disposition).isNotNull();
|
||||
assertThat(headers.getContentDisposition()).as("Invalid Content-Disposition header").isEqualTo(ContentDisposition.empty());
|
||||
@@ -389,13 +390,13 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test // SPR-11917
|
||||
public void getAllowEmptySet() {
|
||||
void getAllowEmptySet() {
|
||||
headers.setAllow(Collections.emptySet());
|
||||
assertThat(headers.getAllow()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessControlAllowCredentials() {
|
||||
void accessControlAllowCredentials() {
|
||||
assertThat(headers.getAccessControlAllowCredentials()).isFalse();
|
||||
headers.setAccessControlAllowCredentials(false);
|
||||
assertThat(headers.getAccessControlAllowCredentials()).isFalse();
|
||||
@@ -404,7 +405,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessControlAllowHeaders() {
|
||||
void accessControlAllowHeaders() {
|
||||
List<String> allowedHeaders = headers.getAccessControlAllowHeaders();
|
||||
assertThat(allowedHeaders).isEmpty();
|
||||
headers.setAccessControlAllowHeaders(Arrays.asList("header1", "header2"));
|
||||
@@ -413,7 +414,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessControlAllowHeadersMultipleValues() {
|
||||
void accessControlAllowHeadersMultipleValues() {
|
||||
List<String> allowedHeaders = headers.getAccessControlAllowHeaders();
|
||||
assertThat(allowedHeaders).isEmpty();
|
||||
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "header1, header2");
|
||||
@@ -423,7 +424,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessControlAllowMethods() {
|
||||
void accessControlAllowMethods() {
|
||||
List<HttpMethod> allowedMethods = headers.getAccessControlAllowMethods();
|
||||
assertThat(allowedMethods).isEmpty();
|
||||
headers.setAccessControlAllowMethods(Arrays.asList(HttpMethod.GET, HttpMethod.POST));
|
||||
@@ -432,14 +433,14 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessControlAllowOrigin() {
|
||||
void accessControlAllowOrigin() {
|
||||
assertThat(headers.getAccessControlAllowOrigin()).isNull();
|
||||
headers.setAccessControlAllowOrigin("*");
|
||||
assertThat(headers.getAccessControlAllowOrigin()).isEqualTo("*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessControlExposeHeaders() {
|
||||
void accessControlExposeHeaders() {
|
||||
List<String> exposedHeaders = headers.getAccessControlExposeHeaders();
|
||||
assertThat(exposedHeaders).isEmpty();
|
||||
headers.setAccessControlExposeHeaders(Arrays.asList("header1", "header2"));
|
||||
@@ -448,14 +449,14 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessControlMaxAge() {
|
||||
void accessControlMaxAge() {
|
||||
assertThat(headers.getAccessControlMaxAge()).isEqualTo(-1);
|
||||
headers.setAccessControlMaxAge(3600);
|
||||
assertThat(headers.getAccessControlMaxAge()).isEqualTo(3600);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessControlRequestHeaders() {
|
||||
void accessControlRequestHeaders() {
|
||||
List<String> requestHeaders = headers.getAccessControlRequestHeaders();
|
||||
assertThat(requestHeaders).isEmpty();
|
||||
headers.setAccessControlRequestHeaders(Arrays.asList("header1", "header2"));
|
||||
@@ -464,14 +465,14 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessControlRequestMethod() {
|
||||
void accessControlRequestMethod() {
|
||||
assertThat(headers.getAccessControlRequestMethod()).isNull();
|
||||
headers.setAccessControlRequestMethod(HttpMethod.POST);
|
||||
assertThat(headers.getAccessControlRequestMethod()).isEqualTo(HttpMethod.POST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptLanguage() {
|
||||
void acceptLanguage() {
|
||||
String headerValue = "fr-ch, fr;q=0.9, en-*;q=0.8, de;q=0.7, *;q=0.5";
|
||||
headers.setAcceptLanguage(Locale.LanguageRange.parse(headerValue));
|
||||
assertThat(headers.getFirst(HttpHeaders.ACCEPT_LANGUAGE)).isEqualTo(headerValue);
|
||||
@@ -491,26 +492,26 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test // SPR-15603
|
||||
public void acceptLanguageWithEmptyValue() throws Exception {
|
||||
void acceptLanguageWithEmptyValue() throws Exception {
|
||||
this.headers.set(HttpHeaders.ACCEPT_LANGUAGE, "");
|
||||
assertThat(this.headers.getAcceptLanguageAsLocales()).isEqualTo(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentLanguage() {
|
||||
void contentLanguage() {
|
||||
headers.setContentLanguage(Locale.FRANCE);
|
||||
assertThat(headers.getContentLanguage()).isEqualTo(Locale.FRANCE);
|
||||
assertThat(headers.getFirst(HttpHeaders.CONTENT_LANGUAGE)).isEqualTo("fr-FR");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentLanguageSerialized() {
|
||||
void contentLanguageSerialized() {
|
||||
headers.set(HttpHeaders.CONTENT_LANGUAGE, "de, en_CA");
|
||||
assertThat(headers.getContentLanguage()).as("Expected one (first) locale").isEqualTo(Locale.GERMAN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void firstDate() {
|
||||
void firstDate() {
|
||||
headers.setDate(HttpHeaders.DATE, 1496370120000L);
|
||||
assertThat(headers.getFirstDate(HttpHeaders.DATE)).isEqualTo(1496370120000L);
|
||||
|
||||
@@ -522,7 +523,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void firstZonedDateTime() {
|
||||
void firstZonedDateTime() {
|
||||
ZonedDateTime date = ZonedDateTime.of(2017, 6, 2, 2, 22, 0, 0, ZoneId.of("GMT"));
|
||||
headers.setZonedDateTime(HttpHeaders.DATE, date);
|
||||
assertThat(headers.getFirst(HttpHeaders.DATE)).isEqualTo("Fri, 02 Jun 2017 02:22:00 GMT");
|
||||
@@ -547,7 +548,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicAuth() {
|
||||
void basicAuth() {
|
||||
String username = "foo";
|
||||
String password = "bar";
|
||||
headers.setBasicAuth(username, password);
|
||||
@@ -559,14 +560,14 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicAuthIllegalChar() {
|
||||
void basicAuthIllegalChar() {
|
||||
String username = "foo";
|
||||
String password = "\u03BB";
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> headers.setBasicAuth(username, password));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bearerAuth() {
|
||||
void bearerAuth() {
|
||||
String token = "foo";
|
||||
|
||||
headers.setBearerAuth(token);
|
||||
@@ -575,7 +576,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keySetOperations() {
|
||||
void keySetOperations() {
|
||||
headers.add("Alpha", "apple");
|
||||
headers.add("Bravo", "banana");
|
||||
Set<String> keySet = headers.keySet();
|
||||
@@ -634,7 +635,7 @@ public class HttpHeadersTests {
|
||||
* than {@link #removalFromKeySetRemovesEntryFromUnderlyingMap()}.
|
||||
*/
|
||||
@Test // https://github.com/spring-projects/spring-framework/issues/23633
|
||||
public void keySetRemovalChecks() {
|
||||
void keySetRemovalChecks() {
|
||||
// --- Given ---
|
||||
headers.add("Alpha", "apple");
|
||||
headers.add("Bravo", "banana");
|
||||
@@ -660,7 +661,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removalFromKeySetRemovesEntryFromUnderlyingMap() {
|
||||
void removalFromKeySetRemovesEntryFromUnderlyingMap() {
|
||||
String headerName = "MyHeader";
|
||||
String headerValue = "value";
|
||||
|
||||
@@ -674,7 +675,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removalFromEntrySetRemovesEntryFromUnderlyingMap() {
|
||||
void removalFromEntrySetRemovesEntryFromUnderlyingMap() {
|
||||
String headerName = "MyHeader";
|
||||
String headerValue = "value";
|
||||
|
||||
@@ -688,7 +689,7 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOnlyHttpHeadersRetainEntrySetOrder() {
|
||||
void readOnlyHttpHeadersRetainEntrySetOrder() {
|
||||
headers.add("aardvark", "enigma");
|
||||
headers.add("beaver", "enigma");
|
||||
headers.add("cat", "enigma");
|
||||
@@ -704,11 +705,12 @@ public class HttpHeadersTests {
|
||||
}
|
||||
|
||||
@Test // gh-25034
|
||||
public void equalsUnwrapsHttpHeaders() {
|
||||
void equalsUnwrapsHttpHeaders() {
|
||||
HttpHeaders headers1 = new HttpHeaders();
|
||||
HttpHeaders headers2 = new HttpHeaders(new HttpHeaders(headers1));
|
||||
|
||||
assertThat(headers1).isEqualTo(headers2);
|
||||
assertThat(headers2).isEqualTo(headers1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -38,10 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Arjen Poutsma
|
||||
* @author Parviz Rozikov
|
||||
*/
|
||||
public class RequestEntityTests {
|
||||
class RequestEntityTests {
|
||||
|
||||
@Test
|
||||
public void normal() throws URISyntaxException {
|
||||
void normal() throws URISyntaxException {
|
||||
String headerName = "My-Custom-Header";
|
||||
String headerValue = "HeaderValue";
|
||||
URI url = new URI("https://example.com");
|
||||
@@ -59,7 +58,7 @@ public class RequestEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriVariablesExpansion() throws URISyntaxException {
|
||||
void uriVariablesExpansion() throws URISyntaxException {
|
||||
URI uri = UriComponentsBuilder.fromUriString("https://example.com/{foo}").buildAndExpand("bar").toUri();
|
||||
RequestEntity.get(uri).accept(MediaType.TEXT_PLAIN).build();
|
||||
|
||||
@@ -82,22 +81,20 @@ public class RequestEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriExpansion() {
|
||||
|
||||
void uriExpansion() {
|
||||
RequestEntity<Void> entity =
|
||||
RequestEntity.get("https://www.{host}.com/{path}", "example", "foo/bar").build();
|
||||
|
||||
assertThat(entity).isInstanceOf(RequestEntity.UriTemplateRequestEntity.class);
|
||||
RequestEntity.UriTemplateRequestEntity<Void> ext = (RequestEntity.UriTemplateRequestEntity<Void>) entity;
|
||||
|
||||
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
|
||||
assertThat(ext.getUriTemplate()).isEqualTo("https://www.{host}.com/{path}");
|
||||
assertThat(ext.getVars()).containsExactly("example", "foo/bar");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void get() {
|
||||
void get() {
|
||||
RequestEntity<Void> requestEntity = RequestEntity.get(URI.create("https://example.com")).accept(
|
||||
MediaType.IMAGE_GIF, MediaType.IMAGE_JPEG, MediaType.IMAGE_PNG).build();
|
||||
|
||||
@@ -109,7 +106,7 @@ public class RequestEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headers() throws URISyntaxException {
|
||||
void headers() throws URISyntaxException {
|
||||
MediaType accept = MediaType.TEXT_PLAIN;
|
||||
long ifModifiedSince = 12345L;
|
||||
String ifNoneMatch = "\"foo\"";
|
||||
@@ -142,7 +139,7 @@ public class RequestEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methods() throws URISyntaxException {
|
||||
void methods() throws URISyntaxException {
|
||||
URI url = new URI("https://example.com");
|
||||
|
||||
RequestEntity<?> entity = RequestEntity.get(url).build();
|
||||
@@ -169,7 +166,7 @@ public class RequestEntityTests {
|
||||
}
|
||||
|
||||
@Test // SPR-13154
|
||||
public void types() throws URISyntaxException {
|
||||
void types() throws URISyntaxException {
|
||||
URI url = new URI("https://example.com");
|
||||
List<String> body = Arrays.asList("foo", "bar");
|
||||
ParameterizedTypeReference<?> typeReference = new ParameterizedTypeReference<List<String>>() {};
|
||||
|
||||
@@ -134,7 +134,6 @@ public abstract class AbstractAsyncHttpRequestFactoryTests extends AbstractMockW
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("try")
|
||||
public void multipleWrites() throws Exception {
|
||||
AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/echo"), HttpMethod.POST);
|
||||
final byte[] body = "Hello World".getBytes("UTF-8");
|
||||
@@ -149,12 +148,12 @@ public abstract class AbstractAsyncHttpRequestFactoryTests extends AbstractMockW
|
||||
|
||||
Future<ClientHttpResponse> futureResponse = request.executeAsync();
|
||||
try (ClientHttpResponse response = futureResponse.get()) {
|
||||
assertThat(response).isNotNull();
|
||||
assertThatIllegalStateException().isThrownBy(() -> FileCopyUtils.copy(body, request.getBody()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("try")
|
||||
public void headersAfterExecute() throws Exception {
|
||||
AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/echo"), HttpMethod.POST);
|
||||
request.getHeaders().add("MyHeader", "value");
|
||||
@@ -163,6 +162,7 @@ public abstract class AbstractAsyncHttpRequestFactoryTests extends AbstractMockW
|
||||
|
||||
Future<ClientHttpResponse> futureResponse = request.executeAsync();
|
||||
try (ClientHttpResponse response = futureResponse.get()) {
|
||||
assertThat(response).isNotNull();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
request.getHeaders().add("MyHeader", "value"));
|
||||
}
|
||||
|
||||
@@ -129,7 +129,6 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("try")
|
||||
void headersAfterExecute() throws Exception {
|
||||
ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/status/ok"), HttpMethod.POST);
|
||||
|
||||
@@ -138,6 +137,7 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> {
|
||||
FileCopyUtils.copy(body, request.getBody());
|
||||
try (ClientHttpResponse response = request.execute()) {
|
||||
assertThat(response).isNotNull();
|
||||
request.getHeaders().add("MyHeader", "value");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -210,11 +210,4 @@ class EncoderHttpMessageWriterTests {
|
||||
.willReturn(encodedStream);
|
||||
}
|
||||
|
||||
private void configureEncoder(DataBuffer dataBuffer, MimeType... mimeTypes) {
|
||||
List<MimeType> typeList = Arrays.asList(mimeTypes);
|
||||
given(this.encoder.getEncodableMimeTypes()).willReturn(typeList);
|
||||
given(this.encoder.encodeValue(any(), any(), any(), this.mediaTypeCaptor.capture(), any()))
|
||||
.willReturn(dataBuffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ContentNegotiationManagerFactoryBeanTests {
|
||||
class ContentNegotiationManagerFactoryBeanTests {
|
||||
|
||||
private ContentNegotiationManagerFactoryBean factoryBean;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
void setup() {
|
||||
TestServletContext servletContext = new TestServletContext();
|
||||
servletContext.getMimeTypes().put("foo", "application/foo");
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void defaultSettings() throws Exception {
|
||||
void defaultSettings() throws Exception {
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
ContentNegotiationManager manager = this.factoryBean.getObject();
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitStrategies() throws Exception {
|
||||
void explicitStrategies() throws Exception {
|
||||
Map<String, MediaType> mediaTypes = Collections.singletonMap("bar", new MediaType("application", "bar"));
|
||||
ParameterContentNegotiationStrategy strategy1 = new ParameterContentNegotiationStrategy(mediaTypes);
|
||||
HeaderContentNegotiationStrategy strategy2 = new HeaderContentNegotiationStrategy();
|
||||
@@ -116,7 +116,8 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void favorPath() throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
void favorPath() throws Exception {
|
||||
this.factoryBean.setFavorPathExtension(true);
|
||||
this.factoryBean.addMediaType("bar", new MediaType("application", "bar"));
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
@@ -136,7 +137,8 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test // SPR-10170
|
||||
public void favorPathWithIgnoreUnknownPathExtensionTurnedOff() {
|
||||
@SuppressWarnings("deprecation")
|
||||
void favorPathWithIgnoreUnknownPathExtensionTurnedOff() {
|
||||
this.factoryBean.setFavorPathExtension(true);
|
||||
this.factoryBean.setIgnoreUnknownPathExtensions(false);
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
@@ -150,7 +152,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void favorParameter() throws Exception {
|
||||
void favorParameter() throws Exception {
|
||||
this.factoryBean.setFavorParameter(true);
|
||||
this.factoryBean.addMediaType("json", MediaType.APPLICATION_JSON);
|
||||
|
||||
@@ -165,7 +167,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test // SPR-10170
|
||||
public void favorParameterWithUnknownMediaType() {
|
||||
void favorParameterWithUnknownMediaType() {
|
||||
this.factoryBean.setFavorParameter(true);
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
ContentNegotiationManager manager = this.factoryBean.getObject();
|
||||
@@ -178,8 +180,8 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mediaTypeMappingsWithoutPathAndParameterStrategies() {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
void mediaTypeMappingsWithoutPathAndParameterStrategies() {
|
||||
this.factoryBean.setFavorPathExtension(false);
|
||||
this.factoryBean.setFavorParameter(false);
|
||||
|
||||
@@ -199,8 +201,8 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileExtensions() {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
void fileExtensions() {
|
||||
this.factoryBean.setFavorPathExtension(false);
|
||||
this.factoryBean.setFavorParameter(false);
|
||||
|
||||
@@ -222,7 +224,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ignoreAcceptHeader() throws Exception {
|
||||
void ignoreAcceptHeader() throws Exception {
|
||||
this.factoryBean.setIgnoreAcceptHeader(true);
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
ContentNegotiationManager manager = this.factoryBean.getObject();
|
||||
@@ -235,7 +237,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultContentType() throws Exception {
|
||||
void setDefaultContentType() throws Exception {
|
||||
this.factoryBean.setDefaultContentType(MediaType.APPLICATION_JSON);
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
ContentNegotiationManager manager = this.factoryBean.getObject();
|
||||
@@ -248,7 +250,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test // SPR-15367
|
||||
public void setDefaultContentTypes() throws Exception {
|
||||
void setDefaultContentTypes() throws Exception {
|
||||
List<MediaType> mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON, MediaType.ALL);
|
||||
this.factoryBean.setDefaultContentTypes(mediaTypes);
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
@@ -261,7 +263,7 @@ public class ContentNegotiationManagerFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test // SPR-12286
|
||||
public void setDefaultContentTypeWithStrategy() throws Exception {
|
||||
void setDefaultContentTypeWithStrategy() throws Exception {
|
||||
this.factoryBean.setDefaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON));
|
||||
this.factoryBean.afterPropertiesSet();
|
||||
ContentNegotiationManager manager = this.factoryBean.getObject();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.web.accept;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -20,7 +21,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -33,103 +33,79 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* A test fixture for PathExtensionContentNegotiationStrategy.
|
||||
* A test fixture for {@link PathExtensionContentNegotiationStrategy}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.2
|
||||
*/
|
||||
public class PathExtensionContentNegotiationStrategyTests {
|
||||
@SuppressWarnings("deprecation")
|
||||
class PathExtensionContentNegotiationStrategyTests {
|
||||
|
||||
private NativeWebRequest webRequest;
|
||||
private final MockHttpServletRequest servletRequest = new MockHttpServletRequest();
|
||||
|
||||
private MockHttpServletRequest servletRequest;
|
||||
private final NativeWebRequest webRequest = new ServletWebRequest(servletRequest);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.servletRequest = new MockHttpServletRequest();
|
||||
this.webRequest = new ServletWebRequest(servletRequest);
|
||||
}
|
||||
private PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy();
|
||||
|
||||
|
||||
@Test
|
||||
public void resolveMediaTypesFromMapping() throws Exception {
|
||||
|
||||
void resolveMediaTypesFromMapping() throws Exception {
|
||||
this.servletRequest.setRequestURI("test.html");
|
||||
|
||||
PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy();
|
||||
List<MediaType> mediaTypes = strategy.resolveMediaTypes(this.webRequest);
|
||||
List<MediaType> mediaTypes = this.strategy.resolveMediaTypes(this.webRequest);
|
||||
|
||||
assertThat(mediaTypes).isEqualTo(Arrays.asList(new MediaType("text", "html")));
|
||||
|
||||
Map<String, MediaType> mapping = Collections.singletonMap("HTML", MediaType.APPLICATION_XHTML_XML);
|
||||
strategy = new PathExtensionContentNegotiationStrategy(mapping);
|
||||
mediaTypes = strategy.resolveMediaTypes(this.webRequest);
|
||||
this.strategy = new PathExtensionContentNegotiationStrategy(mapping);
|
||||
mediaTypes = this.strategy.resolveMediaTypes(this.webRequest);
|
||||
|
||||
assertThat(mediaTypes).isEqualTo(Arrays.asList(new MediaType("application", "xhtml+xml")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveMediaTypesFromMediaTypeFactory() throws Exception {
|
||||
|
||||
void resolveMediaTypesFromMediaTypeFactory() throws Exception {
|
||||
this.servletRequest.setRequestURI("test.xls");
|
||||
|
||||
PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy();
|
||||
List<MediaType> mediaTypes = strategy.resolveMediaTypes(this.webRequest);
|
||||
List<MediaType> mediaTypes = this.strategy.resolveMediaTypes(this.webRequest);
|
||||
|
||||
assertThat(mediaTypes).isEqualTo(Arrays.asList(new MediaType("application", "vnd.ms-excel")));
|
||||
}
|
||||
|
||||
// SPR-8678
|
||||
|
||||
@Test
|
||||
public void getMediaTypeFilenameWithContextPath() throws Exception {
|
||||
|
||||
PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy();
|
||||
|
||||
@Test // SPR-8678
|
||||
void getMediaTypeFilenameWithContextPath() throws Exception {
|
||||
this.servletRequest.setContextPath("/project-1.0.0.M3");
|
||||
this.servletRequest.setRequestURI("/project-1.0.0.M3/");
|
||||
assertThat(strategy.resolveMediaTypes(webRequest)).as("Context path should be excluded").isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST);
|
||||
assertThat(this.strategy.resolveMediaTypes(webRequest)).as("Context path should be excluded").isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST);
|
||||
|
||||
this.servletRequest.setRequestURI("/project-1.0.0.M3");
|
||||
assertThat(strategy.resolveMediaTypes(webRequest)).as("Context path should be excluded").isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST);
|
||||
assertThat(this.strategy.resolveMediaTypes(webRequest)).as("Context path should be excluded").isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST);
|
||||
}
|
||||
|
||||
// SPR-9390
|
||||
|
||||
@Test
|
||||
public void getMediaTypeFilenameWithEncodedURI() throws Exception {
|
||||
|
||||
@Test // SPR-9390
|
||||
void getMediaTypeFilenameWithEncodedURI() throws Exception {
|
||||
this.servletRequest.setRequestURI("/quo%20vadis%3f.html");
|
||||
|
||||
PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy();
|
||||
List<MediaType> result = strategy.resolveMediaTypes(webRequest);
|
||||
List<MediaType> result = this.strategy.resolveMediaTypes(webRequest);
|
||||
|
||||
assertThat(result).as("Invalid content type").isEqualTo(Collections.singletonList(new MediaType("text", "html")));
|
||||
}
|
||||
|
||||
// SPR-10170
|
||||
|
||||
@Test
|
||||
public void resolveMediaTypesIgnoreUnknownExtension() throws Exception {
|
||||
|
||||
@Test // SPR-10170
|
||||
void resolveMediaTypesIgnoreUnknownExtension() throws Exception {
|
||||
this.servletRequest.setRequestURI("test.foobar");
|
||||
|
||||
PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy();
|
||||
List<MediaType> mediaTypes = strategy.resolveMediaTypes(this.webRequest);
|
||||
List<MediaType> mediaTypes = this.strategy.resolveMediaTypes(this.webRequest);
|
||||
|
||||
assertThat(mediaTypes).isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveMediaTypesDoNotIgnoreUnknownExtension() throws Exception {
|
||||
|
||||
void resolveMediaTypesDoNotIgnoreUnknownExtension() {
|
||||
this.servletRequest.setRequestURI("test.foobar");
|
||||
|
||||
PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy();
|
||||
strategy.setIgnoreUnknownExtensions(false);
|
||||
assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class).isThrownBy(() ->
|
||||
strategy.resolveMediaTypes(this.webRequest));
|
||||
this.strategy.setIgnoreUnknownExtensions(false);
|
||||
assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class)
|
||||
.isThrownBy(() -> this.strategy.resolveMediaTypes(this.webRequest));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -81,36 +81,30 @@ import static org.springframework.http.MediaType.parseMediaType;
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class RestTemplateTests {
|
||||
class RestTemplateTests {
|
||||
|
||||
private RestTemplate template;
|
||||
private final ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class);
|
||||
|
||||
private ClientHttpRequestFactory requestFactory;
|
||||
private final ClientHttpRequest request = mock(ClientHttpRequest.class);
|
||||
|
||||
private ClientHttpRequest request;
|
||||
private final ClientHttpResponse response = mock(ClientHttpResponse.class);
|
||||
|
||||
private ClientHttpResponse response;
|
||||
|
||||
private ResponseErrorHandler errorHandler;
|
||||
private final ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private HttpMessageConverter converter;
|
||||
private final HttpMessageConverter converter = mock(HttpMessageConverter.class);
|
||||
|
||||
private final RestTemplate template = new RestTemplate(Collections.singletonList(converter));
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
requestFactory = mock(ClientHttpRequestFactory.class);
|
||||
request = mock(ClientHttpRequest.class);
|
||||
response = mock(ClientHttpResponse.class);
|
||||
errorHandler = mock(ResponseErrorHandler.class);
|
||||
converter = mock(HttpMessageConverter.class);
|
||||
template = new RestTemplate(Collections.singletonList(converter));
|
||||
void setup() {
|
||||
template.setRequestFactory(requestFactory);
|
||||
template.setErrorHandler(errorHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorPreconditions() {
|
||||
void constructorPreconditions() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new RestTemplate((List<HttpMessageConverter<?>>) null))
|
||||
.withMessage("At least one HttpMessageConverter is required");
|
||||
@@ -120,7 +114,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setMessageConvertersPreconditions() {
|
||||
void setMessageConvertersPreconditions() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> template.setMessageConverters((List<HttpMessageConverter<?>>) null))
|
||||
.withMessage("At least one HttpMessageConverter is required");
|
||||
@@ -130,7 +124,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void varArgsTemplateVariables() throws Exception {
|
||||
void varArgsTemplateVariables() throws Exception {
|
||||
mockSentRequest(GET, "https://example.com/hotels/42/bookings/21");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
|
||||
@@ -141,7 +135,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void varArgsNullTemplateVariable() throws Exception {
|
||||
void varArgsNullTemplateVariable() throws Exception {
|
||||
mockSentRequest(GET, "https://example.com/-foo");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
|
||||
@@ -151,7 +145,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapTemplateVariables() throws Exception {
|
||||
void mapTemplateVariables() throws Exception {
|
||||
mockSentRequest(GET, "https://example.com/hotels/42/bookings/42");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
|
||||
@@ -162,7 +156,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapNullTemplateVariable() throws Exception {
|
||||
void mapNullTemplateVariable() throws Exception {
|
||||
mockSentRequest(GET, "https://example.com/-foo");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
|
||||
@@ -175,7 +169,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test // SPR-15201
|
||||
public void uriTemplateWithTrailingSlash() throws Exception {
|
||||
void uriTemplateWithTrailingSlash() throws Exception {
|
||||
String url = "https://example.com/spring/";
|
||||
mockSentRequest(GET, url);
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
@@ -186,7 +180,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorHandling() throws Exception {
|
||||
void errorHandling() throws Exception {
|
||||
String url = "https://example.com";
|
||||
mockSentRequest(GET, url);
|
||||
mockResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@@ -200,7 +194,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getForObject() throws Exception {
|
||||
void getForObject() throws Exception {
|
||||
String expected = "Hello World";
|
||||
mockTextPlainHttpMessageConverter();
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
@@ -216,7 +210,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUnsupportedMediaType() throws Exception {
|
||||
void getUnsupportedMediaType() throws Exception {
|
||||
mockSentRequest(GET, "https://example.com/resource");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
|
||||
@@ -235,7 +229,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestAvoidsDuplicateAcceptHeaderValues() throws Exception {
|
||||
void requestAvoidsDuplicateAcceptHeaderValues() throws Exception {
|
||||
HttpMessageConverter<?> firstConverter = mock(HttpMessageConverter.class);
|
||||
given(firstConverter.canRead(any(), any())).willReturn(true);
|
||||
given(firstConverter.getSupportedMediaTypes())
|
||||
@@ -257,7 +251,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getForEntity() throws Exception {
|
||||
void getForEntity() throws Exception {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(GET, "https://example.com", requestHeaders);
|
||||
mockTextPlainHttpMessageConverter();
|
||||
@@ -275,7 +269,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getForObjectWithCustomUriTemplateHandler() throws Exception {
|
||||
void getForObjectWithCustomUriTemplateHandler() throws Exception {
|
||||
DefaultUriBuilderFactory uriTemplateHandler = new DefaultUriBuilderFactory();
|
||||
template.setUriTemplateHandler(uriTemplateHandler);
|
||||
mockSentRequest(GET, "https://example.com/hotels/1/pic/pics%2Flogo.png/size/150x150");
|
||||
@@ -295,7 +289,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headForHeaders() throws Exception {
|
||||
void headForHeaders() throws Exception {
|
||||
mockSentRequest(HEAD, "https://example.com");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
@@ -309,7 +303,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForLocation() throws Exception {
|
||||
void postForLocation() throws Exception {
|
||||
mockSentRequest(POST, "https://example.com");
|
||||
mockTextPlainHttpMessageConverter();
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
@@ -326,7 +320,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForLocationEntityContentType() throws Exception {
|
||||
void postForLocationEntityContentType() throws Exception {
|
||||
mockSentRequest(POST, "https://example.com");
|
||||
mockTextPlainHttpMessageConverter();
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
@@ -348,7 +342,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForLocationEntityCustomHeader() throws Exception {
|
||||
void postForLocationEntityCustomHeader() throws Exception {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(POST, "https://example.com", requestHeaders);
|
||||
mockTextPlainHttpMessageConverter();
|
||||
@@ -370,7 +364,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForLocationNoLocation() throws Exception {
|
||||
void postForLocationNoLocation() throws Exception {
|
||||
mockSentRequest(POST, "https://example.com");
|
||||
mockTextPlainHttpMessageConverter();
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
@@ -382,7 +376,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForLocationNull() throws Exception {
|
||||
void postForLocationNull() throws Exception {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(POST, "https://example.com", requestHeaders);
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
@@ -394,7 +388,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForObject() throws Exception {
|
||||
void postForObject() throws Exception {
|
||||
mockTextPlainHttpMessageConverter();
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(POST, "https://example.com", requestHeaders);
|
||||
@@ -410,7 +404,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForEntity() throws Exception {
|
||||
void postForEntity() throws Exception {
|
||||
mockTextPlainHttpMessageConverter();
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(POST, "https://example.com", requestHeaders);
|
||||
@@ -428,7 +422,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForObjectNull() throws Exception {
|
||||
void postForObjectNull() throws Exception {
|
||||
mockTextPlainHttpMessageConverter();
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(POST, "https://example.com", requestHeaders);
|
||||
@@ -448,7 +442,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForEntityNull() throws Exception {
|
||||
void postForEntityNull() throws Exception {
|
||||
mockTextPlainHttpMessageConverter();
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(POST, "https://example.com", requestHeaders);
|
||||
@@ -470,7 +464,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void put() throws Exception {
|
||||
void put() throws Exception {
|
||||
mockTextPlainHttpMessageConverter();
|
||||
mockSentRequest(PUT, "https://example.com");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
@@ -481,7 +475,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putNull() throws Exception {
|
||||
void putNull() throws Exception {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(PUT, "https://example.com", requestHeaders);
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
@@ -493,26 +487,21 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test // gh-23740
|
||||
public void headerAcceptAllOnPut() throws Exception {
|
||||
MockWebServer server = new MockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error"));
|
||||
server.start();
|
||||
try {
|
||||
void headerAcceptAllOnPut() throws Exception {
|
||||
try (MockWebServer server = new MockWebServer()) {
|
||||
server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error"));
|
||||
server.start();
|
||||
template.setRequestFactory(new SimpleClientHttpRequestFactory());
|
||||
template.put(server.url("/internal/server/error").uri(), null);
|
||||
assertThat(server.takeRequest().getHeader("Accept")).isEqualTo("*/*");
|
||||
}
|
||||
finally {
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-23740
|
||||
public void keepGivenAcceptHeaderOnPut() throws Exception {
|
||||
MockWebServer server = new MockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error"));
|
||||
server.start();
|
||||
try {
|
||||
void keepGivenAcceptHeaderOnPut() throws Exception {
|
||||
try (MockWebServer server = new MockWebServer()) {
|
||||
server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error"));
|
||||
server.start();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
HttpEntity<String> entity = new HttpEntity<>(null, headers);
|
||||
@@ -530,13 +519,10 @@ public class RestTemplateTests {
|
||||
assertThat(accepts.get(0)).hasSize(1);
|
||||
assertThat(accepts.get(0).get(0)).isEqualTo("application/json");
|
||||
}
|
||||
finally {
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patchForObject() throws Exception {
|
||||
void patchForObject() throws Exception {
|
||||
mockTextPlainHttpMessageConverter();
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(PATCH, "https://example.com", requestHeaders);
|
||||
@@ -552,7 +538,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patchForObjectNull() throws Exception {
|
||||
void patchForObjectNull() throws Exception {
|
||||
mockTextPlainHttpMessageConverter();
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(PATCH, "https://example.com", requestHeaders);
|
||||
@@ -570,9 +556,8 @@ public class RestTemplateTests {
|
||||
verify(response).close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void delete() throws Exception {
|
||||
void delete() throws Exception {
|
||||
mockSentRequest(DELETE, "https://example.com");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
|
||||
@@ -582,22 +567,18 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test // gh-23740
|
||||
public void headerAcceptAllOnDelete() throws Exception {
|
||||
MockWebServer server = new MockWebServer();
|
||||
server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error"));
|
||||
server.start();
|
||||
try {
|
||||
void headerAcceptAllOnDelete() throws Exception {
|
||||
try (MockWebServer server = new MockWebServer()) {
|
||||
server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error"));
|
||||
server.start();
|
||||
template.setRequestFactory(new SimpleClientHttpRequestFactory());
|
||||
template.delete(server.url("/internal/server/error").uri());
|
||||
assertThat(server.takeRequest().getHeader("Accept")).isEqualTo("*/*");
|
||||
}
|
||||
finally {
|
||||
server.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsForAllow() throws Exception {
|
||||
void optionsForAllow() throws Exception {
|
||||
mockSentRequest(OPTIONS, "https://example.com");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
@@ -612,7 +593,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test // SPR-9325, SPR-13860
|
||||
public void ioException() throws Exception {
|
||||
void ioException() throws Exception {
|
||||
String url = "https://example.com/resource?access_token=123";
|
||||
mockSentRequest(GET, url);
|
||||
mockHttpMessageConverter(new MediaType("foo", "bar"), String.class);
|
||||
@@ -625,8 +606,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test // SPR-15900
|
||||
public void ioExceptionWithEmptyQueryString() throws Exception {
|
||||
|
||||
void ioExceptionWithEmptyQueryString() throws Exception {
|
||||
// https://example.com/resource?
|
||||
URI uri = new URI("https", "example.com", "/resource", "", null);
|
||||
|
||||
@@ -643,7 +623,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exchange() throws Exception {
|
||||
void exchange() throws Exception {
|
||||
mockTextPlainHttpMessageConverter();
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
mockSentRequest(POST, "https://example.com", requestHeaders);
|
||||
@@ -666,7 +646,7 @@ public class RestTemplateTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void exchangeParameterizedType() throws Exception {
|
||||
void exchangeParameterizedType() throws Exception {
|
||||
GenericHttpMessageConverter converter = mock(GenericHttpMessageConverter.class);
|
||||
template.setMessageConverters(Collections.<HttpMessageConverter<?>>singletonList(converter));
|
||||
ParameterizedTypeReference<List<Integer>> intList = new ParameterizedTypeReference<List<Integer>>() {};
|
||||
@@ -700,7 +680,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test // SPR-15066
|
||||
public void requestInterceptorCanAddExistingHeaderValueWithoutBody() throws Exception {
|
||||
void requestInterceptorCanAddExistingHeaderValueWithoutBody() throws Exception {
|
||||
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
|
||||
request.getHeaders().add("MyHeader", "MyInterceptorValue");
|
||||
return execution.execute(request, body);
|
||||
@@ -721,7 +701,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test // SPR-15066
|
||||
public void requestInterceptorCanAddExistingHeaderValueWithBody() throws Exception {
|
||||
void requestInterceptorCanAddExistingHeaderValueWithBody() throws Exception {
|
||||
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
|
||||
request.getHeaders().add("MyHeader", "MyInterceptorValue");
|
||||
return execution.execute(request, body);
|
||||
@@ -745,7 +725,7 @@ public class RestTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientHttpRequestInitializerAndRequestInterceptorAreBothApplied() throws Exception {
|
||||
void clientHttpRequestInitializerAndRequestInterceptorAreBothApplied() throws Exception {
|
||||
ClientHttpRequestInitializer initializer = request ->
|
||||
request.getHeaders().add("MyHeader", "MyInitializerValue");
|
||||
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
|
||||
|
||||
Reference in New Issue
Block a user