Search in sources :

Example 1 with SC_HTTP_RESOURCE_NOTFOUND

use of com.canoo.dp.impl.platform.core.http.HttpStatus.SC_HTTP_RESOURCE_NOTFOUND 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);
}
Also used : AfterClass(org.testng.annotations.AfterClass) SC_HTTP_RESOURCE_NOTFOUND(com.canoo.dp.impl.platform.core.http.HttpStatus.SC_HTTP_RESOURCE_NOTFOUND) ByteArrayProvider(com.canoo.platform.core.http.ByteArrayProvider) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ConnectionException(com.canoo.platform.core.http.ConnectionException) HttpResponse(com.canoo.platform.core.http.HttpResponse) BeforeClass(org.testng.annotations.BeforeClass) HttpClient(com.canoo.platform.core.http.HttpClient) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.testng.annotations.Test) CompletableFuture(java.util.concurrent.CompletableFuture) HttpHeaderConstants(com.canoo.dp.impl.platform.core.http.HttpHeaderConstants) BadResponseException(com.canoo.platform.core.http.BadResponseException) SC_HTTP_UNAUTHORIZED(com.canoo.dp.impl.platform.core.http.HttpStatus.SC_HTTP_UNAUTHORIZED) ServerSocket(java.net.ServerSocket) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PlatformClient(com.canoo.platform.client.PlatformClient) Assert(org.testng.Assert) Gson(com.google.gson.Gson) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Spark(spark.Spark) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpClient(com.canoo.platform.core.http.HttpClient) HttpResponse(com.canoo.platform.core.http.HttpResponse) Test(org.testng.annotations.Test)

Aggregations

HttpHeaderConstants (com.canoo.dp.impl.platform.core.http.HttpHeaderConstants)1 SC_HTTP_RESOURCE_NOTFOUND (com.canoo.dp.impl.platform.core.http.HttpStatus.SC_HTTP_RESOURCE_NOTFOUND)1 SC_HTTP_UNAUTHORIZED (com.canoo.dp.impl.platform.core.http.HttpStatus.SC_HTTP_UNAUTHORIZED)1 PlatformClient (com.canoo.platform.client.PlatformClient)1 BadResponseException (com.canoo.platform.core.http.BadResponseException)1 ByteArrayProvider (com.canoo.platform.core.http.ByteArrayProvider)1 ConnectionException (com.canoo.platform.core.http.ConnectionException)1 HttpClient (com.canoo.platform.core.http.HttpClient)1 HttpResponse (com.canoo.platform.core.http.HttpResponse)1 Gson (com.google.gson.Gson)1 ServerSocket (java.net.ServerSocket)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.is (org.hamcrest.Matchers.is)1 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)1 Assert (org.testng.Assert)1 AfterClass (org.testng.annotations.AfterClass)1