Search in sources :

Example 6 with FCMBroadcastReceiver_processBundle

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

the class GenerateNotificationRunner method testNotificationProcessing_completeNotCalled.

@Test
@Config(shadows = { ShadowGenerateNotification.class, ShadowTimeoutHandler.class })
public void testNotificationProcessing_completeNotCalled() throws Exception {
    // 1. Setup correct notification extension service class
    startRemoteNotificationReceivedHandlerService("com.test.onesignal.GenerateNotificationRunner$" + "RemoteNotificationReceivedHandler_notificationReceivedCompleteNotCalled");
    // 2. Add app context and setup the established notification extension service
    OneSignal.initWithContext(ApplicationProvider.getApplicationContext());
    OneSignal_setupNotificationServiceExtension();
    // Mock timeout to 1, given that we are not calling complete inside RemoteNotificationReceivedHandler we depend on the timeout complete
    ShadowTimeoutHandler.setMockDelayMillis(1);
    // 3. Receive a notification
    Bundle bundle = getBaseNotifBundle();
    FCMBroadcastReceiver_processBundle(blankActivity, bundle);
    threadAndTaskWait();
    // 4. Make sure service was called
    assertNotNull(lastServiceNotificationReceivedEvent);
    // Notification save is done on the OSTimeoutHandler, we wait until the notification is saved
    Awaitility.await().atMost(new Duration(3, TimeUnit.SECONDS)).pollInterval(new Duration(100, TimeUnit.MILLISECONDS)).untilAsserted(() -> {
        // 5. Make sure 1 notification exists in DB
        assertNotificationDbRecords(1);
    });
}
Also used : Bundle(android.os.Bundle) FCMBroadcastReceiver_processBundle(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_processBundle) OneSignalPackagePrivateHelper.createInternalPayloadBundle(com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle) Duration(org.awaitility.Duration) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 7 with FCMBroadcastReceiver_processBundle

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

the class GenerateNotificationRunner method testNotificationProcessing_silentNotification.

@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void testNotificationProcessing_silentNotification() throws Exception {
    // 1. Setup correct notification extension service class
    startRemoteNotificationReceivedHandlerService("com.test.onesignal.GenerateNotificationRunner$" + "RemoteNotificationReceivedHandler_notificationReceivedDisplayNotCalled");
    // 2. Add app context and setup the established notification extension service
    OneSignal.initWithContext(ApplicationProvider.getApplicationContext());
    OneSignal_setupNotificationServiceExtension();
    // 3. Receive a notification
    Bundle bundle = getBaseNotifBundle();
    FCMBroadcastReceiver_processBundle(blankActivity, bundle);
    threadAndTaskWait();
    // 4. Make sure service was called
    assertNotNull(lastServiceNotificationReceivedEvent);
    // 5. Make sure running on main thread check was not called, this is only called for showing the notification
    assertFalse(ShadowGenerateNotification.isRunningOnMainThreadCheckCalled());
    // 6. Make sure 1 notification exists in DB
    assertNotificationDbRecords(1);
}
Also used : Bundle(android.os.Bundle) FCMBroadcastReceiver_processBundle(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_processBundle) OneSignalPackagePrivateHelper.createInternalPayloadBundle(com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 8 with FCMBroadcastReceiver_processBundle

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

the class GenerateNotificationRunner method testNotificationProcessing_whenAlertIsNull.

@Test
public // No MainThread mock since notification is not being display
void testNotificationProcessing_whenAlertIsNull() throws Exception {
    // 1. Setup correct notification extension service class
    startRemoteNotificationReceivedHandlerService("com.test.onesignal.GenerateNotificationRunner$" + "RemoteNotificationReceivedHandler_notificationReceivedDisplayAndComplete");
    // 2. Add app context and setup the established notification extension service
    OneSignal.initWithContext(ApplicationProvider.getApplicationContext());
    OneSignal_setupNotificationServiceExtension();
    // 3. Receive a notification
    Bundle bundle = getBaseNotifBundle();
    bundle.remove("alert");
    FCMBroadcastReceiver_processBundle(blankActivity, bundle);
    threadAndTaskWait();
    // 4. Make sure service was called
    assertNotNull(lastServiceNotificationReceivedEvent);
    // 5. Make sure 1 notification exists in DB
    assertNotificationDbRecords(1);
}
Also used : Bundle(android.os.Bundle) FCMBroadcastReceiver_processBundle(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_processBundle) OneSignalPackagePrivateHelper.createInternalPayloadBundle(com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle) Test(org.junit.Test)

Aggregations

Bundle (android.os.Bundle)8 FCMBroadcastReceiver_processBundle (com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_processBundle)8 OneSignalPackagePrivateHelper.createInternalPayloadBundle (com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle)7 Test (org.junit.Test)7 Config (org.robolectric.annotation.Config)6 Duration (org.awaitility.Duration)3 OneSignalPackagePrivateHelper (com.onesignal.OneSignalPackagePrivateHelper)2 OSNotification (com.onesignal.OSNotification)1 PostedNotification (com.onesignal.ShadowRoboNotificationManager.PostedNotification)1 GenerateNotificationRunner.getBaseNotifBundle (com.test.onesignal.GenerateNotificationRunner.getBaseNotifBundle)1 BigInteger (java.math.BigInteger)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1