Search in sources :

Example 26 with Route

use of okhttp3.Route in project fabric8-maven-plugin by fabric8io.

the class SpringbootConfigmapBoosterIT method assertApplicationEndpoint.

private void assertApplicationEndpoint(String key, String value) throws Exception {
    int nTries = 0;
    Response readResponse = null;
    String responseContent = null;
    Route applicationRoute = getApplicationRouteWithName(testsuiteRepositoryArtifactId);
    String hostUrl = applicationRoute.getSpec().getHost() + TEST_ENDPOINT;
    do {
        readResponse = makeHttpRequest(HttpRequestType.GET, "http://" + hostUrl, null);
        responseContent = new JSONObject(readResponse.body().string()).getString(key);
        nTries++;
        TimeUnit.SECONDS.sleep(10);
    } while (nTries < 3 && readResponse.code() != HttpStatus.SC_OK);
    if (!responseContent.equals(value))
        throw new AssertionError(String.format("Actual : %s, Expected : %s", responseContent, value));
}
Also used : Response(okhttp3.Response) JSONObject(org.json.JSONObject) Route(io.fabric8.openshift.api.model.Route)

Example 27 with Route

use of okhttp3.Route in project fabric8-maven-plugin by fabric8io.

the class VertxHealthchecksBoosterIT method testHealthChecks.

private void testHealthChecks(Route applicationRoute) throws Exception {
    String hostUrl = "http://" + applicationRoute.getSpec().getHost();
    // Check service state
    assert isApplicationUpAndRunning(hostUrl);
    // Stop the service
    assert makeHttpRequest(HttpRequestType.GET, hostUrl + "/api/stop", null).code() == HttpStatus.SC_OK;
    // Check service state after shutdown
    Response serviceStatus = makeHttpRequest(HttpRequestType.GET, hostUrl + "/api/health/liveness", null);
    assert serviceStatus.code() != HttpStatus.SC_OK;
    assert new JSONObject(serviceStatus.body().string()).getString("outcome").equals("DOWN");
    // Wait for recovery
    assertApplicationRecovery(hostUrl + "/api/greeting", 120);
}
Also used : Response(okhttp3.Response) JSONObject(org.json.JSONObject)

Example 28 with Route

use of okhttp3.Route in project fabric8-maven-plugin by fabric8io.

the class SpringbootCrudBoosterIT method executeCRUDAssertions.

private void executeCRUDAssertions(Route applicationRoute) throws Exception {
    String hostUrl = "http://" + applicationRoute.getSpec().getHost() + TEST_ENDPOINT;
    JSONObject jsonRequest = new JSONObject();
    String testFruitName = "Pineapple";
    // limiting test scope, a basic write followed by read is sufficient.
    // (C) Create
    jsonRequest.put("name", testFruitName);
    Response createResponse = makeHttpRequest(HttpRequestType.POST, hostUrl, jsonRequest.toString());
    assert createResponse.code() == HttpStatus.SC_CREATED;
    Integer fruitId = new JSONObject(createResponse.body().string()).getInt("id");
    hostUrl += ("/" + fruitId.toString());
    // (R) Read
    Response readResponse = makeHttpRequest(HttpRequestType.GET, hostUrl, null);
    String fruitName = new JSONObject(readResponse.body().string()).getString("name");
    assert readResponse.code() == HttpStatus.SC_OK;
    assert fruitName.equals(testFruitName);
}
Also used : Response(okhttp3.Response) JSONObject(org.json.JSONObject)

Example 29 with Route

use of okhttp3.Route in project fabric8-maven-plugin by fabric8io.

the class VertxConfigmapBoosterIT method assertApplicationEndpoint.

private boolean assertApplicationEndpoint(String key, String value) throws Exception {
    Route applicationRoute = getApplicationRouteWithName(testsuiteRepositoryArtifactId);
    String hostUrl = applicationRoute.getSpec().getHost() + TEST_ENDPOINT;
    Response response = makeHttpRequest(HttpRequestType.GET, "http://" + hostUrl, null);
    return new JSONObject(response.body().string()).getString(key).equals(value);
}
Also used : Response(okhttp3.Response) JSONObject(org.json.JSONObject) Route(io.fabric8.openshift.api.model.Route)

Example 30 with Route

use of okhttp3.Route in project spring-cloud-netflix by spring-cloud.

the class RibbonCommandContextTest method givenRibbonCommandContextIsSetup.

private void givenRibbonCommandContextIsSetup() {
    LinkedMultiValueMap headers = new LinkedMultiValueMap();
    LinkedMultiValueMap params = new LinkedMultiValueMap();
    RibbonRequestCustomizer requestCustomizer = new RibbonRequestCustomizer<Request.Builder>() {

        @Override
        public boolean accepts(Class builderClass) {
            return builderClass == Request.Builder.class;
        }

        @Override
        public void customize(Request.Builder builder) {
            builder.addHeader("from-customizer", "foo");
        }
    };
    ribbonCommandContext = new RibbonCommandContext("serviceId", HttpMethod.POST.toString(), "/my/route", true, headers, params, new ByteArrayInputStream(TEST_CONTENT), Lists.newArrayList(requestCustomizer));
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Request(okhttp3.Request)

Aggregations

Response (okhttp3.Response)52 Request (okhttp3.Request)41 IOException (java.io.IOException)40 OkHttpClient (okhttp3.OkHttpClient)33 Route (okhttp3.Route)31 Proxy (java.net.Proxy)23 InetSocketAddress (java.net.InetSocketAddress)21 Authenticator (okhttp3.Authenticator)18 Test (org.junit.Test)17 Map (java.util.Map)16 List (java.util.List)13 HttpUrl (okhttp3.HttpUrl)13 RequestBody (okhttp3.RequestBody)13 Test (org.junit.jupiter.api.Test)13 Credentials (okhttp3.Credentials)11 ArrayList (java.util.ArrayList)10 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)10 File (java.io.File)9 URI (java.net.URI)9 URL (java.net.URL)9