Search in sources :

Example 16 with Response

use of retrofit2.Response in project okhttp by square.

the class HttpLoggingInterceptorTest method headersResponseBody.

@Test
public void headersResponseBody() throws IOException {
    setLevel(Level.HEADERS);
    server.enqueue(new MockResponse().setBody("Hello!").setHeader("Content-Type", PLAIN));
    Response response = client.newCall(request().build()).execute();
    response.body().close();
    applicationLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 6").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
    networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 6").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
}
Also used : Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 17 with Response

use of retrofit2.Response in project okhttp by square.

the class HttpLoggingInterceptorTest method headersGet.

@Test
public void headersGet() throws IOException {
    setLevel(Level.HEADERS);
    server.enqueue(new MockResponse());
    Response response = client.newCall(request().build()).execute();
    response.body().close();
    applicationLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
    networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
}
Also used : Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 18 with Response

use of retrofit2.Response in project okhttp by square.

the class HttpLoggingInterceptorTest method bodyPost.

@Test
public void bodyPost() throws IOException {
    setLevel(Level.BODY);
    server.enqueue(new MockResponse());
    Request request = request().post(RequestBody.create(PLAIN, "Hi?")).build();
    Response response = client.newCall(request).execute();
    response.body().close();
    applicationLogs.assertLogEqual("--> POST " + url + " http/1.1").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("Content-Length: 3").assertLogEqual("").assertLogEqual("Hi?").assertLogEqual("--> END POST (3-byte body)").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
    networkLogs.assertLogEqual("--> POST " + url + " http/1.1").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("Content-Length: 3").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("").assertLogEqual("Hi?").assertLogEqual("--> END POST (3-byte body)").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
}
Also used : Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Request(okhttp3.Request) Test(org.junit.Test)

Example 19 with Response

use of retrofit2.Response in project okhttp by square.

the class HttpLoggingInterceptorTest method basicChunkedResponseBody.

@Test
public void basicChunkedResponseBody() throws IOException {
    setLevel(Level.BASIC);
    server.enqueue(new MockResponse().setChunkedBody("Hello!", 2).setHeader("Content-Type", PLAIN));
    Response response = client.newCall(request().build()).execute();
    response.body().close();
    applicationLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, unknown-length body\\)").assertNoMoreLogs();
    networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, unknown-length body\\)").assertNoMoreLogs();
}
Also used : Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 20 with Response

use of retrofit2.Response in project okhttp by square.

the class HttpLoggingInterceptorTest method bodyGetNoBody.

private void bodyGetNoBody(int code) throws IOException {
    server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + code + " No Content"));
    Response response = client.newCall(request().build()).execute();
    response.body().close();
    applicationLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("--> END GET").assertLogMatch("<-- " + code + " No Content " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
    networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("--> END GET").assertLogMatch("<-- " + code + " No Content " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
}
Also used : Response(okhttp3.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse)

Aggregations

Response (okhttp3.Response)474 Request (okhttp3.Request)352 Test (org.junit.Test)237 IOException (java.io.IOException)188 Response (retrofit2.Response)156 ResponseBody (okhttp3.ResponseBody)148 ServiceResponse (com.microsoft.rest.ServiceResponse)114 Call (okhttp3.Call)102 MockResponse (okhttp3.mockwebserver.MockResponse)99 Observable (rx.Observable)98 OkHttpClient (okhttp3.OkHttpClient)72 RequestBody (okhttp3.RequestBody)71 Callback (okhttp3.Callback)43 List (java.util.List)40 TestClients.clientRequest (keywhiz.TestClients.clientRequest)37 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)34 Interceptor (okhttp3.Interceptor)29 HttpUrl (okhttp3.HttpUrl)27 MediaType (okhttp3.MediaType)26 Buffer (okio.Buffer)25