Search in sources :

Example 6 with OSTrackerFactory

use of com.onesignal.influence.data.OSTrackerFactory in project OneSignal-Android-SDK by OneSignal.

the class InAppMessageIntegrationTests method testInAppMessageClickActionOutcomeV2.

@Test
public void testInAppMessageClickActionOutcomeV2() 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);
    // 1. Init OneSignal
    OneSignalInit();
    threadAndTaskWait();
    // Enable influence outcomes
    trackerFactory.saveInfluenceParams(new OneSignalPackagePrivateHelper.RemoteOutcomeParams());
    // 2. Create an IAM
    final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.SESSION_TIME, null, OSTestTrigger.OSTriggerOperator.NOT_EXISTS.toString(), null);
    final JSONArray outcomes = new JSONArray();
    outcomes.put(new JSONObject() {

        {
            put("name", IAM_OUTCOME_NAME);
        }
    });
    JSONObject action = new JSONObject() {

        {
            put("id", IAM_CLICK_ID);
            put("outcomes", outcomes);
        }
    };
    OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
    // 3. Ensure outcome is sent
    assertMeasureOnV2AtIndex(3, "outcome_name", new JSONArray().put(message.getMessageId()), new JSONArray(), null, null);
}
Also used : MockOSLog(com.onesignal.MockOSLog) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) OneSignalPackagePrivateHelper(com.onesignal.OneSignalPackagePrivateHelper) Test(org.junit.Test)

Example 7 with OSTrackerFactory

use of com.onesignal.influence.data.OSTrackerFactory in project OneSignal-Android-SDK by OneSignal.

the class LocationIntegrationTests 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 8 with OSTrackerFactory

use of com.onesignal.influence.data.OSTrackerFactory in project OneSignal-Android-SDK by OneSignal.

the class OutcomeEventIntegrationTests method testOnV2OutcomeNameSentWithMeasureOncePerSession_whenSendingMultipleUniqueOutcomes_inUnattributedSession.

@Test
public void testOnV2OutcomeNameSentWithMeasureOncePerSession_whenSendingMultipleUniqueOutcomes_inUnattributedSession() 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);
    OneSignalInit();
    threadAndTaskWait();
    // Make sure session is UNATTRIBUTED
    assertNotificationChannelUnattributedInfluence();
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Check measure end point was most recent request and contains received notification
    assertMeasureOnV2AtIndex(2, ONESIGNAL_OUTCOME_NAME, null, null, null, null);
    // Only 3 requests have been made
    assertRestCalls(3);
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Make still only 3 requests have been made
    assertRestCalls(3);
    // Background app
    pauseActivity(blankActivityController);
    // Wait 31 seconds to start new session
    time.advanceSystemTimeBy(31);
    // Foreground app
    blankActivityController.resume();
    threadAndTaskWait();
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Make sure session is UNATTRIBUTED
    assertNotificationChannelUnattributedInfluence();
    // Check measure end point was most recent request and contains received notification
    assertMeasureOnV2AtIndex(4, ONESIGNAL_OUTCOME_NAME, null, null, null, null);
}
Also used : OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) Test(org.junit.Test)

Example 9 with OSTrackerFactory

use of com.onesignal.influence.data.OSTrackerFactory in project OneSignal-Android-SDK by OneSignal.

the class OutcomeEventIntegrationTests method testOnV2UniqueOutcomeMeasureOnlySentOncePerNotification_whenSendingMultipleUniqueOutcomes_inIndirectSessions.

