Search in sources :

Example 1 with OSNotificationAction

use of com.onesignal.OSNotificationAction in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method testOSNotificationOpenResultToJSONObject.

@Test
public void testOSNotificationOpenResultToJSONObject() throws Exception {
    OSNotificationOpenResult osNotificationOpenResult = new OSNotificationOpenResult();
    osNotificationOpenResult.notification = createTestOSNotification();
    osNotificationOpenResult.action = new OSNotificationAction();
    osNotificationOpenResult.action.type = OSNotificationAction.ActionType.Opened;
    JSONObject testJsonObj = osNotificationOpenResult.toJSONObject();
    JSONObject additionalData = testJsonObj.optJSONObject("notification").optJSONObject("payload").optJSONObject("additionalData");
    Assert.assertEquals("bar", additionalData.optString("foo"));
    JSONObject firstGroupedNotification = (JSONObject) testJsonObj.optJSONObject("notification").optJSONArray("groupedNotifications").get(0);
    Assert.assertEquals("collapseId1", firstGroupedNotification.optString("collapseId"));
}
Also used : JSONObject(org.json.JSONObject) OneSignalPackagePrivateHelper.bundleAsJSONObject(com.onesignal.OneSignalPackagePrivateHelper.bundleAsJSONObject) OSNotificationAction(com.onesignal.OSNotificationAction) OSNotificationOpenResult(com.onesignal.OSNotificationOpenResult) Test(org.junit.Test)

Aggregations

OSNotificationAction (com.onesignal.OSNotificationAction)1 OSNotificationOpenResult (com.onesignal.OSNotificationOpenResult)1 OneSignalPackagePrivateHelper.bundleAsJSONObject (com.onesignal.OneSignalPackagePrivateHelper.bundleAsJSONObject)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1