Search in sources :

Example 1 with MockClientHttpResponse

use of org.springframework.mock.http.client.reactive.MockClientHttpResponse 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));
}
Also used : MockClientHttpRequest(org.springframework.mock.http.client.reactive.MockClientHttpRequest) MockClientHttpResponse(org.springframework.mock.http.client.reactive.MockClientHttpResponse)

Example 2 with MockClientHttpResponse

use of org.springframework.mock.http.client.reactive.MockClientHttpResponse 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));
}
Also used : MockClientHttpRequest(org.springframework.mock.http.client.reactive.MockClientHttpRequest) MockClientHttpResponse(org.springframework.mock.http.client.reactive.MockClientHttpResponse)

Example 3 with MockClientHttpResponse

use of org.springframework.mock.http.client.reactive.MockClientHttpResponse 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());
}
Also used : MockClientHttpResponse(org.springframework.mock.http.client.reactive.MockClientHttpResponse) ExchangeFunction(org.springframework.web.reactive.function.client.ExchangeFunction) Assert.assertNotNull(org.junit.Assert.assertNotNull) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) ClientHttpResponse(org.springframework.http.client.reactive.ClientHttpResponse) HttpStatus(org.springframework.http.HttpStatus) ClientRequest(org.springframework.web.reactive.function.client.ClientRequest) ExchangeFunctions(org.springframework.web.reactive.function.client.ExchangeFunctions) ClientHttpRequest(org.springframework.http.client.reactive.ClientHttpRequest) URI(java.net.URI) Assert.assertEquals(org.junit.Assert.assertEquals) ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) MockClientHttpRequest(org.springframework.mock.http.client.reactive.MockClientHttpRequest) ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) MockClientHttpRequest(org.springframework.mock.http.client.reactive.MockClientHttpRequest) ClientHttpRequest(org.springframework.http.client.reactive.ClientHttpRequest) MockClientHttpRequest(org.springframework.mock.http.client.reactive.MockClientHttpRequest) MockClientHttpResponse(org.springframework.mock.http.client.reactive.MockClientHttpResponse) ClientHttpResponse(org.springframework.http.client.reactive.ClientHttpResponse) ClientRequest(org.springframework.web.reactive.function.client.ClientRequest) MockClientHttpResponse(org.springframework.mock.http.client.reactive.MockClientHttpResponse) ExchangeFunction(org.springframework.web.reactive.function.client.ExchangeFunction) Test(org.junit.Test)

Example 4 with MockClientHttpResponse

use of org.springframework.mock.http.client.reactive.MockClientHttpResponse in project spring-framework by spring-projects.

the class HttpHandlerConnector method adaptResponse.

private ClientHttpResponse adaptResponse(MockServerHttpResponse response, Flux<DataBuffer> body) {
    HttpStatus status = Optional.ofNullable(response.getStatusCode()).orElse(HttpStatus.OK);
    MockClientHttpResponse clientResponse = new MockClientHttpResponse(status);
    clientResponse.getHeaders().putAll(response.getHeaders());
    clientResponse.getCookies().putAll(response.getCookies());
    clientResponse.setBody(body);
    return clientResponse;
}
Also used : HttpStatus(org.springframework.http.HttpStatus) MockClientHttpResponse(org.springframework.mock.http.client.reactive.MockClientHttpResponse)

Aggregations

MockClientHttpResponse (org.springframework.mock.http.client.reactive.MockClientHttpResponse)4 MockClientHttpRequest (org.springframework.mock.http.client.reactive.MockClientHttpRequest)3 HttpStatus (org.springframework.http.HttpStatus)2 URI (java.net.URI)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Test (org.junit.Test)1 HttpMethod (org.springframework.http.HttpMethod)1 ClientHttpConnector (org.springframework.http.client.reactive.ClientHttpConnector)1 ClientHttpRequest (org.springframework.http.client.reactive.ClientHttpRequest)1 ClientHttpResponse (org.springframework.http.client.reactive.ClientHttpResponse)1 ClientRequest (org.springframework.web.reactive.function.client.ClientRequest)1 ExchangeFunction (org.springframework.web.reactive.function.client.ExchangeFunction)1 ExchangeFunctions (org.springframework.web.reactive.function.client.ExchangeFunctions)1 Mono (reactor.core.publisher.Mono)1