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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations