use of okhttp3.mockwebserver.RecordedRequest in project spring-framework by spring-projects.
the class AbstractMockWebServerTestCase method jsonPostRequest.
private MockResponse jsonPostRequest(RecordedRequest request, String location, String contentType) {
if (request.getBodySize() > 0) {
assertTrue("Invalid request content-length", Integer.parseInt(request.getHeader("Content-Length")) > 0);
assertNotNull("No content-type", request.getHeader("Content-Type"));
}
return new MockResponse().setHeader("Location", baseUrl + location).setHeader("Content-Type", contentType).setHeader("Content-Length", request.getBody().size()).setBody(request.getBody()).setResponseCode(201);
}
use of okhttp3.mockwebserver.RecordedRequest in project spring-framework by spring-projects.
the class WebClientIntegrationTests method plainText.
@Test
public void plainText() throws Exception {
this.server.enqueue(new MockResponse().setBody("Hello Spring!"));
Mono<String> result = this.webClient.get().uri("/greeting?name=Spring").header("X-Test-Header", "testvalue").exchange().then(response -> response.bodyToMono(String.class));
StepVerifier.create(result).expectNext("Hello Spring!").expectComplete().verify(Duration.ofSeconds(3));
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("testvalue", recordedRequest.getHeader("X-Test-Header"));
Assert.assertEquals("*/*", recordedRequest.getHeader(HttpHeaders.ACCEPT));
Assert.assertEquals("/greeting?name=Spring", recordedRequest.getPath());
}
use of okhttp3.mockwebserver.RecordedRequest in project spring-framework by spring-projects.
the class WebClientIntegrationTests method headers.
@Test
public void headers() throws Exception {
this.server.enqueue(new MockResponse().setHeader("Content-Type", "text/plain").setBody("Hello Spring!"));
Mono<HttpHeaders> result = this.webClient.get().uri("/greeting?name=Spring").exchange().map(response -> response.headers().asHttpHeaders());
StepVerifier.create(result).consumeNextWith(httpHeaders -> {
assertEquals(MediaType.TEXT_PLAIN, httpHeaders.getContentType());
assertEquals(13L, httpHeaders.getContentLength());
}).expectComplete().verify(Duration.ofSeconds(3));
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("*/*", recordedRequest.getHeader(HttpHeaders.ACCEPT));
Assert.assertEquals("/greeting?name=Spring", recordedRequest.getPath());
}
use of okhttp3.mockwebserver.RecordedRequest in project spring-framework by spring-projects.
the class WebClientIntegrationTests method jsonString.
@Test
public void jsonString() throws Exception {
String content = "{\"bar\":\"barbar\",\"foo\":\"foofoo\"}";
this.server.enqueue(new MockResponse().setHeader("Content-Type", "application/json").setBody(content));
Mono<String> result = this.webClient.get().uri("/json").accept(MediaType.APPLICATION_JSON).exchange().then(response -> response.bodyToMono(String.class));
StepVerifier.create(result).expectNext(content).expectComplete().verify(Duration.ofSeconds(3));
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("/json", recordedRequest.getPath());
Assert.assertEquals("application/json", recordedRequest.getHeader(HttpHeaders.ACCEPT));
}
use of okhttp3.mockwebserver.RecordedRequest in project spring-framework by spring-projects.
the class WebClientIntegrationTests method buildFilter.
@Test
public void buildFilter() throws Exception {
this.server.enqueue(new MockResponse().setHeader("Content-Type", "text/plain").setBody("Hello Spring!"));
WebClient filteredClient = this.webClient.filter((request, next) -> {
ClientRequest filteredRequest = ClientRequest.from(request).header("foo", "bar").build();
return next.exchange(filteredRequest);
});
Mono<String> result = filteredClient.get().uri("/greeting?name=Spring").exchange().then(response -> response.bodyToMono(String.class));
StepVerifier.create(result).expectNext("Hello Spring!").expectComplete().verify(Duration.ofSeconds(3));
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("bar", recordedRequest.getHeader("foo"));
}
Aggregations