Search in sources :

Example 51 with Callback

use of zipkin2.Callback in project mapbox-events-android by mapbox.

the class TelemetryClientMapEventsTest method sendsTheCorrectBodyPostingMapLoadEvent.

@Test
public void sendsTheCorrectBodyPostingMapLoadEvent() throws Exception {
    TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
    Event.Type load = Event.Type.MAP_LOAD;
    Event aLoadEvent = obtainMapEvent(load);
    List<Event> theLoadEvent = obtainEvents(aLoadEvent);
    Callback mockedCallback = mock(Callback.class);
    enqueueMockResponse();
    telemetryClient.sendEvents(theLoadEvent, mockedCallback);
    String expectedRequestBody = obtainExpectedRequestBody(new GsonBuilder(), theLoadEvent.get(0));
    assertRequestBodyEquals(expectedRequestBody);
}
Also used : Callback(okhttp3.Callback) GsonBuilder(com.google.gson.GsonBuilder) Test(org.junit.Test)

Example 52 with Callback

use of zipkin2.Callback in project mapbox-events-android by mapbox.

the class TelemetryClientTest method sendsPostEventRequestWithTheCorrectAccessTokenParameter.

@Test
public void sendsPostEventRequestWithTheCorrectAccessTokenParameter() throws Exception {
    Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
    MapboxTelemetry.applicationContext = mockedContext;
    TelemetryClient telemetryClient = obtainATelemetryClient("theAccessToken", "anyUserAgent");
    List<Event> mockedEvent = obtainAnEvent();
    Callback mockedCallback = mock(Callback.class);
    enqueueMockResponse();
    telemetryClient.sendEvents(mockedEvent, mockedCallback);
    assertRequestContainsParameter("access_token", "theAccessToken");
}
Also used : Context(android.content.Context) Callback(okhttp3.Callback) Test(org.junit.Test)

Example 53 with Callback

use of zipkin2.Callback in project mapbox-events-android by mapbox.

the class TelemetryClientTest method provideACallback.

private Callback provideACallback(final CountDownLatch latch, final AtomicReference<String> bodyRef, final AtomicBoolean failureRef) {
    Callback aCallback = new Callback() {

        @Override
        public void onFailure(Call call, IOException exception) {
            failureRef.set(true);
            latch.countDown();
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            try {
                bodyRef.set(response.body().string());
            } catch (IOException exception) {
                throw exception;
            } finally {
                latch.countDown();
            }
        }
    };
    return aCallback;
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) IOException(java.io.IOException)

Example 54 with Callback

use of zipkin2.Callback in project mapbox-events-android by mapbox.

the class TelemetryClientTest method sendsContentEncodingHeader.

@Test
public void sendsContentEncodingHeader() throws Exception {
    Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
    MapboxTelemetry.applicationContext = mockedContext;
    TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
    List<Event> mockedEvent = obtainAnEvent();
    Callback mockedCallback = mock(Callback.class);
    enqueueMockResponse();
    telemetryClient.sendEvents(mockedEvent, mockedCallback);
    assertRequestContainsHeader("Content-Encoding", "gzip");
}
Also used : Context(android.content.Context) Callback(okhttp3.Callback) Test(org.junit.Test)

Example 55 with Callback

use of zipkin2.Callback in project mapbox-events-android by mapbox.

the class TelemetryClientTest method sendsContentTypeHeader.

@Test
public void sendsContentTypeHeader() throws Exception {
    Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
    MapboxTelemetry.applicationContext = mockedContext;
    TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
    List<Event> mockedEvent = obtainAnEvent();
    Callback mockedCallback = mock(Callback.class);
    enqueueMockResponse();
    telemetryClient.sendEvents(mockedEvent, mockedCallback);
    assertRequestContainsHeader("Content-Type", "application/json; charset=utf-8");
}
Also used : Context(android.content.Context) Callback(okhttp3.Callback) Test(org.junit.Test)

Aggregations

Callback (okhttp3.Callback)173 IOException (java.io.IOException)137 Call (okhttp3.Call)132 Response (okhttp3.Response)132 Request (okhttp3.Request)110 Callback (retrofit2.Callback)42 Call (retrofit2.Call)41 Test (org.junit.Test)39 Response (retrofit2.Response)39 RequestBody (okhttp3.RequestBody)37 OkHttpClient (okhttp3.OkHttpClient)34 File (java.io.File)27 Context (android.content.Context)24 JSONObject (org.json.JSONObject)20 FormBody (okhttp3.FormBody)19 ArrayList (java.util.ArrayList)18 View (android.view.View)16 Intent (android.content.Intent)14 TextView (android.widget.TextView)14 GsonBuilder (com.google.gson.GsonBuilder)14