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
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user