use of okhttp3.mockwebserver.MockResponse in project spring-framework by spring-projects.
the class WebClientIntegrationTests method postJsonPojo.
@Test
public void postJsonPojo() throws Exception {
this.server.enqueue(new MockResponse().setHeader("Content-Type", "application/json").setBody("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}"));
Mono<Pojo> result = this.webClient.post().uri("/pojo/capitalize").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).exchange(fromObject(new Pojo("foofoo", "barbar"))).then(response -> response.bodyToMono(Pojo.class));
StepVerifier.create(result).consumeNextWith(p -> assertEquals("BARBAR", p.getBar())).expectComplete().verify(Duration.ofSeconds(3));
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("/pojo/capitalize", recordedRequest.getPath());
Assert.assertEquals("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}", recordedRequest.getBody().readUtf8());
Assert.assertEquals("chunked", recordedRequest.getHeader(HttpHeaders.TRANSFER_ENCODING));
Assert.assertEquals("application/json", recordedRequest.getHeader(HttpHeaders.ACCEPT));
Assert.assertEquals("application/json", recordedRequest.getHeader(HttpHeaders.CONTENT_TYPE));
}
use of okhttp3.mockwebserver.MockResponse in project glide by bumptech.
the class VolleyStreamFetcherServerTest method testCallsLoadFailedIfStatusCodeIs500.
@Test
public void testCallsLoadFailedIfStatusCodeIs500() throws Exception {
mockWebServer.enqueue(new MockResponse().setResponseCode(500).setBody("error"));
getFetcher().loadData(Priority.NORMAL, callback);
waitForResponseLatch.await();
verify(callback).onLoadFailed(isA(VolleyError.class));
}
use of okhttp3.mockwebserver.MockResponse in project glide by bumptech.
the class VolleyStreamFetcherServerTest method testHandlesRedirect302s.
@Test
public void testHandlesRedirect302s() throws Exception {
String expected = "fakedata";
mockWebServer.enqueue(new MockResponse().setResponseCode(302).setHeader("Location", mockWebServer.url("/redirect").toString()));
mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(expected));
getFetcher().loadData(Priority.LOW, callback);
waitForResponseLatch.await();
verify(callback).onDataReady(streamCaptor.capture());
assertStreamOf(expected, streamCaptor.getValue());
}
use of okhttp3.mockwebserver.MockResponse in project glide by bumptech.
the class VolleyStreamFetcherServerTest method testCallsLoadFailedIfStatusCodeIs400.
@Test
public void testCallsLoadFailedIfStatusCodeIs400() throws Exception {
mockWebServer.enqueue(new MockResponse().setResponseCode(400).setBody("error"));
getFetcher().loadData(Priority.LOW, callback);
waitForResponseLatch.await();
verify(callback).onLoadFailed(isA(VolleyError.class));
}
use of okhttp3.mockwebserver.MockResponse in project zipkin by openzipkin.
the class ZipkinServerTest method connectsToConfiguredBackend.
@Test
public void connectsToConfiguredBackend() throws Exception {
try (MockWebServer es = new MockWebServer()) {
es.start(elasticsearchPort);
es.enqueue(new MockResponse().setBody("{\"version\":{\"number\":\"2.4.0\"}}"));
// template
es.enqueue(new MockResponse());
// search (will fail because no content, but that's ok)
es.enqueue(new MockResponse());
client.newCall(new Request.Builder().url(HttpUrl.parse("http://localhost:" + zipkinPort + "/api/v1/services")).get().build()).execute();
// version
assertEquals("/", es.takeRequest().getPath());
assertEquals("/_template/zipkin_template", es.takeRequest().getPath());
assertTrue(es.takeRequest().getPath().replaceAll("\\?.*", "").endsWith("/span/_search"));
}
}
Aggregations