Search in sources :

Example 66 with HttpUrl

use of okhttp3.HttpUrl in project java-sdk by watson-developer-cloud.

the class WatsonService method getToken.

/**
 * Gets an authorization token that can be use to authorize API calls.
 *
 * @return the token
 */
public ServiceCall<String> getToken() {
    HttpUrl url = HttpUrl.parse(getEndPoint()).newBuilder().setPathSegment(0, AUTHORIZATION).addPathSegment(PATH_AUTHORIZATION_V1_TOKEN).build();
    Request request = RequestBuilder.get(url).header(HttpHeaders.ACCEPT, HttpMediaType.TEXT_PLAIN).query(URL, getEndPoint()).build();
    return createServiceCall(request, ResponseConverterUtils.getString());
}
Also used : Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Example 67 with HttpUrl

use of okhttp3.HttpUrl in project pivotal-cla by pivotalsoftware.

the class EnqueueResourcesMockWebServerITest method multipleRequests.

@Test
public void multipleRequests() throws IOException {
    OkHttpClient client = new OkHttpClient.Builder().build();
    HttpUrl url = server.getServer().url("/");
    Request request = new Request.Builder().get().url(url).build();
    Response response = client.newCall(request).execute();
    assertEquals(200, response.code());
    assertEquals("Hi", response.body().string());
    response = client.newCall(request).execute();
    assertEquals(500, response.code());
    assertEquals("Fail", response.body().string());
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 68 with HttpUrl

use of okhttp3.HttpUrl in project pivotal-cla by pivotalsoftware.

the class EnqueueResourcesMockWebServerITest method singleRequest.

@Test
public void singleRequest() throws IOException {
    OkHttpClient client = new OkHttpClient.Builder().build();
    HttpUrl url = server.getServer().url("/");
    Request request = new Request.Builder().get().url(url).build();
    Response response = client.newCall(request).execute();
    assertEquals(200, response.code());
    assertEquals("Hi", response.body().string());
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 69 with HttpUrl

use of okhttp3.HttpUrl in project pivotal-cla by pivotalsoftware.

the class EnqueueResourcesMockWebServerITest method enqueueRequestsRelative.

@Test
@EnqueueRequests("body-relative")
public void enqueueRequestsRelative() throws Exception {
    OkHttpClient client = new OkHttpClient.Builder().build();
    HttpUrl url = server.getServer().url("/");
    Request request = new Request.Builder().get().url(url).build();
    Response response = client.newCall(request).execute();
    assertEquals(200, response.code());
    assertEquals("body-relative", response.body().string());
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 70 with HttpUrl

use of okhttp3.HttpUrl in project pivotal-cla by pivotalsoftware.

the class EnqueueResourcesMockWebServerITest method enqueueRequestsAbsolute.

@Test
@EnqueueRequests("/okhttp3/mockwebserver/EnqueueResourcesMockWebServerITest_resource/body-absolute")
public void enqueueRequestsAbsolute() throws Exception {
    OkHttpClient client = new OkHttpClient.Builder().build();
    HttpUrl url = server.getServer().url("/");
    Request request = new Request.Builder().get().url(url).build();
    Response response = client.newCall(request).execute();
    assertEquals(200, response.code());
    assertEquals("body-absolute", response.body().string());
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Aggregations

HttpUrl (okhttp3.HttpUrl)302 Request (okhttp3.Request)130 Test (org.junit.Test)86 Response (okhttp3.Response)69 IOException (java.io.IOException)61 MockResponse (okhttp3.mockwebserver.MockResponse)40 Cookie (okhttp3.Cookie)35 ArrayList (java.util.ArrayList)28 OkHttpClient (okhttp3.OkHttpClient)27 MockWebServer (okhttp3.mockwebserver.MockWebServer)26 InputStream (java.io.InputStream)21 InputStreamReader (java.io.InputStreamReader)20 HashMap (java.util.HashMap)19 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)19 RequestBody (okhttp3.RequestBody)18 JsonParseException (com.google.gson.JsonParseException)13 File (java.io.File)12 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)10 List (java.util.List)10 Test (org.junit.jupiter.api.Test)10