@Test
@Config(shadows = { ShadowGenerateNotification.class })
public void testOnV2UniqueOutcomeMeasureOnlySentOncePerNotification_whenSendingMultipleUniqueOutcomes_inIndirectSessions() 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);
    foregroundAppAfterReceivingNotification();
    // Check notificationIds equal indirectNotificationIds from OSSessionManager
    JSONArray notificationIds = new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "1");
    assertEquals(notificationIds, trackerFactory.getNotificationChannelTracker().getIndirectIds());
    // Make sure session is INDIRECT
    assertNotificationChannelIndirectInfluence(1);
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Check measure end point was most recent request and contains received notification
    assertMeasureOnV2AtIndex(2, ONESIGNAL_OUTCOME_NAME, null, null, new JSONArray(), notificationIds);
    // Only 3 requests have been made
    assertRestCalls(3);
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Make still only 3 requests have been made
    assertRestCalls(3);
    // Background app
    pauseActivity(blankActivityController);
    // Receive notification
    Bundle bundle = getBaseNotifBundle(ONESIGNAL_NOTIFICATION_ID + "2");
    FCMBroadcastReceiver_onReceived_withBundle(blankActivity, bundle);
    // Wait 31 seconds to start new session
    time.advanceSystemTimeBy(31);
    // Foreground app will start a new session upgrade
    blankActivityController.resume();
    threadAndTaskWait();
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Check notificationIds are not equal indirectNotificationIds from OSSessionManager
    notificationIds.put(ONESIGNAL_NOTIFICATION_ID + "2");
    assertEquals(notificationIds, trackerFactory.getNotificationChannelTracker().getIndirectIds());
    // Make sure session is INDIRECT
    assertNotificationChannelIndirectInfluence(2);
    // Check measure end point was most recent request and contains received notification
    assertMeasureOnV2AtIndex(4, ONESIGNAL_OUTCOME_NAME, null, null, new JSONArray(), new JSONArray().put(ONESIGNAL_NOTIFICATION_ID + "2"));
}
Also used : OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) Bundle(android.os.Bundle) GenerateNotificationRunner.getBaseNotifBundle(com.test.onesignal.GenerateNotificationRunner.getBaseNotifBundle) FCMBroadcastReceiver_onReceived_withBundle(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle) JSONArray(org.json.JSONArray) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 10 with OSTrackerFactory

use of com.onesignal.influence.data.OSTrackerFactory in project OneSignal-Android-SDK by OneSignal.

the class OutcomeEventUnitTests method beforeEachTest.

// Before each test
@Before
public void beforeEachTest() throws Exception {
    outcomeEvents = null;
    MockOSTimeImpl time = new MockOSTimeImpl();
    dbHelper = new MockOneSignalDBHelper(ApplicationProvider.getApplicationContext());
    // Mock on a custom HashMap in order to not use custom context
    preferences = new MockOSSharedPreferences();
    trackerFactory = new OSTrackerFactory(preferences, logWrapper, time);
    sessionManager = new MockSessionManager(sessionListener, trackerFactory, logWrapper);
    service = new MockOneSignalAPIClient();
    OSOutcomeEventsFactory factory = new OSOutcomeEventsFactory(logWrapper, service, dbHelper, preferences);
    controller = new MockOutcomeEventsController(sessionManager, factory);
    TestHelpers.beforeTestInitAndCleanup();
    repository = factory.getRepository();
    trackerFactory.saveInfluenceParams(new OneSignalPackagePrivateHelper.RemoteOutcomeParams());
    OneSignal.setAppId(APP_ID);
}
Also used : OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) MockOneSignalDBHelper(com.onesignal.MockOneSignalDBHelper) MockOSTimeImpl(com.onesignal.MockOSTimeImpl) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) MockOneSignalAPIClient(com.onesignal.MockOneSignalAPIClient) OSOutcomeEventsFactory(com.onesignal.outcomes.data.OSOutcomeEventsFactory) MockOutcomeEventsController(com.onesignal.MockOutcomeEventsController) OneSignalPackagePrivateHelper(com.onesignal.OneSignalPackagePrivateHelper) Before(org.junit.Before)

Aggregations

OSTrackerFactory (com.onesignal.influence.data.OSTrackerFactory)17 MockOSSharedPreferences (com.onesignal.MockOSSharedPreferences)16 MockSessionManager (com.onesignal.MockSessionManager)16 MockOSLog (com.onesignal.MockOSLog)9 MockOSTimeImpl (com.onesignal.MockOSTimeImpl)9 Before (org.junit.Before)9 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