Raise the minimum support version of Spring Framework to 7.0
See gh-955
This commit is contained in:
committed by
Andy Wilkinson
parent
db16f279c2
commit
c72e32d3cb
@@ -6,4 +6,4 @@ org.gradle.parallel=true
|
||||
|
||||
javaFormatVersion=0.0.43
|
||||
jmustacheVersion=1.15
|
||||
springFrameworkVersion=6.1.13
|
||||
springFrameworkVersion=7.0.0-SNAPSHOT
|
||||
|
||||
@@ -82,10 +82,3 @@ components.java.withVariantsFromConfiguration(configurations.testFixturesApiElem
|
||||
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) {
|
||||
skip()
|
||||
}
|
||||
|
||||
compatibilityTest {
|
||||
dependency("Spring Framework") { springFramework ->
|
||||
springFramework.groupId = "org.springframework"
|
||||
springFramework.versions = ["6.0.+", "6.2.+"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -76,7 +76,7 @@ final class CliOperationRequest implements OperationRequest {
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
HttpHeaders filteredHeaders = new HttpHeaders();
|
||||
for (Entry<String, List<String>> header : this.delegate.getHeaders().entrySet()) {
|
||||
for (Entry<String, List<String>> header : this.delegate.getHeaders().headerSet()) {
|
||||
if (allowedHeader(header)) {
|
||||
filteredHeaders.put(header.getKey(), header.getValue());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -132,7 +132,7 @@ public class CurlRequestSnippet extends TemplatedSnippet {
|
||||
}
|
||||
|
||||
private void writeHeaders(CliOperationRequest request, List<String> lines) {
|
||||
for (Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
|
||||
for (Entry<String, List<String>> entry : request.getHeaders().headerSet()) {
|
||||
for (String header : entry.getValue()) {
|
||||
if (StringUtils.hasText(request.getContentAsString()) && HttpHeaders.CONTENT_TYPE.equals(entry.getKey())
|
||||
&& MediaType.APPLICATION_FORM_URLENCODED.equals(request.getHeaders().getContentType())) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -160,7 +160,7 @@ public class HttpieRequestSnippet extends TemplatedSnippet {
|
||||
|
||||
private void writeHeaders(OperationRequest request, List<String> lines) {
|
||||
HttpHeaders headers = request.getHeaders();
|
||||
for (Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
for (Entry<String, List<String>> entry : headers.headerSet()) {
|
||||
if (entry.getKey().equals(HttpHeaders.CONTENT_TYPE)
|
||||
&& headers.getContentType().isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED)) {
|
||||
continue;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -57,7 +57,7 @@ public class RequestHeadersSnippet extends AbstractHeadersSnippet {
|
||||
|
||||
@Override
|
||||
protected Set<String> extractActualHeaders(Operation operation) {
|
||||
return operation.getRequest().getHeaders().keySet();
|
||||
return operation.getRequest().getHeaders().headerNames();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -57,7 +57,7 @@ public class ResponseHeadersSnippet extends AbstractHeadersSnippet {
|
||||
|
||||
@Override
|
||||
protected Set<String> extractActualHeaders(Operation operation) {
|
||||
return operation.getResponse().getHeaders().keySet();
|
||||
return operation.getResponse().getHeaders().headerNames();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2024 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -91,7 +91,7 @@ public class HttpRequestSnippet extends TemplatedSnippet {
|
||||
private List<Map<String, String>> getHeaders(OperationRequest request) {
|
||||
List<Map<String, String>> headers = new ArrayList<>();
|
||||
|
||||
for (Entry<String, List<String>> header : request.getHeaders().entrySet()) {
|
||||
for (Entry<String, List<String>> header : request.getHeaders().headerSet()) {
|
||||
for (String value : header.getValue()) {
|
||||
if (HttpHeaders.CONTENT_TYPE.equals(header.getKey()) && !request.getParts().isEmpty()) {
|
||||
headers.add(header(header.getKey(), String.format("%s; boundary=%s", value, MULTIPART_BOUNDARY)));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -73,7 +73,7 @@ public class HttpResponseSnippet extends TemplatedSnippet {
|
||||
|
||||
private List<Map<String, String>> headers(OperationResponse response) {
|
||||
List<Map<String, String>> headers = new ArrayList<>();
|
||||
for (Entry<String, List<String>> header : response.getHeaders().entrySet()) {
|
||||
for (Entry<String, List<String>> header : response.getHeaders().headerSet()) {
|
||||
List<String> values = header.getValue();
|
||||
for (String value : values) {
|
||||
headers.add(header(header.getKey(), value));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -210,7 +210,7 @@ public class HeadersModifyingOperationPreprocessor implements OperationPreproces
|
||||
|
||||
@Override
|
||||
public void applyTo(HttpHeaders headers) {
|
||||
headers.keySet().removeIf((name) -> this.namePattern.matcher(name).matches());
|
||||
headers.headerNames().removeIf((name) -> this.namePattern.matcher(name).matches());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -147,7 +147,7 @@ public class UriModifyingOperationPreprocessor implements OperationPreprocessor
|
||||
|
||||
private HttpHeaders modify(HttpHeaders headers) {
|
||||
HttpHeaders modified = new HttpHeaders();
|
||||
for (Entry<String, List<String>> header : headers.entrySet()) {
|
||||
for (Entry<String, List<String>> header : headers.headerSet()) {
|
||||
for (String value : header.getValue()) {
|
||||
modified.add(header.getKey(), this.contentModifier.modify(value));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -210,7 +210,7 @@ public class RestDocumentationConfigurerTests {
|
||||
headers.add("Foo", "value");
|
||||
OperationRequest request = new OperationRequestFactory().create(URI.create("http://localhost:8080"),
|
||||
HttpMethod.GET, null, headers, null, Collections.emptyList());
|
||||
assertThat(preprocessor.preprocess(request).getHeaders()).doesNotContainKey("Foo");
|
||||
assertThat(preprocessor.preprocess(request).getHeaders().headerNames()).doesNotContain("Foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -224,7 +224,7 @@ public class RestDocumentationConfigurerTests {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Foo", "value");
|
||||
OperationResponse response = new OperationResponseFactory().create(HttpStatus.OK, headers, null);
|
||||
assertThat(preprocessor.preprocess(response).getHeaders()).doesNotContainKey("Foo");
|
||||
assertThat(preprocessor.preprocess(response).getHeaders().headerNames()).doesNotContain("Foo");
|
||||
}
|
||||
|
||||
private RestDocumentationContext createContext() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -33,6 +33,7 @@ import org.springframework.restdocs.operation.OperationResponse;
|
||||
import org.springframework.restdocs.operation.OperationResponseFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
* Tests for {@link HeadersModifyingOperationPreprocessor}.
|
||||
@@ -47,60 +48,66 @@ public class HeadersModifyingOperationPreprocessorTests {
|
||||
@Test
|
||||
public void addNewHeader() {
|
||||
this.preprocessor.add("a", "alpha");
|
||||
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders()).containsEntry("a",
|
||||
Arrays.asList("alpha"));
|
||||
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders()).containsEntry("a",
|
||||
Arrays.asList("alpha"));
|
||||
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders().get("a"))
|
||||
.isEqualTo(Arrays.asList("alpha"));
|
||||
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders().get("a"))
|
||||
.isEqualTo(Arrays.asList("alpha"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addValueToExistingHeader() {
|
||||
this.preprocessor.add("a", "alpha");
|
||||
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple"))).getHeaders())
|
||||
.containsEntry("a", Arrays.asList("apple", "alpha"));
|
||||
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple"))).getHeaders())
|
||||
.containsEntry("a", Arrays.asList("apple", "alpha"));
|
||||
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple")))
|
||||
.getHeaders()
|
||||
.headerSet()).contains(entry("a", Arrays.asList("apple", "alpha")));
|
||||
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple")))
|
||||
.getHeaders()
|
||||
.headerSet()).contains(entry("a", Arrays.asList("apple", "alpha")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNewHeader() {
|
||||
this.preprocessor.set("a", "alpha", "avocado");
|
||||
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders()).containsEntry("a",
|
||||
Arrays.asList("alpha", "avocado"));
|
||||
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders()).containsEntry("a",
|
||||
Arrays.asList("alpha", "avocado"));
|
||||
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders().headerSet())
|
||||
.contains(entry("a", Arrays.asList("alpha", "avocado")));
|
||||
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders().headerSet())
|
||||
.contains(entry("a", Arrays.asList("alpha", "avocado")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setExistingHeader() {
|
||||
this.preprocessor.set("a", "alpha", "avocado");
|
||||
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple"))).getHeaders())
|
||||
.containsEntry("a", Arrays.asList("alpha", "avocado"));
|
||||
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple"))).getHeaders())
|
||||
.containsEntry("a", Arrays.asList("alpha", "avocado"));
|
||||
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple")))
|
||||
.getHeaders()
|
||||
.headerSet()).contains(entry("a", Arrays.asList("alpha", "avocado")));
|
||||
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple")))
|
||||
.getHeaders()
|
||||
.headerSet()).contains(entry("a", Arrays.asList("alpha", "avocado")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeNonExistentHeader() {
|
||||
this.preprocessor.remove("a");
|
||||
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders()).doesNotContainKey("a");
|
||||
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders()).doesNotContainKey("a");
|
||||
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders().headerNames()).doesNotContain("a");
|
||||
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders().headerNames()).doesNotContain("a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeHeader() {
|
||||
this.preprocessor.remove("a");
|
||||
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple"))).getHeaders())
|
||||
.doesNotContainKey("a");
|
||||
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple"))).getHeaders())
|
||||
.doesNotContainKey("a");
|
||||
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple")))
|
||||
.getHeaders()
|
||||
.headerNames()).doesNotContain("a");
|
||||
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple")))
|
||||
.getHeaders()
|
||||
.headerNames()).doesNotContain("a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeHeaderValueForNonExistentHeader() {
|
||||
this.preprocessor.remove("a", "apple");
|
||||
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders()).doesNotContainKey("a");
|
||||
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders()).doesNotContainKey("a");
|
||||
assertThat(this.preprocessor.preprocess(createRequest()).getHeaders().headerNames()).doesNotContain("a");
|
||||
assertThat(this.preprocessor.preprocess(createResponse()).getHeaders().headerNames()).doesNotContain("a");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,20 +115,24 @@ public class HeadersModifyingOperationPreprocessorTests {
|
||||
this.preprocessor.remove("a", "apple");
|
||||
assertThat(
|
||||
this.preprocessor.preprocess(createRequest((headers) -> headers.addAll("a", List.of("apple", "alpha"))))
|
||||
.getHeaders())
|
||||
.containsEntry("a", Arrays.asList("alpha"));
|
||||
.getHeaders()
|
||||
.headerSet())
|
||||
.contains(entry("a", Arrays.asList("alpha")));
|
||||
assertThat(this.preprocessor
|
||||
.preprocess(createResponse((headers) -> headers.addAll("a", List.of("apple", "alpha"))))
|
||||
.getHeaders()).containsEntry("a", Arrays.asList("alpha"));
|
||||
.getHeaders()
|
||||
.headerSet()).contains(entry("a", Arrays.asList("alpha")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeHeaderValueWithSingleValueRemovesEntryEntirely() {
|
||||
this.preprocessor.remove("a", "apple");
|
||||
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple"))).getHeaders())
|
||||
.doesNotContainKey("a");
|
||||
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple"))).getHeaders())
|
||||
.doesNotContainKey("a");
|
||||
assertThat(this.preprocessor.preprocess(createRequest((headers) -> headers.add("a", "apple")))
|
||||
.getHeaders()
|
||||
.headerNames()).doesNotContain("a");
|
||||
assertThat(this.preprocessor.preprocess(createResponse((headers) -> headers.add("a", "apple")))
|
||||
.getHeaders()
|
||||
.headerNames()).doesNotContain("a");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,10 +144,10 @@ public class HeadersModifyingOperationPreprocessorTests {
|
||||
headers.add("bravo", "bravo");
|
||||
};
|
||||
this.preprocessor.removeMatching("^a.*");
|
||||
assertThat(this.preprocessor.preprocess(createRequest(headersCustomizer)).getHeaders()).containsOnlyKeys("Host",
|
||||
"bravo");
|
||||
assertThat(this.preprocessor.preprocess(createResponse(headersCustomizer)).getHeaders())
|
||||
.containsOnlyKeys("bravo");
|
||||
assertThat(this.preprocessor.preprocess(createRequest(headersCustomizer)).getHeaders().headerNames())
|
||||
.containsOnly("Host", "bravo");
|
||||
assertThat(this.preprocessor.preprocess(createResponse(headersCustomizer)).getHeaders().headerNames())
|
||||
.containsOnly("bravo");
|
||||
}
|
||||
|
||||
private OperationRequest createRequest() {
|
||||
|
||||
@@ -22,10 +22,3 @@ dependencies {
|
||||
testImplementation("org.hamcrest:hamcrest-library")
|
||||
testImplementation("org.mockito:mockito-core")
|
||||
}
|
||||
|
||||
compatibilityTest {
|
||||
dependency("Spring Framework") { springFramework ->
|
||||
springFramework.groupId = "org.springframework"
|
||||
springFramework.versions = ["6.0.+", "6.2.+"]
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -68,7 +68,7 @@ class MockMvcResponseConverter implements ResponseConverter<MockHttpServletRespo
|
||||
}
|
||||
}
|
||||
|
||||
if (response.getCookies() != null && !headers.containsKey(HttpHeaders.SET_COOKIE)) {
|
||||
if (response.getCookies() != null && !headers.containsHeader(HttpHeaders.SET_COOKIE)) {
|
||||
for (Cookie cookie : response.getCookies()) {
|
||||
headers.add(HttpHeaders.SET_COOKIE, generateSetCookieHeader(cookie));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -37,6 +37,7 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -78,8 +79,8 @@ public class MockMvcRequestConverterTests {
|
||||
MockMvcRequestBuilders.get("/foo").header("a", "alpha", "apple").header("b", "bravo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
assertThat(request.getMethod()).isEqualTo(HttpMethod.GET);
|
||||
assertThat(request.getHeaders()).containsEntry("a", Arrays.asList("alpha", "apple"));
|
||||
assertThat(request.getHeaders()).containsEntry("b", Arrays.asList("bravo"));
|
||||
assertThat(request.getHeaders().headerSet()).contains(entry("a", Arrays.asList("alpha", "apple")),
|
||||
entry("b", Arrays.asList("bravo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -30,6 +30,7 @@ import org.springframework.restdocs.operation.OperationResponse;
|
||||
import org.springframework.restdocs.operation.ResponseCookie;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
* Tests for {@link MockMvcResponseConverter}.
|
||||
@@ -57,9 +58,8 @@ public class MockMvcResponseConverterTests {
|
||||
cookie.setHttpOnly(true);
|
||||
response.addCookie(cookie);
|
||||
OperationResponse operationResponse = this.factory.convert(response);
|
||||
assertThat(operationResponse.getHeaders()).hasSize(1);
|
||||
assertThat(operationResponse.getHeaders()).containsEntry(HttpHeaders.SET_COOKIE,
|
||||
Collections.singletonList("name=value; Domain=localhost; HttpOnly"));
|
||||
assertThat(operationResponse.getHeaders().headerSet()).containsOnly(
|
||||
entry(HttpHeaders.SET_COOKIE, Collections.singletonList("name=value; Domain=localhost; HttpOnly")));
|
||||
assertThat(operationResponse.getCookies()).hasSize(1);
|
||||
assertThat(operationResponse.getCookies()).first().extracting(ResponseCookie::getName).isEqualTo("name");
|
||||
assertThat(operationResponse.getCookies()).first().extracting(ResponseCookie::getValue).isEqualTo("value");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -40,6 +40,7 @@ import org.springframework.restdocs.operation.RequestCookie;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
* Tests for {@link RestAssuredRequestConverter}.
|
||||
@@ -98,10 +99,8 @@ public class RestAssuredRequestConverterTests {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).header("Foo", "bar");
|
||||
requestSpec.get("/");
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getHeaders()).hasSize(2);
|
||||
assertThat(request.getHeaders()).containsEntry("Foo", Collections.singletonList("bar"));
|
||||
assertThat(request.getHeaders()).containsEntry("Host",
|
||||
Collections.singletonList("localhost:" + tomcat.getPort()));
|
||||
assertThat(request.getHeaders().headerSet()).containsOnly(entry("Foo", Collections.singletonList("bar")),
|
||||
entry("Host", Collections.singletonList("localhost:" + tomcat.getPort())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,11 +111,9 @@ public class RestAssuredRequestConverterTests {
|
||||
.accept("application/json");
|
||||
requestSpec.get("/");
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getHeaders()).hasSize(3);
|
||||
assertThat(request.getHeaders()).containsEntry("Foo", Collections.singletonList("bar"));
|
||||
assertThat(request.getHeaders()).containsEntry("Accept", Collections.singletonList("application/json"));
|
||||
assertThat(request.getHeaders()).containsEntry("Host",
|
||||
Collections.singletonList("localhost:" + tomcat.getPort()));
|
||||
assertThat(request.getHeaders().headerSet()).containsOnly(entry("Foo", Collections.singletonList("bar")),
|
||||
entry("Accept", Collections.singletonList("application/json")),
|
||||
entry("Host", Collections.singletonList("localhost:" + tomcat.getPort())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,8 +150,7 @@ public class RestAssuredRequestConverterTests {
|
||||
assertThat(parts).extracting("name").containsExactly("a", "b");
|
||||
assertThat(parts).extracting("submittedFileName").containsExactly("a.txt", "file");
|
||||
assertThat(parts).extracting("contentAsString").containsExactly("alpha", "{\"foo\":\"bar\"}");
|
||||
assertThat(parts).extracting("headers")
|
||||
.extracting(HttpHeaders.CONTENT_TYPE)
|
||||
assertThat(parts).map((part) -> part.getHeaders().get(HttpHeaders.CONTENT_TYPE))
|
||||
.containsExactly(Collections.singletonList(MediaType.TEXT_PLAIN_VALUE),
|
||||
Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
|
||||
}
|
||||
|
||||
@@ -21,10 +21,3 @@ dependencies {
|
||||
|
||||
testRuntimeOnly("org.springframework:spring-context")
|
||||
}
|
||||
|
||||
compatibilityTest {
|
||||
dependency("Spring Framework") { springFramework ->
|
||||
springFramework.groupId = "org.springframework"
|
||||
springFramework.versions = ["6.0.+", "6.2.+"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -46,7 +46,7 @@ class WebTestClientResponseConverter implements ResponseConverter<ExchangeResult
|
||||
|
||||
private HttpHeaders extractHeaders(ExchangeResult result) {
|
||||
HttpHeaders headers = result.getResponseHeaders();
|
||||
if (result.getResponseCookies().isEmpty() || headers.containsKey(HttpHeaders.SET_COOKIE)) {
|
||||
if (result.getResponseCookies().isEmpty() || headers.containsHeader(HttpHeaders.SET_COOKIE)) {
|
||||
return headers;
|
||||
}
|
||||
result.getResponseCookies()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2024 the original author or authors.
|
||||
* Copyright 2014-2025 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.
|
||||
@@ -39,6 +39,7 @@ import org.springframework.web.reactive.function.server.RouterFunctions;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
|
||||
|
||||
@@ -99,8 +100,8 @@ public class WebTestClientRequestConverterTests {
|
||||
OperationRequest request = this.converter.convert(result);
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
assertThat(request.getMethod()).isEqualTo(HttpMethod.GET);
|
||||
assertThat(request.getHeaders()).containsEntry("a", Arrays.asList("alpha", "apple"));
|
||||
assertThat(request.getHeaders()).containsEntry("b", Arrays.asList("bravo"));
|
||||
assertThat(request.getHeaders().headerSet()).contains(entry("a", Arrays.asList("alpha", "apple")),
|
||||
entry("b", Arrays.asList("bravo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -266,7 +267,7 @@ public class WebTestClientRequestConverterTests {
|
||||
OperationRequestPart part = request.getParts().iterator().next();
|
||||
assertThat(part.getName()).isEqualTo("file");
|
||||
assertThat(part.getSubmittedFileName()).isNull();
|
||||
assertThat(part.getHeaders()).hasSize(2);
|
||||
assertThat(part.getHeaders().size()).isEqualTo(2);
|
||||
assertThat(part.getHeaders().getContentLength()).isEqualTo(4L);
|
||||
assertThat(part.getHeaders().getContentDisposition().getName()).isEqualTo("file");
|
||||
assertThat(part.getContent()).containsExactly(1, 2, 3, 4);
|
||||
@@ -303,7 +304,7 @@ public class WebTestClientRequestConverterTests {
|
||||
OperationRequestPart part = request.getParts().iterator().next();
|
||||
assertThat(part.getName()).isEqualTo("file");
|
||||
assertThat(part.getSubmittedFileName()).isEqualTo("image.png");
|
||||
assertThat(part.getHeaders()).hasSize(3);
|
||||
assertThat(part.getHeaders().size()).isEqualTo(3);
|
||||
assertThat(part.getHeaders().getContentLength()).isEqualTo(4);
|
||||
ContentDisposition contentDisposition = part.getHeaders().getContentDisposition();
|
||||
assertThat(contentDisposition.getName()).isEqualTo("file");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2025 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,6 +32,7 @@ import org.springframework.web.reactive.function.server.RouterFunctions;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
|
||||
/**
|
||||
@@ -83,9 +84,8 @@ public class WebTestClientResponseConverterTests {
|
||||
.expectBody()
|
||||
.returnResult();
|
||||
OperationResponse response = this.converter.convert(result);
|
||||
assertThat(response.getHeaders()).hasSize(1);
|
||||
assertThat(response.getHeaders()).containsEntry(HttpHeaders.SET_COOKIE,
|
||||
Collections.singletonList("name=value; Domain=localhost; HttpOnly"));
|
||||
assertThat(response.getHeaders().headerSet()).containsOnly(
|
||||
entry(HttpHeaders.SET_COOKIE, Collections.singletonList("name=value; Domain=localhost; HttpOnly")));
|
||||
assertThat(response.getCookies()).hasSize(1);
|
||||
assertThat(response.getCookies()).first().extracting(ResponseCookie::getName).isEqualTo("name");
|
||||
assertThat(response.getCookies()).first().extracting(ResponseCookie::getValue).isEqualTo("value");
|
||||
|
||||
Reference in New Issue
Block a user