use of com.canoo.platform.core.http.HttpResponse in project dolphin-platform by canoo.
the class HttpClientTests method testSimpleGet.
@Test
public void testSimpleGet() 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<Void>> future = getHttpResponseCompletableFuture(client, actionCalled, doneCalled, errorCalled);
// then:
future.get(1_000, TimeUnit.MILLISECONDS);
final HttpResponse<Void> 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());
assertThatDoneCalledAndErrorNotCalled(actionCalled, doneCalled, errorCalled);
}
use of com.canoo.platform.core.http.HttpResponse 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);
}
use of com.canoo.platform.core.http.HttpResponse in project dolphin-platform by canoo.
the class HttpClientTests method testPostWithoutContent.
@Test
public void testPostWithoutContent() 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<String>> future = client.post("http://localhost:" + freePort).withoutContent().readString().onDone(response -> {
actionCalled.set(true);
doneCalled.set(true);
}).onError(e -> {
actionCalled.set(true);
errorCalled.set(true);
}).execute();
// then:
final HttpResponse<String> 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 String content = response.getContent();
assertThat("String content does not match", content, is("CHECK"));
assertThatDoneCalledAndErrorNotCalled(actionCalled, doneCalled, errorCalled);
}
use of com.canoo.platform.core.http.HttpResponse in project dolphin-platform by canoo.
the class HttpClientTests method testBadEndpoint.
@Test
public void testBadEndpoint() 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<Void>> future = client.get("http://localhost:" + freePort + "/not/available").withoutContent().withoutResult().onDone(response -> {
actionCalled.set(true);
doneCalled.set(true);
}).onError(e -> {
actionCalled.set(true);
errorCalled.set(true);
}).execute();
// then:
assertThatBadResponseException(doneCalled, errorCalled, future, SC_HTTP_RESOURCE_NOTFOUND);
assertThatErrorCalledAndDoneNotCalled(actionCalled, doneCalled, errorCalled);
}
use of com.canoo.platform.core.http.HttpResponse in project dolphin-platform by canoo.
the class HttpClientTests method testBadConnection.
@Test
public void testBadConnection() 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<Void>> future = client.get("http://localhost:" + getFreePort()).withoutContent().withoutResult().onDone(response -> {
actionCalled.set(true);
doneCalled.set(true);
}).onError(e -> {
actionCalled.set(true);
errorCalled.set(true);
}).execute();
// then:
assertThatConnectionException(future);
assertThatErrorCalledAndDoneNotCalled(actionCalled, doneCalled, errorCalled);
}
Aggregations