toEntityFlux methods apply error status handling

Closes gh-26069
This commit is contained in:
Rossen Stoyanchev
2020-11-12 18:42:21 +00:00
parent 94fcb37d30
commit 42d3bc47c9
2 changed files with 46 additions and 13 deletions

View File

@@ -30,10 +30,12 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.springframework.core.NamedThreadLocal;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -443,6 +445,27 @@ public class DefaultWebClientTests {
verify(predicate2).test(HttpStatus.BAD_REQUEST);
}
@Test // gh-26069
public void onStatusHandlersApplyForToEntityMethods() {
ClientResponse response = ClientResponse.create(HttpStatus.BAD_REQUEST).build();
given(exchangeFunction.exchange(any())).willReturn(Mono.just(response));
WebClient.ResponseSpec spec = this.builder.build().get().uri("/path").retrieve();
testStatusHandlerForToEntity(spec.toEntity(String.class));
testStatusHandlerForToEntity(spec.toEntity(new ParameterizedTypeReference<String>() {}));
testStatusHandlerForToEntity(spec.toEntityList(String.class));
testStatusHandlerForToEntity(spec.toEntityList(new ParameterizedTypeReference<String>() {}));
testStatusHandlerForToEntity(spec.toEntityFlux(String.class));
testStatusHandlerForToEntity(spec.toEntityFlux(new ParameterizedTypeReference<String>() {}));
}
private void testStatusHandlerForToEntity(Publisher<?> responsePublisher) {
StepVerifier.create(responsePublisher).expectError(WebClientResponseException.class).verify();
}
private ClientRequest verifyAndGetRequest() {
ClientRequest request = this.captor.getValue();
verify(this.exchangeFunction).exchange(request);