Remove APIs marked as deprecated for removal
Closes gh-33809
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.http;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -279,221 +278,6 @@ class MediaTypeTests {
|
||||
assertThat(audioBasic.isLessSpecific(MediaType.TEXT_HTML)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void specificityComparator() {
|
||||
MediaType audioBasic = new MediaType("audio", "basic");
|
||||
MediaType audioWave = new MediaType("audio", "wave");
|
||||
MediaType audio = new MediaType("audio");
|
||||
MediaType audio03 = new MediaType("audio", "*", 0.3);
|
||||
MediaType audio07 = new MediaType("audio", "*", 0.7);
|
||||
MediaType audioBasicLevel = new MediaType("audio", "basic", Collections.singletonMap("level", "1"));
|
||||
MediaType textHtml = new MediaType("text", "html");
|
||||
MediaType allXml = new MediaType("application", "*+xml");
|
||||
MediaType all = MediaType.ALL;
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
Comparator<MediaType> comp = MediaType.SPECIFICITY_COMPARATOR;
|
||||
|
||||
// equal
|
||||
assertThat(comp.compare(audioBasic, audioBasic)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audio, audio)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audio07, audio07)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audio03, audio03)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audioBasicLevel, audioBasicLevel)).as("Invalid comparison result").isEqualTo(0);
|
||||
|
||||
// specific to unspecific
|
||||
assertThat(comp.compare(audioBasic, audio)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(audioBasic, all)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(audio, all)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(MediaType.APPLICATION_XHTML_XML, allXml)).as("Invalid comparison result").isLessThan(0);
|
||||
|
||||
// unspecific to specific
|
||||
assertThat(comp.compare(audio, audioBasic)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(allXml, MediaType.APPLICATION_XHTML_XML)).as("Invalid comparison result")
|
||||
.isGreaterThan(0);
|
||||
assertThat(comp.compare(all, audioBasic)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(all, audio)).as("Invalid comparison result").isGreaterThan(0);
|
||||
|
||||
// qualifiers
|
||||
assertThat(comp.compare(audio, audio07)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(audio07, audio)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(audio07, audio03)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(audio03, audio07)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(audio03, all)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(all, audio03)).as("Invalid comparison result").isGreaterThan(0);
|
||||
|
||||
// other parameters
|
||||
assertThat(comp.compare(audioBasic, audioBasicLevel)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(audioBasicLevel, audioBasic)).as("Invalid comparison result").isLessThan(0);
|
||||
|
||||
// different types
|
||||
assertThat(comp.compare(audioBasic, textHtml)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(textHtml, audioBasic)).as("Invalid comparison result").isEqualTo(0);
|
||||
|
||||
// different subtypes
|
||||
assertThat(comp.compare(audioBasic, audioWave)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audioWave, audioBasic)).as("Invalid comparison result").isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("removal")
|
||||
public void sortBySpecificityRelated() {
|
||||
MediaType audioBasic = new MediaType("audio", "basic");
|
||||
MediaType audio = new MediaType("audio");
|
||||
MediaType audio03 = new MediaType("audio", "*", 0.3);
|
||||
MediaType audio07 = new MediaType("audio", "*", 0.7);
|
||||
MediaType audioBasicLevel = new MediaType("audio", "basic", Collections.singletonMap("level", "1"));
|
||||
MediaType all = MediaType.ALL;
|
||||
|
||||
List<MediaType> expected = new ArrayList<>();
|
||||
expected.add(audioBasicLevel);
|
||||
expected.add(audioBasic);
|
||||
expected.add(audio);
|
||||
expected.add(audio07);
|
||||
expected.add(audio03);
|
||||
expected.add(all);
|
||||
|
||||
List<MediaType> result = new ArrayList<>(expected);
|
||||
Random rnd = new Random();
|
||||
// shuffle & sort 10 times
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Collections.shuffle(result, rnd);
|
||||
MediaType.sortBySpecificity(result);
|
||||
|
||||
for (int j = 0; j < result.size(); j++) {
|
||||
assertThat(result.get(j)).as("Invalid media type at " + j).isSameAs(expected.get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("removal")
|
||||
public void sortBySpecificityUnrelated() {
|
||||
MediaType audioBasic = new MediaType("audio", "basic");
|
||||
MediaType audioWave = new MediaType("audio", "wave");
|
||||
MediaType textHtml = new MediaType("text", "html");
|
||||
|
||||
List<MediaType> expected = new ArrayList<>();
|
||||
expected.add(textHtml);
|
||||
expected.add(audioBasic);
|
||||
expected.add(audioWave);
|
||||
|
||||
List<MediaType> result = new ArrayList<>(expected);
|
||||
MediaType.sortBySpecificity(result);
|
||||
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertThat(result.get(i)).as("Invalid media type at " + i).isSameAs(expected.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void qualityComparator() {
|
||||
MediaType audioBasic = new MediaType("audio", "basic");
|
||||
MediaType audioWave = new MediaType("audio", "wave");
|
||||
MediaType audio = new MediaType("audio");
|
||||
MediaType audio03 = new MediaType("audio", "*", 0.3);
|
||||
MediaType audio07 = new MediaType("audio", "*", 0.7);
|
||||
MediaType audioBasicLevel = new MediaType("audio", "basic", Collections.singletonMap("level", "1"));
|
||||
MediaType textHtml = new MediaType("text", "html");
|
||||
MediaType allXml = new MediaType("application", "*+xml");
|
||||
MediaType all = MediaType.ALL;
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
Comparator<MediaType> comp = MediaType.QUALITY_VALUE_COMPARATOR;
|
||||
|
||||
// equal
|
||||
assertThat(comp.compare(audioBasic, audioBasic)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audio, audio)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audio07, audio07)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audio03, audio03)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audioBasicLevel, audioBasicLevel)).as("Invalid comparison result").isEqualTo(0);
|
||||
|
||||
// specific to unspecific
|
||||
assertThat(comp.compare(audioBasic, audio)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(audioBasic, all)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(audio, all)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(MediaType.APPLICATION_XHTML_XML, allXml)).as("Invalid comparison result").isLessThan(0);
|
||||
|
||||
// unspecific to specific
|
||||
assertThat(comp.compare(audio, audioBasic)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(all, audioBasic)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(all, audio)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(allXml, MediaType.APPLICATION_XHTML_XML)).as("Invalid comparison result")
|
||||
.isGreaterThan(0);
|
||||
|
||||
// qualifiers
|
||||
assertThat(comp.compare(audio, audio07)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(audio07, audio)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(audio07, audio03)).as("Invalid comparison result").isLessThan(0);
|
||||
assertThat(comp.compare(audio03, audio07)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(audio03, all)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(all, audio03)).as("Invalid comparison result").isLessThan(0);
|
||||
|
||||
// other parameters
|
||||
assertThat(comp.compare(audioBasic, audioBasicLevel)).as("Invalid comparison result").isGreaterThan(0);
|
||||
assertThat(comp.compare(audioBasicLevel, audioBasic)).as("Invalid comparison result").isLessThan(0);
|
||||
|
||||
// different types
|
||||
assertThat(comp.compare(audioBasic, textHtml)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(textHtml, audioBasic)).as("Invalid comparison result").isEqualTo(0);
|
||||
|
||||
// different subtypes
|
||||
assertThat(comp.compare(audioBasic, audioWave)).as("Invalid comparison result").isEqualTo(0);
|
||||
assertThat(comp.compare(audioWave, audioBasic)).as("Invalid comparison result").isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("removal")
|
||||
public void sortByQualityRelated() {
|
||||
MediaType audioBasic = new MediaType("audio", "basic");
|
||||
MediaType audio = new MediaType("audio");
|
||||
MediaType audio03 = new MediaType("audio", "*", 0.3);
|
||||
MediaType audio07 = new MediaType("audio", "*", 0.7);
|
||||
MediaType audioBasicLevel = new MediaType("audio", "basic", Collections.singletonMap("level", "1"));
|
||||
MediaType all = MediaType.ALL;
|
||||
|
||||
List<MediaType> expected = new ArrayList<>();
|
||||
expected.add(audioBasicLevel);
|
||||
expected.add(audioBasic);
|
||||
expected.add(audio);
|
||||
expected.add(all);
|
||||
expected.add(audio07);
|
||||
expected.add(audio03);
|
||||
|
||||
List<MediaType> result = new ArrayList<>(expected);
|
||||
Random rnd = new Random();
|
||||
// shuffle & sort 10 times
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Collections.shuffle(result, rnd);
|
||||
MediaType.sortByQualityValue(result);
|
||||
|
||||
for (int j = 0; j < result.size(); j++) {
|
||||
assertThat(result.get(j)).as("Invalid media type at " + j).isSameAs(expected.get(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("removal")
|
||||
public void sortByQualityUnrelated() {
|
||||
MediaType audioBasic = new MediaType("audio", "basic");
|
||||
MediaType audioWave = new MediaType("audio", "wave");
|
||||
MediaType textHtml = new MediaType("text", "html");
|
||||
|
||||
List<MediaType> expected = new ArrayList<>();
|
||||
expected.add(textHtml);
|
||||
expected.add(audioBasic);
|
||||
expected.add(audioWave);
|
||||
|
||||
List<MediaType> result = new ArrayList<>(expected);
|
||||
MediaType.sortBySpecificity(result);
|
||||
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertThat(result.get(i)).as("Invalid media type at " + i).isSameAs(expected.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithConversionService() {
|
||||
ConversionService conversionService = new DefaultConversionService();
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2024 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http.client;
|
||||
|
||||
/**
|
||||
* Tests for {@link BufferingClientHttpRequestWrapper} for clients
|
||||
* not supporting non-null, empty request bodies for GET requests.
|
||||
*/
|
||||
class BufferingClientHttpRequestFactoryWithOkHttpTests extends AbstractHttpRequestFactoryTests {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
protected ClientHttpRequestFactory createRequestFactory() {
|
||||
return new BufferingClientHttpRequestFactory(new OkHttp3ClientHttpRequestFactory());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2024 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http.client;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
/**
|
||||
* @author Roy Clarkson
|
||||
*/
|
||||
class OkHttp3ClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@Override
|
||||
protected ClientHttpRequestFactory createRequestFactory() {
|
||||
return new OkHttp3ClientHttpRequestFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
void httpMethods() throws Exception {
|
||||
super.httpMethods();
|
||||
assertHttpMethod("patch", HttpMethod.PATCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,12 +76,10 @@ class RestClientIntegrationTests {
|
||||
@interface ParameterizedRestClientTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
static Stream<Arguments> clientHttpRequestFactories() {
|
||||
return Stream.of(
|
||||
argumentSet("JDK HttpURLConnection", new SimpleClientHttpRequestFactory()),
|
||||
argumentSet("HttpComponents", new HttpComponentsClientHttpRequestFactory()),
|
||||
argumentSet("OkHttp", new org.springframework.http.client.OkHttp3ClientHttpRequestFactory()),
|
||||
argumentSet("Jetty", new JettyClientHttpRequestFactory()),
|
||||
argumentSet("JDK HttpClient", new JdkClientHttpRequestFactory()),
|
||||
argumentSet("Reactor Netty", new ReactorClientHttpRequestFactory())
|
||||
|
||||
@@ -90,12 +90,10 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
|
||||
@interface ParameterizedRestTemplateTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
static Stream<Arguments> clientHttpRequestFactories() {
|
||||
return Stream.of(
|
||||
argumentSet("JDK HttpURLConnection", new SimpleClientHttpRequestFactory()),
|
||||
argumentSet("HttpComponents", new HttpComponentsClientHttpRequestFactory()),
|
||||
argumentSet("OkHttp", new org.springframework.http.client.OkHttp3ClientHttpRequestFactory()),
|
||||
argumentSet("Jetty", new JettyClientHttpRequestFactory()),
|
||||
argumentSet("JDK HttpClient", new JdkClientHttpRequestFactory()),
|
||||
argumentSet("Reactor Netty", new ReactorClientHttpRequestFactory())
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2023 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.filter.reactive;
|
||||
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import io.micrometer.observation.Observation;
|
||||
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
|
||||
import io.micrometer.observation.tck.TestObservationRegistry;
|
||||
import io.micrometer.observation.tck.TestObservationRegistryAssert;
|
||||
import org.assertj.core.api.ThrowingConsumer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.http.server.reactive.observation.ServerRequestObservationContext;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ServerHttpObservationFilter}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
class ServerHttpObservationFilterTests {
|
||||
|
||||
private final TestObservationRegistry observationRegistry = TestObservationRegistry.create();
|
||||
|
||||
private final ServerHttpObservationFilter filter = new ServerHttpObservationFilter(this.observationRegistry);
|
||||
|
||||
@Test
|
||||
void filterShouldFillObservationContext() {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/test/resource"));
|
||||
exchange.getResponse().setRawStatusCode(200);
|
||||
WebFilterChain filterChain = createFilterChain(filterExchange -> {
|
||||
Optional<ServerRequestObservationContext> observationContext = ServerHttpObservationFilter.findObservationContext(filterExchange);
|
||||
assertThat(observationContext).isPresent();
|
||||
assertThat(observationContext.get().getCarrier()).isEqualTo(exchange.getRequest());
|
||||
assertThat(observationContext.get().getResponse()).isEqualTo(exchange.getResponse());
|
||||
});
|
||||
this.filter.filter(exchange, filterChain).block();
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("outcome", "SUCCESS");
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterShouldAddNewObservationToReactorContext() {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/test/resource"));
|
||||
exchange.getResponse().setRawStatusCode(200);
|
||||
WebFilterChain filterChain = webExchange -> Mono.deferContextual(contextView -> {
|
||||
Observation observation = contextView.get(ObservationThreadLocalAccessor.KEY);
|
||||
assertThat(observation).isNotNull();
|
||||
// check that the observation was started
|
||||
assertThat(observation.getContext().getLowCardinalityKeyValue("outcome")).isNotNull();
|
||||
return Mono.empty();
|
||||
});
|
||||
this.filter.filter(exchange, filterChain).block();
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("outcome", "SUCCESS");
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterShouldUseThrownException() {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/test/resource"));
|
||||
exchange.getResponse().setRawStatusCode(500);
|
||||
WebFilterChain filterChain = createFilterChain(filterExchange -> {
|
||||
throw new IllegalArgumentException("server error");
|
||||
});
|
||||
StepVerifier.create(this.filter.filter(exchange, filterChain))
|
||||
.expectError(IllegalArgumentException.class)
|
||||
.verify();
|
||||
Optional<ServerRequestObservationContext> observationContext = ServerHttpObservationFilter.findObservationContext(exchange);
|
||||
assertThat(observationContext.get().getError()).isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("outcome", "SERVER_ERROR");
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterShouldRecordObservationWhenCancelled() {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/test/resource"));
|
||||
exchange.getResponse().setRawStatusCode(200);
|
||||
WebFilterChain filterChain = createFilterChain(filterExchange -> {
|
||||
});
|
||||
StepVerifier.create(this.filter.filter(exchange, filterChain))
|
||||
.thenCancel()
|
||||
.verify();
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("outcome", "UNKNOWN");
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterShouldStopObservationOnResponseCommit() {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/test/resource"));
|
||||
WebFilterChain filterChain = createFilterChain(filterExchange -> {
|
||||
throw new IllegalArgumentException("server error");
|
||||
});
|
||||
StepVerifier.create(this.filter.filter(exchange, filterChain).doOnError(throwable -> {
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
response.setRawStatusCode(500);
|
||||
response.setComplete().block();
|
||||
}))
|
||||
.expectError(IllegalArgumentException.class)
|
||||
.verify();
|
||||
Optional<ServerRequestObservationContext> observationContext = ServerHttpObservationFilter.findObservationContext(exchange);
|
||||
assertThat(observationContext.get().getError()).isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatHttpObservation().hasLowCardinalityKeyValue("outcome", "SERVER_ERROR");
|
||||
}
|
||||
|
||||
|
||||
private WebFilterChain createFilterChain(ThrowingConsumer<ServerWebExchange> exchangeConsumer) {
|
||||
return filterExchange -> {
|
||||
try {
|
||||
exchangeConsumer.accept(filterExchange);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
return Mono.empty();
|
||||
};
|
||||
}
|
||||
|
||||
private TestObservationRegistryAssert.TestObservationRegistryAssertReturningObservationContextAssert assertThatHttpObservation() {
|
||||
return assertThat(this.observationRegistry).hasObservationWithNameEqualTo("http.server.requests").that();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user