use of com.onesignal.ShadowRoboNotificationManager.PostedNotification in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldGenerate2BasicGroupNotifications.
@Test
public void shouldGenerate2BasicGroupNotifications() throws Exception {
// Make sure the notification got posted and the content is correct.
Bundle bundle = getBaseNotifBundle();
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
Assert.assertEquals(2, postedNotifs.size());
// Test summary notification
Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();
PostedNotification postedNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals(notifMessage, postedNotification.getShadow().getContentText());
Assert.assertEquals(Notification.FLAG_GROUP_SUMMARY, postedNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
// Test Android Wear notification
postedNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals(notifMessage, postedNotification.getShadow().getContentText());
Assert.assertEquals(0, postedNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
// Badge count should only be one as only one notification is visible in the notification area.
Assert.assertEquals(1, ShadowBadgeCountUpdater.lastCount);
// Should be 2 DB entries (summary and individual)
SQLiteDatabase readableDb = OneSignalDbHelper.getInstance(blankActivity).getReadableDatabase();
Cursor cursor = readableDb.query(NotificationTable.TABLE_NAME, null, null, null, null, null, null);
Assert.assertEquals(2, cursor.getCount());
cursor.close();
// Add another notification to the group.
ShadowRoboNotificationManager.notifications.clear();
bundle = new Bundle();
bundle.putString("alert", "Notif test 2");
bundle.putString("custom", "{\"i\": \"UUID2\"}");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
postedNotifs = ShadowRoboNotificationManager.notifications;
Assert.assertEquals(2, postedNotifs.size());
Assert.assertEquals(2, ShadowBadgeCountUpdater.lastCount);
postedNotifsIterator = postedNotifs.entrySet().iterator();
postedNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals("2 new messages", postedNotification.getShadow().getContentText());
Assert.assertEquals(Notification.FLAG_GROUP_SUMMARY, postedNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
// Test Android Wear notification
postedNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals("Notif test 2", postedNotification.getShadow().getContentText());
Assert.assertEquals(0, postedNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
// Should be 3 DB entries (summary and 2 individual)
readableDb = OneSignalDbHelper.getInstance(blankActivity).getReadableDatabase();
cursor = readableDb.query(NotificationTable.TABLE_NAME, null, null, null, null, null, null);
Assert.assertEquals(3, cursor.getCount());
// Open summary notification
postedNotifsIterator = postedNotifs.entrySet().iterator();
postedNotification = postedNotifsIterator.next().getValue();
Intent intent = createOpenIntent(postedNotification.id, bundle).putExtra("summary", "test1");
NotificationOpenedProcessor_processFromContext(blankActivity, intent);
Assert.assertEquals(0, ShadowBadgeCountUpdater.lastCount);
// 2 open calls should fire.
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
ShadowRoboNotificationManager.notifications.clear();
// Send 3rd notification
bundle = new Bundle();
bundle.putString("alert", "Notif test 3");
bundle.putString("custom", "{\"i\": \"UUID3\"}");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
postedNotifsIterator = postedNotifs.entrySet().iterator();
postedNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals("Notif test 3", postedNotification.getShadow().getContentText());
Assert.assertEquals(Notification.FLAG_GROUP_SUMMARY, postedNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
Assert.assertEquals(1, ShadowBadgeCountUpdater.lastCount);
cursor.close();
}
use of com.onesignal.ShadowRoboNotificationManager.PostedNotification in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldCancelNotificationAndUpdateSummary.
@Test
@Config(shadows = { ShadowNotificationRestorer.class })
public void shouldCancelNotificationAndUpdateSummary() throws Exception {
// Setup - Init
OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification);
OneSignal.init(blankActivity, "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
threadAndTaskWait();
// Setup - Display 3 notifications that will be grouped together.
Bundle bundle = getBaseNotifBundle("UUID1");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
bundle = getBaseNotifBundle("UUID2");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
bundle = getBaseNotifBundle("UUID3");
bundle.putString("grp", "test1");
NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();
// Test - 3 notifis + 1 summary
Assert.assertEquals(4, postedNotifs.size());
// Test - First notification should be the summary
PostedNotification postedSummaryNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals("3 new messages", postedSummaryNotification.getShadow().getContentText());
Assert.assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
// Setup - Let's cancel a child notification.
PostedNotification postedNotification = postedNotifsIterator.next().getValue();
OneSignal.cancelNotification(postedNotification.id);
// Test - It should update summary text to say 2 notifications
postedNotifs = ShadowRoboNotificationManager.notifications;
// 2 notifis + 1 summary
Assert.assertEquals(3, postedNotifs.size());
postedNotifsIterator = postedNotifs.entrySet().iterator();
postedSummaryNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals("2 new messages", postedSummaryNotification.getShadow().getContentText());
Assert.assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
// Setup - Let's cancel a 2nd child notification.
postedNotification = postedNotifsIterator.next().getValue();
OneSignal.cancelNotification(postedNotification.id);
// Test - It should update summary notification to be the text of the last remaining one.
postedNotifs = ShadowRoboNotificationManager.notifications;
// 1 notifis + 1 summary
Assert.assertEquals(2, postedNotifs.size());
postedNotifsIterator = postedNotifs.entrySet().iterator();
postedSummaryNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals(notifMessage, postedSummaryNotification.getShadow().getContentText());
Assert.assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY);
// Test - Let's make sure we will have our last notification too
postedNotification = postedNotifsIterator.next().getValue();
Assert.assertEquals(notifMessage, postedNotification.getShadow().getContentText());
// Setup - Let's cancel our 3rd and last child notification.
OneSignal.cancelNotification(postedNotification.id);
// Test - No more notifications! :)
postedNotifs = ShadowRoboNotificationManager.notifications;
Assert.assertEquals(0, postedNotifs.size());
}
Aggregations