use of com.canoo.platform.core.http.ByteArrayProvider in project dolphin-platform by canoo.
the class HttpClientTests method testSimpleGetWithByteContent.
@Test
public void testSimpleGetWithByteContent() throws Exception {
// given:
final HttpClient client = PlatformClient.getService(HttpClient.class);
final AtomicBoolean actionCalled = new AtomicBoolean(false);
final AtomicBoolean doneCalled = new AtomicBoolean(false);
final AtomicBoolean errorCalled = new AtomicBoolean(false);
// when:
final CompletableFuture<HttpResponse<ByteArrayProvider>> future = client.get("http://localhost:" + freePort).withoutContent().readBytes().onDone(response -> {
actionCalled.set(true);
doneCalled.set(true);
}).onError(e -> {
actionCalled.set(true);
errorCalled.set(true);
}).execute();
// then:
final HttpResponse<ByteArrayProvider> response = future.get(1_000, TimeUnit.MILLISECONDS);
assertThat("response not defined", response, notNullValue());
assertThat("Wrong response code", response.getStatusCode(), is(200));
assertThat("Content should not be null", response.getRawContent(), notNullValue());
final byte[] bytes = response.getContent().get();
assertThat("Byte content does not match", bytes, is("Spark Server for HTTP client integration tests".getBytes()));
assertThatDoneCalledAndErrorNotCalled(actionCalled, doneCalled, errorCalled);
}
Aggregations