use of com.onesignal.OSNotificationPayload in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method createTestOSNotification.
// ####### Unit test helper methods ########
private static OSNotification createTestOSNotification() throws Exception {
OSNotification osNotification = new OSNotification();
osNotification.payload = new OSNotificationPayload();
osNotification.payload.body = "msg_body";
osNotification.payload.additionalData = new JSONObject("{\"foo\": \"bar\"}");
osNotification.payload.actionButtons = new ArrayList<>();
OSNotificationPayload.ActionButton actionButton = new OSNotificationPayload.ActionButton();
actionButton.text = "text";
actionButton.id = "id";
osNotification.payload.actionButtons.add(actionButton);
osNotification.displayType = OSNotification.DisplayType.None;
osNotification.groupedNotifications = new ArrayList<>();
OSNotificationPayload groupedPayload = new OSNotificationPayload();
groupedPayload.collapseId = "collapseId1";
osNotification.groupedNotifications.add(groupedPayload);
return osNotification;
}
use of com.onesignal.OSNotificationPayload in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotificationRunner method shouldFireNotificationExtenderService.
@Test
@Config(shadows = { ShadowOneSignal.class })
public void shouldFireNotificationExtenderService() throws Exception {
// Test that GCM receiver starts the NotificationExtenderServiceTest when it is in the AndroidManifest.xml
Bundle bundle = getBaseNotifBundle();
Intent serviceIntent = new Intent();
serviceIntent.setPackage("com.onesignal.example");
serviceIntent.setAction("com.onesignal.NotificationExtender");
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.serviceInfo = new ServiceInfo();
resolveInfo.serviceInfo.name = "com.onesignal.example.NotificationExtenderServiceTest";
RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForIntent(serviceIntent, resolveInfo);
boolean ret = OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle(blankActivity, bundle);
Assert.assertTrue(ret);
Intent intent = Shadows.shadowOf(blankActivity).getNextStartedService();
Assert.assertEquals("com.onesignal.NotificationExtender", intent.getAction());
// Test that all options are set.
NotificationExtenderServiceTest service = startNotificationExtender(createInternalPayloadBundle(getBundleWithAllOptionsSet()), NotificationExtenderServiceTest.class);
OSNotificationReceivedResult notificationReceived = service.notification;
OSNotificationPayload notificationPayload = notificationReceived.payload;
Assert.assertEquals("Test H", notificationPayload.title);
Assert.assertEquals("Test B", notificationPayload.body);
Assert.assertEquals("9764eaeb-10ce-45b1-a66d-8f95938aaa51", notificationPayload.notificationID);
Assert.assertEquals(0, notificationPayload.lockScreenVisibility);
Assert.assertEquals("FF0000FF", notificationPayload.smallIconAccentColor);
Assert.assertEquals("703322744261", notificationPayload.fromProjectNumber);
Assert.assertEquals("FFFFFF00", notificationPayload.ledColor);
Assert.assertEquals("big_picture", notificationPayload.bigPicture);
Assert.assertEquals("large_icon", notificationPayload.largeIcon);
Assert.assertEquals("small_icon", notificationPayload.smallIcon);
Assert.assertEquals("test_sound", notificationPayload.sound);
Assert.assertEquals("You test $[notif_count] MSGs!", notificationPayload.groupMessage);
Assert.assertEquals("http://google.com", notificationPayload.launchURL);
Assert.assertEquals(10, notificationPayload.priority);
Assert.assertEquals("a_key", notificationPayload.collapseId);
Assert.assertEquals("id1", notificationPayload.actionButtons.get(0).id);
Assert.assertEquals("button1", notificationPayload.actionButtons.get(0).text);
Assert.assertEquals("ic_menu_share", notificationPayload.actionButtons.get(0).icon);
Assert.assertEquals("id2", notificationPayload.actionButtons.get(1).id);
Assert.assertEquals("button2", notificationPayload.actionButtons.get(1).text);
Assert.assertEquals("ic_menu_send", notificationPayload.actionButtons.get(1).icon);
Assert.assertEquals("test_image_url", notificationPayload.backgroundImageLayout.image);
Assert.assertEquals("FF000000", notificationPayload.backgroundImageLayout.titleTextColor);
Assert.assertEquals("FFFFFFFF", notificationPayload.backgroundImageLayout.bodyTextColor);
JSONObject additionalData = notificationPayload.additionalData;
Assert.assertEquals("myValue", additionalData.getString("myKey"));
Assert.assertEquals("nValue", additionalData.getJSONObject("nested").getString("nKey"));
Assert.assertNotSame(-1, service.notificationId);
// Test a basic notification without anything special.
startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle()), NotificationExtenderServiceTest.class);
Assert.assertFalse(ShadowOneSignal.messages.contains("Error assigning"));
// Test that a notification is still displayed if the developer's code in onNotificationProcessing throws an Exception.
NotificationExtenderServiceTest.throwInAppCode = true;
startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle("NewUUID1")), NotificationExtenderServiceTest.class);
Assert.assertTrue(ShadowOneSignal.messages.contains("onNotificationProcessing throw an exception"));
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
Assert.assertEquals(3, postedNotifs.size());
}
Aggregations