use of org.apache.http.HttpResponse in project moco by dreamhead.
the class MocoJunitJsonRestRunnerTest method should_return_expected_message.
@Test
public void should_return_expected_message() throws IOException {
HttpResponse response = helper.postForResponse(remoteUrl("/targets"), "hello");
assertThat(response.getStatusLine().getStatusCode(), is(201));
assertThat(response.getFirstHeader("Location").getValue(), is("/targets/123"));
}
use of org.apache.http.HttpResponse in project moco by dreamhead.
the class MocoJunitJsonRestRunnerWithPathTest method should_return_expected_message.
@Test
public void should_return_expected_message() throws IOException {
HttpResponse response = helper.postForResponse(remoteUrl("/targets"), "hello");
assertThat(response.getStatusLine().getStatusCode(), is(201));
assertThat(response.getFirstHeader("Location").getValue(), is("/targets/123"));
}
use of org.apache.http.HttpResponse in project moco by dreamhead.
the class MocoJunitPojoRestRunnerTest method should_return_expected_message.
@Test
public void should_return_expected_message() throws IOException {
HttpResponse response = helper.postForResponse(remoteUrl("/targets"), "hello");
assertThat(response.getStatusLine().getStatusCode(), is(201));
assertThat(response.getFirstHeader("Location").getValue(), is("/targets/123"));
}
use of org.apache.http.HttpResponse in project moco by dreamhead.
the class MocoGlobalResponseTest method should_return_all_response_for_content_with_header.
@Test
public void should_return_all_response_for_content_with_header() throws Exception {
server = httpServer(port(), response(header("foo", "bar")));
server.response("hello");
running(server, new Runnable() {
@Override
public void run() throws Exception {
HttpResponse response = Request.Get(root()).execute().returnResponse();
Header header = response.getFirstHeader("foo");
assertThat(header.getValue(), is("bar"));
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
response.getEntity().writeTo(outstream);
assertThat(new String(outstream.toByteArray()), is("hello"));
}
});
}
use of org.apache.http.HttpResponse in project elasticsearch by elastic.
the class RemoteScrollableHitSourceTests method testTooLargeResponse.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testTooLargeResponse() throws Exception {
ContentTooLongException tooLong = new ContentTooLongException("too long!");
CloseableHttpAsyncClient httpClient = mock(CloseableHttpAsyncClient.class);
when(httpClient.<HttpResponse>execute(any(HttpAsyncRequestProducer.class), any(HttpAsyncResponseConsumer.class), any(HttpClientContext.class), any(FutureCallback.class))).then(new Answer<Future<HttpResponse>>() {
@Override
public Future<HttpResponse> answer(InvocationOnMock invocationOnMock) throws Throwable {
HeapBufferedAsyncResponseConsumer consumer = (HeapBufferedAsyncResponseConsumer) invocationOnMock.getArguments()[1];
FutureCallback callback = (FutureCallback) invocationOnMock.getArguments()[3];
assertEquals(new ByteSizeValue(100, ByteSizeUnit.MB).bytesAsInt(), consumer.getBufferLimit());
callback.failed(tooLong);
return null;
}
});
RemoteScrollableHitSource source = sourceWithMockedClient(true, httpClient);
AtomicBoolean called = new AtomicBoolean();
Consumer<Response> checkResponse = r -> called.set(true);
Throwable e = expectThrows(RuntimeException.class, () -> source.doStartNextScroll(FAKE_SCROLL_ID, timeValueMillis(0), checkResponse));
// Unwrap the some artifacts from the test
while (e.getMessage().equals("failed")) {
e = e.getCause();
}
// This next exception is what the user sees
assertEquals("Remote responded with a chunk that was too large. Use a smaller batch size.", e.getMessage());
// And that exception is reported as being caused by the underlying exception returned by the client
assertSame(tooLong, e.getCause());
assertFalse(called.get());
}
Aggregations