import java.net.URI;
import java.nio.charset.Charset;
import java.time.ZonedDateTime;
+import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
+import java.util.function.IntPredicate;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.http.client.reactive.ClientHttpRequest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec;
import org.springframework.web.reactive.function.client.WebClient.ResponseSpec;
import org.springframework.web.util.UriBuilder;
+import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
static class WebClientStub implements WebClient
{
final static WebClientStub WEB_CLIENT = new WebClientStub();
- final static RequestHeadersUriSpecStub URI_SPEC = new RequestHeadersUriSpecStub();
- final static RequestBodySpecStub BODY_SPEC = new RequestBodySpecStub();
+ final static RequestHeadersUriSpecStub HEADERS_SPEC = new RequestHeadersUriSpecStub();
+ final static RequestBodySpecStub REQUEST_BODY_SPEC = new RequestBodySpecStub();
+ final static ResponseSpecStub RESPONSE_SPEC = new ResponseSpecStub();
+
+ static Supplier<Mono<?>> toMono;
+ static Supplier<Flux<?>> toFlux;
private WebClientStub() {}
@Override
public RequestHeadersUriSpec<?> get()
{
- return URI_SPEC;
+ return HEADERS_SPEC;
}
@Override
public RequestHeadersUriSpec<?> head()
{
- return URI_SPEC;
+ return HEADERS_SPEC;
}
@Override
public RequestBodyUriSpec post()
{
- return BODY_SPEC;
+ return REQUEST_BODY_SPEC;
}
@Override
public RequestBodyUriSpec put()
{
- return BODY_SPEC;
+ return REQUEST_BODY_SPEC;
}
@Override
public RequestBodyUriSpec patch()
{
- return BODY_SPEC;
+ return REQUEST_BODY_SPEC;
}
@Override
public RequestHeadersUriSpec<?> delete()
{
- return URI_SPEC;
+ return HEADERS_SPEC;
}
@Override
public RequestHeadersUriSpec<?> options()
{
- return URI_SPEC;
+ return HEADERS_SPEC;
}
@Override
public RequestBodyUriSpec method(HttpMethod hm)
{
- return BODY_SPEC;
+ return REQUEST_BODY_SPEC;
}
@Override
@Override
public ResponseSpec retrieve()
{
+ return RESPONSE_SPEC;
}
@Override
public Mono exchange()
{
+ return WebClientStub.toMono.get();
}
}
return this;
}
}
+
+ static class ResponseSpecStub implements ResponseSpec
+ {
+ private ResponseSpecStub() {}
+
+
+ @Override
+ public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate, Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction)
+ {
+ return this;
+ }
+
+ @Override
+ public ResponseSpec onRawStatus(IntPredicate statusCodePredicate, Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction)
+ {
+ return this;
+ }
+
+ @Override
+ public <T> Mono<T> bodyToMono(Class<T> elementClass)
+ {
+ return (Mono<T>)toMono.get();
+ }
+
+ @Override
+ public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef)
+ {
+ return (Mono<T>)toMono.get();
+ }
+
+ @Override
+ public <T> Flux<T> bodyToFlux(Class<T> elementClass)
+ {
+ return (Flux<T>)toFlux;
+ }
+
+ @Override
+ public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef)
+ {
+ return (Flux<T>)toFlux;
+ }
+
+ @Override
+ public <T> Mono<ResponseEntity<T>> toEntity(Class<T> bodyClass)
+ {
+ return (Mono<ResponseEntity<T>>)toMono.get();
+ }
+
+ @Override
+ public <T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference)
+ {
+ return (Mono<ResponseEntity<T>>)toMono.get();
+ }
+
+ @Override
+ public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass)
+ {
+ return (Mono<ResponseEntity<List<T>>>)toMono.get();
+ }
+
+ @Override
+ public <T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef)
+ {
+ return (Mono<ResponseEntity<List<T>>>)toMono.get();
+ }
+
+ @Override
+ public Mono<ResponseEntity<Void>> toBodilessEntity()
+ {
+ return (Mono<ResponseEntity<Void>>)toMono.get();
+ }
+ }
}
}