Search in sources :

Example 26 with AnalyticsEvent

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

the class ADMNotificationClientTest method testADMMessageReceivedInBackgroundWithConfigShouldPostNotificationsInForegroundSet.

@Test
public void testADMMessageReceivedInBackgroundWithConfigShouldPostNotificationsInForegroundSet() throws JSONException {
    when(mockPinpointConfiguration.getShouldPostNotificationsInForeground()).thenReturn(true);
    // 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(false);
    NotificationClient.CampaignPushResult pushResult = target.handleCampaignPush(buildNotificationDetails());
    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_background"));
    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(5));
    assertThat(receivedEvent.getAttribute("isOptedOut"), is("true"));
    assertThat(receivedEvent.getAttribute("isAppInForeground"), is("false"));
    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 that the notification is posted even though the app is in the foreground, will actually
    // be OPTED_OUT, since the test can't get the app icon id.
    assertTrue(pushResult.equals(NotificationClient.CampaignPushResult.OPTED_OUT));
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) Map(java.util.Map) Test(org.junit.Test)

Example 27 with AnalyticsEvent

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

the class BaiduNotificationClientTest method testBaiduMessageReceivedDefaultDoNotPostNotificationInForeground.

@Test
public void testBaiduMessageReceivedDefaultDoNotPostNotificationInForeground() throws JSONException {
    // Force the app to be in the background.
    final AppUtil appUtil = Mockito.mock(AppUtil.class);
    Whitebox.setInternalState(target.notificationClientBase, "appUtil", appUtil);
    Mockito.when(appUtil.isAppInForeground()).thenReturn(false);
    NotificationClient.CampaignPushResult pushResult = target.handleCampaignPush(buildNotificationDetails());
    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_background"));
    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(5));
    assertThat(receivedEvent.getAttribute("isOptedOut"), is("true"));
    assertThat(receivedEvent.getAttribute("isAppInForeground"), is("false"));
    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));
    assertTrue(pushResult.equals(NotificationClient.CampaignPushResult.OPTED_OUT));
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) Map(java.util.Map) Test(org.junit.Test)

Example 28 with AnalyticsEvent

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

the class BaiduNotificationClientTest method testBaiduMessageReceivedInForegroundDefaultConfig.

@Test
public void testBaiduMessageReceivedInForegroundDefaultConfig() 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.handleCampaignPush(buildNotificationDetails());
    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)

Example 29 with AnalyticsEvent

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

the class BaiduNotificationClientTest method testBaiduMessageReceivedInForegroundWithConfigShouldPostNotificationsInForegroundSet.

@Test
public void testBaiduMessageReceivedInForegroundWithConfigShouldPostNotificationsInForegroundSet() throws JSONException {
    when(mockPinpointConfiguration.getShouldPostNotificationsInForeground()).thenReturn(true);
    // 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.handleCampaignPush(buildNotificationDetails());
    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(5));
    assertThat(receivedEvent.getAttribute("isOptedOut"), is("true"));
    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 that the notification is posted even though the app is in the foreground, will actually
    // be OPTED_OUT, since the test can't get the app icon id.
    assertTrue(pushResult.equals(NotificationClient.CampaignPushResult.OPTED_OUT));
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) Map(java.util.Map) Test(org.junit.Test)

Example 30 with AnalyticsEvent

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

the class BaiduNotificationClientTest method testBaiduMessageReceivedInBackgroundWithConfigShouldPostNotificationsInForegroundSet.

@Test
public void testBaiduMessageReceivedInBackgroundWithConfigShouldPostNotificationsInForegroundSet() throws JSONException {
    when(mockPinpointConfiguration.getShouldPostNotificationsInForeground()).thenReturn(true);
    // 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(false);
    NotificationClient.CampaignPushResult pushResult = target.handleCampaignPush(buildNotificationDetails());
    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_background"));
    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(5));
    assertThat(receivedEvent.getAttribute("isOptedOut"), is("true"));
    assertThat(receivedEvent.getAttribute("isAppInForeground"), is("false"));
    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 that the notification is posted even though the app is in the foreground, will actually
    // be OPTED_OUT, since the test can't get the app icon id.
    assertTrue(pushResult.equals(NotificationClient.CampaignPushResult.OPTED_OUT));
}
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