Search in sources :

Example 41 with AnalyticsEvent

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.

the class GCMNotificationClientTest method testGCMMessageReceivedInForegroundDefaultConfig.

@Test
public void testGCMMessageReceivedInForegroundDefaultConfig() throws JSONException {
    // Force the app to be in the foreground.
    final AppUtil appUtil = Mockito.mock(AppUtil.class);
    Whitebox.setInternalState(target.notificationClientBase, "appUtil", appUtil);
    Mockito.when(appUtil.isAppInForeground()).thenReturn(true);
    NotificationClient.CampaignPushResult pushResult = target.handleGCMCampaignPush("12345", buildPushBundle(), Service.class);
    ArgumentCaptor<AnalyticsEvent> eventCaptor = ArgumentCaptor.forClass(AnalyticsEvent.class);
    verify(mockEventRecorder, times(1)).recordEvent(eventCaptor.capture());
    final AnalyticsEvent receivedEvent = eventCaptor.getAllValues().get(0);
    assertThat(receivedEvent.getEventType(), is("_campaign.received_foreground"));
    assertTrue(receivedEvent.getEventTimestamp() > 0);
    for (Map.Entry<String, String> entry : receivedEvent.getAllAttributes().entrySet()) {
        System.out.println(entry.getKey() + ":" + entry.getValue());
    }
    assertThat(receivedEvent.getAllAttributes().size(), is(4));
    assertThat(receivedEvent.getAttribute("isAppInForeground"), is("true"));
    assertThat(receivedEvent.getAttribute("campaign_id"), is("Customers rule"));
    assertThat(receivedEvent.getAttribute("treatment_id"), is("Treat Me well please"));
    assertThat(receivedEvent.getAttribute("campaign_activity_id"), is("the brink of dawn"));
    // optOut is true because this test can't get the app icon resource id.
    assertThat(receivedEvent.getAllMetrics().size(), is(0));
    // Verify the notification is not posted and instead we get the result that the app was in the foreground.
    assertTrue(pushResult.equals(NotificationClient.CampaignPushResult.APP_IN_FOREGROUND));
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) Map(java.util.Map) Test(org.junit.Test)

Aggregations

AnalyticsEvent (com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)41 Test (org.junit.Test)27 Map (java.util.Map)16 AnalyticsClient (com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient)7 HashMap (java.util.HashMap)6 AnalyticsContextBuilder (com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder)5 PinpointContext (com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext)5 Before (org.junit.Before)5 Uri (android.net.Uri)4 Cursor (android.database.Cursor)3 Event (com.amazonaws.services.pinpoint.model.Event)2 JSONObject (org.json.JSONObject)2 Service (android.app.Service)1 Bundle (android.os.Bundle)1 MockAppDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockAppDetails)1 EventsBatch (com.amazonaws.services.pinpoint.model.EventsBatch)1 PublicEndpoint (com.amazonaws.services.pinpoint.model.PublicEndpoint)1 PutEventsRequest (com.amazonaws.services.pinpoint.model.PutEventsRequest)1 Locale (java.util.Locale)1 JSONException (org.json.JSONException)1