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