Search in sources :

Example 11 with MockSessionManager

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

the class MainOneSignalClassRunner method beforeEachTest.

@Before
public void beforeEachTest() throws Exception {
    blankActivityController = Robolectric.buildActivity(BlankActivity.class).create();
    blankActivity = blankActivityController.get();
    time = new MockOSTimeImpl();
    trackerFactory = new OSTrackerFactory(new MockOSSharedPreferences(), new MockOSLog(), time);
    sessionManager = new MockSessionManager(OneSignal_getSessionListener(), trackerFactory, new MockOSLog());
    dbHelper = new MockOneSignalDBHelper(ApplicationProvider.getApplicationContext());
    TestHelpers.setupTestWorkManager(blankActivity);
    cleanUp();
    OneSignal_setTime(time);
}
Also used : MockOSLog(com.onesignal.MockOSLog) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) MockOneSignalDBHelper(com.onesignal.MockOneSignalDBHelper) MockOSTimeImpl(com.onesignal.MockOSTimeImpl) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) Before(org.junit.Before)

Example 12 with MockSessionManager

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

the class OutcomeEventIntegrationTests method testOnV2UniqueOutcomeMeasureOnlySentOncePerClickedNotification_whenSendingMultipleUniqueOutcomes_inDirectSession.

@Test
public void testOnV2UniqueOutcomeMeasureOnlySentOncePerClickedNotification_whenSendingMultipleUniqueOutcomes_inDirectSession() throws Exception {
    // Enable IAM v2
    preferences = new MockOSSharedPreferences();
    trackerFactory = new OSTrackerFactory(preferences, logger, time);
    sessionManager = new MockSessionManager(sessionListener, trackerFactory, logger);
    preferences.saveBool(preferences.getPreferencesName(), preferences.getOutcomesV2KeyName(), true);
    OneSignal_setSharedPreferences(preferences);
    foregroundAppAfterClickingNotification();
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    JSONArray notificationIds = new JSONArray();
    notificationIds.put(ONESIGNAL_NOTIFICATION_ID + "1");
    // Check measure end point was most recent request and contains clicked notification
    assertMeasureOnV2AtIndex(3, ONESIGNAL_OUTCOME_NAME, new JSONArray(), notificationIds, null, null);
    // Only 4 requests have been made
    assertRestCalls(4);
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Make still only 4 requests have been made
    assertRestCalls(4);
}
Also used : OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) JSONArray(org.json.JSONArray) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) Test(org.junit.Test)

Example 13 with MockSessionManager

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

the class InAppMessageIntegrationTests method beforeEachTest.

@Before
public void beforeEachTest() throws Exception {
    ShadowDynamicTimer.shouldScheduleTimers = true;
    time = new MockOSTimeImpl();
    preferences = new MockOSSharedPreferences();
    trackerFactory = new OSTrackerFactory(preferences, new MockOSLog(), time);
    sessionManager = new MockSessionManager(OneSignal_getSessionListener(), trackerFactory, new MockOSLog());
    blankActivityController = Robolectric.buildActivity(BlankActivity.class).create();
    blankActivity = blankActivityController.get();
    dbHelper = new MockOneSignalDBHelper(ApplicationProvider.getApplicationContext());
    TestHelpers.beforeTestInitAndCleanup();
    // Set remote_params GET response
    setRemoteParamsGetHtmlResponse();
}
Also used : MockOSLog(com.onesignal.MockOSLog) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) MockOneSignalDBHelper(com.onesignal.MockOneSignalDBHelper) MockOSTimeImpl(com.onesignal.MockOSTimeImpl) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) Before(org.junit.Before)

Example 14 with MockSessionManager

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

the class SynchronizerIntegrationTests method beforeEachTest.

@Before
public void beforeEachTest() throws Exception {
    blankActivityController = Robolectric.buildActivity(BlankActivity.class).create();
    blankActivity = blankActivityController.get();
    time = new MockOSTimeImpl();
    trackerFactory = new OSTrackerFactory(new MockOSSharedPreferences(), new MockOSLog(), time);
    sessionManager = new MockSessionManager(OneSignal_getSessionListener(), trackerFactory, new MockOSLog());
    dbHelper = new MockOneSignalDBHelper(ApplicationProvider.getApplicationContext());
    TestHelpers.setupTestWorkManager(blankActivity);
    cleanUp();
    OneSignal_setTime(time);
}
Also used : MockOSLog(com.onesignal.MockOSLog) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) MockOneSignalDBHelper(com.onesignal.MockOneSignalDBHelper) MockOSTimeImpl(com.onesignal.MockOSTimeImpl) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) Before(org.junit.Before)

