use of org.springframework.mock.http.client.reactive.MockClientHttpRequest in project spring-framework by spring-projects.
the class HeaderAssertionsTests method headerAssertions.
private HeaderAssertions headerAssertions(HttpHeaders responseHeaders) {
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/"));
MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
response.getHeaders().putAll(responseHeaders);
WiretapClientHttpRequest wiretapRequest = new WiretapClientHttpRequest(request);
WiretapClientHttpResponse wiretapResponse = new WiretapClientHttpResponse(response);
ExchangeResult result = new ExchangeResult(wiretapRequest, wiretapResponse);
return new HeaderAssertions(result, mock(WebTestClient.ResponseSpec.class));
}
use of org.springframework.mock.http.client.reactive.MockClientHttpRequest in project spring-framework by spring-projects.
the class StatusAssertionTests method statusAssertions.
private StatusAssertions statusAssertions(HttpStatus status) {
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/"));
MockClientHttpResponse response = new MockClientHttpResponse(status);
WiretapClientHttpRequest wiretapRequest = new WiretapClientHttpRequest(request);
WiretapClientHttpResponse wiretapResponse = new WiretapClientHttpResponse(response);
ExchangeResult exchangeResult = new ExchangeResult(wiretapRequest, wiretapResponse);
return new StatusAssertions(exchangeResult, mock(WebTestClient.ResponseSpec.class));
}
use of org.springframework.mock.http.client.reactive.MockClientHttpRequest in project spring-framework by spring-projects.
the class WebTestClientConnectorTests method captureAndClaim.
@Test
@SuppressWarnings("deprecation")
public void captureAndClaim() throws Exception {
ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/test");
ClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(Mono.just(response));
ClientRequest clientRequest = ClientRequest.method(HttpMethod.GET, URI.create("/test")).header(WiretapConnector.REQUEST_ID_HEADER_NAME, "1").build();
WiretapConnector wiretapConnector = new WiretapConnector(connector);
ExchangeFunction function = ExchangeFunctions.create(wiretapConnector);
function.exchange(clientRequest).blockMillis(0);
ExchangeResult actual = wiretapConnector.claimRequest("1");
assertNotNull(actual);
assertEquals(HttpMethod.GET, actual.getMethod());
assertEquals("/test", actual.getUrl().toString());
}
use of org.springframework.mock.http.client.reactive.MockClientHttpRequest in project spring-framework by spring-projects.
the class HttpHandlerConnector method connect.
@Override
public Mono<ClientHttpResponse> connect(HttpMethod httpMethod, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
MonoProcessor<ClientHttpResponse> result = MonoProcessor.create();
MockClientHttpRequest mockClientRequest = new MockClientHttpRequest(httpMethod, uri);
MockServerHttpResponse mockServerResponse = new MockServerHttpResponse();
mockClientRequest.setWriteHandler(requestBody -> {
log("Invoking HttpHandler for ", httpMethod, uri);
ServerHttpRequest mockServerRequest = adaptRequest(mockClientRequest, requestBody);
this.handler.handle(mockServerRequest, mockServerResponse).subscribe(aVoid -> {
}, result::onError);
return Mono.empty();
});
mockServerResponse.setWriteHandler(responseBody -> {
log("Creating client response for ", httpMethod, uri);
result.onNext(adaptResponse(mockServerResponse, responseBody));
return Mono.empty();
});
log("Writing client request for ", httpMethod, uri);
requestCallback.apply(mockClientRequest).subscribe(aVoid -> {
}, result::onError);
return result;
}
Aggregations