From 5ea0674bad7cb3a89c33af51a6cd654e6af7f72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Wed, 7 May 2025 13:09:53 -0700 Subject: [PATCH] Migrate to new HttpHeaders API See gh-45487 Co-authored-by: Phillip Webb --- .../tracing/zipkin/HttpSender.java | 20 +++++----- .../zipkin/ZipkinHttpClientSender.java | 9 ++--- .../reactive/RecordableServerHttpRequest.java | 10 +++-- .../RecordableServerHttpResponse.java | 7 +++- .../web/exchanges/HttpExchangeTests.java | 38 ++++++++++--------- .../RestTemplateAutoConfigurationTests.java | 5 ++- .../livereload/LiveReloadServerTests.java | 4 +- .../web/client/TestRestTemplateTests.java | 4 +- .../boot/web/client/BasicAuthentication.java | 2 +- .../web/client/RestTemplateBuilderTests.java | 12 +++--- ...AbstractReactiveWebServerFactoryTests.java | 2 +- ...ractSampleActuatorCustomSecurityTests.java | 4 +- ...entPathSampleActuatorApplicationTests.java | 4 +- .../SampleActuatorApplicationTests.java | 4 +- ...letPathSampleActuatorApplicationTests.java | 4 +- .../MessageControllerWebTests.java | 4 +- .../thymeleaf/MessageControllerWebTests.java | 4 +- 17 files changed, 73 insertions(+), 64 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/HttpSender.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/HttpSender.java index 2d0b6db80c..f15e291d2a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/HttpSender.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/HttpSender.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -19,7 +19,9 @@ package org.springframework.boot.actuate.autoconfigure.tracing.zipkin; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URI; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.zip.GZIPOutputStream; import zipkin2.reporter.BaseHttpSender; @@ -27,8 +29,6 @@ import zipkin2.reporter.BytesMessageSender; import zipkin2.reporter.Encoding; import zipkin2.reporter.HttpEndpointSupplier.Factory; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.util.unit.DataSize; /** @@ -61,20 +61,20 @@ abstract class HttpSender extends BaseHttpSender { @Override protected void postSpans(URI endpoint, byte[] body) throws IOException { - MultiValueMap headers = getDefaultHeaders(); + Map headers = getDefaultHeaders(); if (needsCompression(body)) { body = compress(body); - headers.add("Content-Encoding", "gzip"); + headers.put("Content-Encoding", "gzip"); } postSpans(endpoint, headers, body); } - abstract void postSpans(URI endpoint, MultiValueMap headers, byte[] body) throws IOException; + abstract void postSpans(URI endpoint, Map headers, byte[] body) throws IOException; - MultiValueMap getDefaultHeaders() { - MultiValueMap headers = new LinkedMultiValueMap<>(); - headers.add("b3", "0"); - headers.add("Content-Type", this.encoding.mediaType()); + Map getDefaultHeaders() { + Map headers = new LinkedHashMap<>(); + headers.put("b3", "0"); + headers.put("Content-Type", this.encoding.mediaType()); return headers; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/ZipkinHttpClientSender.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/ZipkinHttpClientSender.java index 8fa737f78c..148b100f8a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/ZipkinHttpClientSender.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/ZipkinHttpClientSender.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -25,12 +25,11 @@ import java.net.http.HttpRequest.Builder; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.time.Duration; +import java.util.Map; import zipkin2.reporter.Encoding; import zipkin2.reporter.HttpEndpointSupplier.Factory; -import org.springframework.util.MultiValueMap; - /** * A {@link HttpSender} which uses the JDK {@link HttpClient} for HTTP communication. * @@ -50,12 +49,12 @@ class ZipkinHttpClientSender extends HttpSender { } @Override - void postSpans(URI endpoint, MultiValueMap headers, byte[] body) throws IOException { + void postSpans(URI endpoint, Map headers, byte[] body) throws IOException { Builder request = HttpRequest.newBuilder() .POST(BodyPublishers.ofByteArray(body)) .uri(endpoint) .timeout(this.readTimeout); - headers.forEach((name, values) -> values.forEach((value) -> request.header(name, value))); + headers.forEach((name, value) -> request.header(name, value)); try { HttpResponse response = this.httpClient.send(request.build(), BodyHandlers.discarding()); if (response.statusCode() / 100 != 2) { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/exchanges/reactive/RecordableServerHttpRequest.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/exchanges/reactive/RecordableServerHttpRequest.java index 2fcc197cb1..cda765aa92 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/exchanges/reactive/RecordableServerHttpRequest.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/exchanges/reactive/RecordableServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-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. @@ -19,11 +19,13 @@ package org.springframework.boot.actuate.web.exchanges.reactive; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.springframework.boot.actuate.web.exchanges.RecordableHttpRequest; +import org.springframework.http.HttpHeaders; import org.springframework.http.server.reactive.ServerHttpRequest; /** @@ -35,7 +37,7 @@ class RecordableServerHttpRequest implements RecordableHttpRequest { private final String method; - private final Map> headers; + private final HttpHeaders headers; private final URI uri; @@ -66,7 +68,9 @@ class RecordableServerHttpRequest implements RecordableHttpRequest { @Override public Map> getHeaders() { - return new LinkedHashMap<>(this.headers); + Map> headers = new LinkedHashMap<>(); + this.headers.forEach(headers::put); + return Collections.unmodifiableMap(headers); } @Override diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/exchanges/reactive/RecordableServerHttpResponse.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/exchanges/reactive/RecordableServerHttpResponse.java index cc00832e8f..3faa76ce68 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/exchanges/reactive/RecordableServerHttpResponse.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/exchanges/reactive/RecordableServerHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.web.exchanges.reactive; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -38,7 +39,9 @@ class RecordableServerHttpResponse implements RecordableHttpResponse { RecordableServerHttpResponse(ServerHttpResponse response) { this.status = (response.getStatusCode() != null) ? response.getStatusCode().value() : HttpStatus.OK.value(); - this.headers = new LinkedHashMap<>(response.getHeaders()); + Map> headers = new LinkedHashMap<>(); + response.getHeaders().forEach(headers::put); + this.headers = Collections.unmodifiableMap(headers); } @Override diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/exchanges/HttpExchangeTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/exchanges/HttpExchangeTests.java index 97cd4d898f..927910d8ab 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/exchanges/HttpExchangeTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/exchanges/HttpExchangeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -23,11 +23,8 @@ import java.time.Duration; import java.time.Instant; import java.time.ZoneId; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.function.Supplier; import org.junit.jupiter.api.Test; @@ -47,14 +44,11 @@ import static org.mockito.Mockito.mock; */ class HttpExchangeTests { - private static final Map> AUTHORIZATION_HEADER = Map.of(HttpHeaders.AUTHORIZATION, - Arrays.asList("secret")); + private static final HttpHeaders AUTHORIZATION_HEADER = ofSingleHttpHeader(HttpHeaders.AUTHORIZATION, "secret"); - private static final Map> COOKIE_HEADER = Map.of(HttpHeaders.COOKIE, - Arrays.asList("test=test")); + private static final HttpHeaders COOKIE_HEADER = ofSingleHttpHeader(HttpHeaders.COOKIE, "test=test"); - private static final Map> SET_COOKIE_HEADER = Map.of(HttpHeaders.SET_COOKIE, - Arrays.asList("test=test")); + private static final HttpHeaders SET_COOKIE_HEADER = ofSingleHttpHeader(HttpHeaders.SET_COOKIE, "test=test"); private static final Supplier NO_PRINCIPAL = () -> null; @@ -298,31 +292,33 @@ class HttpExchangeTests { } private RecordableHttpRequest createRequest() { - return createRequest(Collections.singletonMap(HttpHeaders.ACCEPT, Arrays.asList("application/json"))); + return createRequest(ofSingleHttpHeader(HttpHeaders.ACCEPT, "application/json")); } - private RecordableHttpRequest createRequest(Map> headers) { + @SuppressWarnings("removal") + private RecordableHttpRequest createRequest(HttpHeaders headers) { RecordableHttpRequest request = mock(RecordableHttpRequest.class); given(request.getMethod()).willReturn("GET"); given(request.getUri()).willReturn(URI.create("https://api.example.com")); - given(request.getHeaders()).willReturn(new HashMap<>(headers)); + given(request.getHeaders()).willReturn(new HashMap<>(headers.asMultiValueMap())); given(request.getRemoteAddress()).willReturn("127.0.0.1"); return request; } private RecordableHttpResponse createResponse() { - return createResponse(Collections.singletonMap(HttpHeaders.CONTENT_TYPE, Arrays.asList("application/json"))); + return createResponse(ofSingleHttpHeader(HttpHeaders.CONTENT_TYPE, "application/json")); } - private RecordableHttpResponse createResponse(Map> headers) { + @SuppressWarnings("removal") + private RecordableHttpResponse createResponse(HttpHeaders headers) { RecordableHttpResponse response = mock(RecordableHttpResponse.class); given(response.getStatus()).willReturn(204); - given(response.getHeaders()).willReturn(new HashMap<>(headers)); + given(response.getHeaders()).willReturn(new HashMap<>(headers.asMultiValueMap())); return response; } - private Map> mixedCase(Map> headers) { - Map> result = new LinkedHashMap<>(); + private HttpHeaders mixedCase(HttpHeaders headers) { + HttpHeaders result = new HttpHeaders(); headers.forEach((key, value) -> result.put(mixedCase(key), value)); return result; } @@ -336,4 +332,10 @@ class HttpExchangeTests { return output.toString(); } + private static HttpHeaders ofSingleHttpHeader(String header, String... values) { + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.put(header, List.of(values)); + return httpHeaders; + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java index 43d718ab41..676ad4a1e6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -45,6 +45,7 @@ import org.springframework.mock.http.client.MockClientHttpResponse; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; @@ -168,7 +169,7 @@ class RestTemplateAutoConfigurationTests { given(requestFactory.createRequest(any(), any())).willReturn(request); RestTemplate restTemplate = builder.requestFactory(() -> requestFactory).build(); restTemplate.getForEntity("http://localhost:8080/test", String.class); - assertThat(request.getHeaders()).containsEntry("spring", Collections.singletonList("boot")); + assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("boot"))); }); } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java index ff47af1b27..5f86a9be74 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -342,7 +342,7 @@ class LiveReloadServerTests { requestHeaders.forEach((key, value) -> uppercaseRequestHeaders.put(key.toUpperCase(Locale.ROOT), value)); requestHeaders.clear(); requestHeaders.putAll(uppercaseRequestHeaders); - requestHeaders.putAll(this.headers); + this.headers.forEach(requestHeaders::put); } @Override diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java index 8b0d55a59c..ed0d981bfd 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/TestRestTemplateTests.java @@ -481,10 +481,10 @@ class TestRestTemplateTests { ClientHttpRequest request = ReflectionTestUtils.invokeMethod(testRestTemplate.getRestTemplate(), "createRequest", URI.create("http://localhost"), HttpMethod.POST); if (username == null) { - assertThat(request.getHeaders()).doesNotContainKey(HttpHeaders.AUTHORIZATION); + assertThat(request.getHeaders().headerNames()).doesNotContain(HttpHeaders.AUTHORIZATION); } else { - assertThat(request.getHeaders()).containsKeys(HttpHeaders.AUTHORIZATION); + assertThat(request.getHeaders().headerNames()).contains(HttpHeaders.AUTHORIZATION); assertThat(request.getHeaders().get(HttpHeaders.AUTHORIZATION)).containsExactly("Basic " + Base64.getEncoder().encodeToString(String.format("%s:%s", username, password).getBytes())); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/BasicAuthentication.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/BasicAuthentication.java index fd49a34160..e76c2d8ce0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/BasicAuthentication.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/BasicAuthentication.java @@ -44,7 +44,7 @@ class BasicAuthentication { } void applyTo(HttpHeaders headers) { - if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { + if (!headers.containsHeader(HttpHeaders.AUTHORIZATION)) { headers.setBasicAuth(this.username, this.password, this.charset); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java index b9c7a44f3c..3f77ed1bc0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java @@ -319,7 +319,7 @@ class RestTemplateBuilderTests { void basicAuthenticationShouldApply() { RestTemplate template = this.builder.basicAuthentication("spring", "boot", StandardCharsets.UTF_8).build(); ClientHttpRequest request = createRequest(template); - assertThat(request.getHeaders()).containsOnlyKeys(HttpHeaders.AUTHORIZATION); + assertThat(request.getHeaders().headerNames()).containsOnly(HttpHeaders.AUTHORIZATION); assertThat(request.getHeaders().get(HttpHeaders.AUTHORIZATION)).containsExactly("Basic c3ByaW5nOmJvb3Q="); } @@ -327,7 +327,7 @@ class RestTemplateBuilderTests { void defaultHeaderAddsHeader() { RestTemplate template = this.builder.defaultHeader("spring", "boot").build(); ClientHttpRequest request = createRequest(template); - assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("boot"))); + assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("boot"))); } @Test @@ -336,7 +336,7 @@ class RestTemplateBuilderTests { String[] values = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }; RestTemplate template = this.builder.defaultHeader(name, values).build(); ClientHttpRequest request = createRequest(template); - assertThat(request.getHeaders()).contains(entry(name, Arrays.asList(values))); + assertThat(request.getHeaders().headerSet()).contains(entry(name, Arrays.asList(values))); } @Test // gh-17885 @@ -344,7 +344,7 @@ class RestTemplateBuilderTests { RestTemplate template = this.builder.defaultHeader("spring", "boot").build(); MockRestServiceServer.bindTo(template).build(); ClientHttpRequest request = createRequest(template); - assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("boot"))); + assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("boot"))); } @Test @@ -361,7 +361,7 @@ class RestTemplateBuilderTests { .requestCustomizers((request) -> request.getHeaders().add("spring", "framework")) .build(); ClientHttpRequest request = createRequest(template); - assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("framework"))); + assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("framework"))); } @Test @@ -371,7 +371,7 @@ class RestTemplateBuilderTests { .additionalRequestCustomizers((request) -> request.getHeaders().add("for", "java")) .build(); ClientHttpRequest request = createRequest(template); - assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("framework"))) + assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("framework"))) .contains(entry("for", Collections.singletonList("java"))); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java index 96be488e32..66ae7af74a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java @@ -662,7 +662,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { protected void assertResponseIsNotCompressed(ResponseEntity response) { assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getHeaders().keySet()).doesNotContain("X-Test-Compressed"); + assertThat(response.getHeaders().headerNames()).doesNotContain("X-Test-Compressed"); } protected void assertForwardHeaderIsUsed(AbstractReactiveWebServerFactory factory) { diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/AbstractSampleActuatorCustomSecurityTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/AbstractSampleActuatorCustomSecurityTests.java index 6f40eb7cf6..74bde72561 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/AbstractSampleActuatorCustomSecurityTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/AbstractSampleActuatorCustomSecurityTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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 @@ abstract class AbstractSampleActuatorCustomSecurityTests { @SuppressWarnings("rawtypes") ResponseEntity entity = restTemplate().getForEntity(getPath() + "/", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); + assertThat(entity.getHeaders().headerNames()).doesNotContain("Set-Cookie"); } @Test diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java index ae97c9a256..efab8e347d 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -53,7 +53,7 @@ class ManagementPathSampleActuatorApplicationTests { void testHomeIsSecure() { ResponseEntity> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); + assertThat(entity.getHeaders().headerNames()).doesNotContain("Set-Cookie"); } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java index ca12587bf8..1fdec515c8 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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 @@ class SampleActuatorApplicationTests { void testHomeIsSecure() { ResponseEntity> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); + assertThat(entity.getHeaders().headerNames()).doesNotContain("Set-Cookie"); } @Test diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java index 87e9d3330d..0ad7a9572e 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -61,7 +61,7 @@ class ServletPathSampleActuatorApplicationTests { void testHomeIsSecure() { ResponseEntity> entity = asMapEntity(this.restTemplate.getForEntity("/spring/", Map.class)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); + assertThat(entity.getHeaders().headerNames()).doesNotContain("Set-Cookie"); } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/MessageControllerWebTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/MessageControllerWebTests.java index eee8695591..92e44b6802 100755 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/MessageControllerWebTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/MessageControllerWebTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -54,7 +54,7 @@ class MessageControllerWebTests { assertThat(this.mvc.post().uri("/").param("text", "FOO text").param("summary", "FOO")) .hasStatus(HttpStatus.FOUND) .headers() - .hasEntrySatisfying("Location", + .hasHeaderSatisfying("Location", (values) -> assertThat(values).hasSize(1) .element(0) .satisfies(HamcrestCondition.matching(RegexMatcher.matches("/[0-9]+")))); diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-thymeleaf/src/test/java/smoketest/web/thymeleaf/MessageControllerWebTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-thymeleaf/src/test/java/smoketest/web/thymeleaf/MessageControllerWebTests.java index bee99a23c0..c61b26f96b 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-thymeleaf/src/test/java/smoketest/web/thymeleaf/MessageControllerWebTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-thymeleaf/src/test/java/smoketest/web/thymeleaf/MessageControllerWebTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -54,7 +54,7 @@ class MessageControllerWebTests { assertThat(this.mvc.post().uri("/").param("text", "FOO text").param("summary", "FOO")) .hasStatus(HttpStatus.FOUND) .headers() - .hasEntrySatisfying("Location", + .hasHeaderSatisfying("Location", (values) -> assertThat(values).hasSize(1) .element(0) .satisfies(HamcrestCondition.matching(RegexMatcher.matches("/[0-9]+"))));