Search in sources :

Example 21 with Callback

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

the class MapboxTelemetryTest method checksOnFullQueueSendEventsCalledWhenIsConnectedAndTelemetryEnabled.

@Test
public void checksOnFullQueueSendEventsCalledWhenIsConnectedAndTelemetryEnabled() throws Exception {
    Context mockedContext = obtainNetworkConnectedMockedContext();
    TelemetryClient mockedTelemetryClient = mock(TelemetryClient.class);
    Callback mockedHttpCallback = mock(Callback.class);
    MapboxTelemetry theMapboxTelemetry = obtainMapboxTelemetryWith(mockedContext, mockedTelemetryClient, mockedHttpCallback);
    List<Event> mockedList = mock(List.class);
    theMapboxTelemetry.enable();
    theMapboxTelemetry.onFullQueue(mockedList);
    verify(mockedTelemetryClient, times(1)).sendEvents(eq(mockedList), eq(mockedHttpCallback));
}
Also used : Context(android.content.Context) Callback(okhttp3.Callback) Test(org.junit.Test)

Example 22 with Callback

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

the class TelemetryClientAppUserTurnstileEventTest method sendsTheCorrectBodyPostingAppUserTurnstileEvent.

@Test
public void sendsTheCorrectBodyPostingAppUserTurnstileEvent() throws Exception {
    Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
    MapboxTelemetry.applicationContext = mockedContext;
    TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
    Event anAppUserTurnstile = new AppUserTurnstile("anySdkIdentifier", "anySdkVersion", false);
    List<Event> theAppUserTurnstile = obtainEvents(anAppUserTurnstile);
    Callback mockedCallback = mock(Callback.class);
    enqueueMockResponse();
    telemetryClient.sendEvents(theAppUserTurnstile, mockedCallback);
    String expectedRequestBody = obtainExpectedRequestBody(new GsonBuilder(), theAppUserTurnstile.get(0));
    assertRequestBodyEquals(expectedRequestBody);
}
Also used : Context(android.content.Context) Callback(okhttp3.Callback) GsonBuilder(com.google.gson.GsonBuilder) Test(org.junit.Test)

Example 23 with Callback

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

the class TelemetryClientNavigationEventsTest method sendsTheCorrectBodyPostingNavigationFeedbackEvent.

@Test
public void sendsTheCorrectBodyPostingNavigationFeedbackEvent() throws Exception {
    TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
    Event.Type feedback = Event.Type.NAV_FEEDBACK;
    Event aFeedbackEvent = obtainNavigationEvent(feedback);
    List<Event> theFeedbackEvent = obtainEvents(aFeedbackEvent);
    Callback mockedCallback = mock(Callback.class);
    enqueueMockResponse();
    telemetryClient.sendEvents(theFeedbackEvent, mockedCallback);
    GsonBuilder gsonBuilder = configureTypeAdapter(feedback, new GsonBuilder());
    String expectedRequestBody = obtainExpectedRequestBody(gsonBuilder, theFeedbackEvent.get(0));
    assertRequestBodyEquals(expectedRequestBody);
}
Also used : Callback(okhttp3.Callback) GsonBuilder(com.google.gson.GsonBuilder) Test(org.junit.Test)

Example 24 with Callback

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

the class TelemetryClientNavigationEventsTest method sendsTheCorrectBodyPostingNavigationRerouteEvent.

@Test
public void sendsTheCorrectBodyPostingNavigationRerouteEvent() throws Exception {
    TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
    Event.Type reroute = Event.Type.NAV_REROUTE;
    Event aRerouteEvent = obtainNavigationEvent(reroute);
    List<Event> theRerouteEvent = obtainEvents(aRerouteEvent);
    Callback mockedCallback = mock(Callback.class);
    enqueueMockResponse();
    telemetryClient.sendEvents(theRerouteEvent, mockedCallback);
    GsonBuilder gsonBuilder = configureTypeAdapter(reroute, new GsonBuilder());
    String expectedRequestBody = obtainExpectedRequestBody(gsonBuilder, theRerouteEvent.get(0));
    assertRequestBodyEquals(expectedRequestBody);
}
Also used : Callback(okhttp3.Callback) GsonBuilder(com.google.gson.GsonBuilder) Test(org.junit.Test)

Example 25 with Callback

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

the class TelemetryClientNavigationEventsTest method sendsTheCorrectBodyPostingNavigationCancelEvent.

@Test
public void sendsTheCorrectBodyPostingNavigationCancelEvent() throws Exception {
    TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
    Event.Type cancel = Event.Type.NAV_CANCEL;
    Event aCancelEvent = obtainNavigationEvent(cancel);
    List<Event> theCancelEvent = obtainEvents(aCancelEvent);
    Callback mockedCallback = mock(Callback.class);
    enqueueMockResponse();
    telemetryClient.sendEvents(theCancelEvent, mockedCallback);
    GsonBuilder gsonBuilder = configureTypeAdapter(cancel, new GsonBuilder());
    String expectedRequestBody = obtainExpectedRequestBody(gsonBuilder, theCancelEvent.get(0));
    assertRequestBodyEquals(expectedRequestBody);
}
Also used : Callback(okhttp3.Callback) GsonBuilder(com.google.gson.GsonBuilder) 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