Example 15 with MockSessionManager

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

the class InAppMessageIntegrationTests method testOnIAMActionSendsOutcome_usingOutcomesV2.

@Test
public void testOnIAMActionSendsOutcome_usingOutcomesV2() throws Exception {
    // Enable IAM v2
    preferences = new MockOSSharedPreferences();
    preferences.saveBool(preferences.getPreferencesName(), preferences.getOutcomesV2KeyName(), true);
    trackerFactory = new OSTrackerFactory(preferences, new MockOSLog(), time);
    sessionManager = new MockSessionManager(OneSignal_getSessionListener(), trackerFactory, new MockOSLog());
    OneSignal_setSharedPreferences(preferences);
    OneSignal_setTrackerFactory(trackerFactory);
    OneSignal_setSessionManager(sessionManager);
    final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2);
    setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {

        {
            add(message);
        }
    });
    // 1. Init OneSignal
    OneSignalInit();
    threadAndTaskWait();
    // Enable influence outcomes
    trackerFactory.saveInfluenceParams(new OneSignalPackagePrivateHelper.RemoteOutcomeParams());
    final OSInAppMessageAction[] lastAction = new OSInAppMessageAction[1];
    OneSignal.setInAppMessageClickHandler(new OneSignal.OSInAppMessageClickHandler() {

        @Override
        public void inAppMessageClicked(OSInAppMessageAction result) {
            lastAction[0] = result;
            // Ensure we are on the main thread when running the callback, since the app developer
            // will most likely need to update UI.
            assertMainThread();
            OneSignal.sendOutcome("test");
            try {
                // Ensure outcome is sent
                assertMeasureOnV2AtIndex(4, "test", new JSONArray().put(message.getMessageId()), new JSONArray(), null, null);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    threadAndTaskWait();
    // Add trigger to make IAM display
    OneSignal.addTrigger("test_1", 2);
    assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
    OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, new JSONObject() {

        {
            put("id", "button_id_123");
            put("name", "my_click_name");
        }
    });
    // Ensure we fire public callback that In-App was clicked.
    assertEquals(lastAction[0].getClickName(), "my_click_name");
}
Also used : MockOSLog(com.onesignal.MockOSLog) OneSignal(com.onesignal.OneSignal) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) OneSignalPackagePrivateHelper(com.onesignal.OneSignalPackagePrivateHelper) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) JSONObject(org.json.JSONObject) MockSessionManager(com.onesignal.MockSessionManager) OSInAppMessageAction(com.onesignal.OSInAppMessageAction) Test(org.junit.Test)

Aggregations

MockSessionManager (com.onesignal.MockSessionManager)16 OSTrackerFactory (com.onesignal.influence.data.OSTrackerFactory)16 MockOSSharedPreferences (com.onesignal.MockOSSharedPreferences)15 MockOSLog (com.onesignal.MockOSLog)8 MockOSTimeImpl (com.onesignal.MockOSTimeImpl)8 Before (org.junit.Before)8 Test (org.junit.Test)8 MockOneSignalDBHelper (com.onesignal.MockOneSignalDBHelper)7 OneSignalPackagePrivateHelper (com.onesignal.OneSignalPackagePrivateHelper)6 JSONArray (org.json.JSONArray)6 OneSignal (com.onesignal.OneSignal)3 OSTestInAppMessageInternal (com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal)3 JSONObject (org.json.JSONObject)3 MockOneSignalAPIClient (com.onesignal.MockOneSignalAPIClient)2 MockOutcomeEventsController (com.onesignal.MockOutcomeEventsController)2 OSInAppMessageAction (com.onesignal.OSInAppMessageAction)2 OSOutcomeEventsFactory (com.onesignal.outcomes.data.OSOutcomeEventsFactory)2 JSONException (org.json.JSONException)2 Bundle (android.os.Bundle)1 OSNotificationOpenedResult (com.onesignal.OSNotificationOpenedResult)1