Search in sources :

Example 1 with OSTrackerFactory

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

the class OutcomeEventIntegrationTests method testOnV2CorrectOutcomeSent_fromNotificationOpenedHandler.

@Test
public void testOnV2CorrectOutcomeSent_fromNotificationOpenedHandler() 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);
    // Init OneSignal with a custom opened handler
    OneSignalInit(new OneSignal.OSNotificationOpenedHandler() {

        @Override
        public void notificationOpened(OSNotificationOpenedResult result) {
            OneSignal.sendOutcome(ONESIGNAL_OUTCOME_NAME);
        }
    });
    threadAndTaskWait();
    // Background app
    pauseActivity(blankActivityController);
    // Receive and open a notification
    OneSignal_handleNotificationOpen(blankActivity, new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\" } }]"), false, ONESIGNAL_NOTIFICATION_ID);
    threadAndTaskWait();
    // Foreground the application
    blankActivityController.resume();
    threadAndTaskWait();
    JSONArray notificationIds = new JSONArray();
    notificationIds.put(ONESIGNAL_NOTIFICATION_ID);
    // Make sure a measure request is made with the correct session and notifications
    assertMeasureOnV2AtIndex(3, ONESIGNAL_OUTCOME_NAME, new JSONArray(), notificationIds, null, null);
}
Also used : OneSignal(com.onesignal.OneSignal) ShadowOneSignal(com.onesignal.ShadowOneSignal) OSNotificationOpenedResult(com.onesignal.OSNotificationOpenedResult) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) JSONArray(org.json.JSONArray) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) Test(org.junit.Test)

Example 2 with OSTrackerFactory

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

the class OutcomeEventIntegrationTests method testSendOutcomesFailWhenRequiresUserPrivacyConsent.

@Test
public void testSendOutcomesFailWhenRequiresUserPrivacyConsent() 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();
    assertRestCalls(2);
    OneSignal.setRequiresUserPrivacyConsent(true);
    // Make sure session is UNATTRIBUTED
    assertNotificationChannelUnattributedInfluence();
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Check that the task has been queued until consent is given
    assertRestCalls(2);
    // Send outcome event
    OneSignal.sendOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Ensure still only 2 requests have been made
    assertRestCalls(2);
    OneSignal.provideUserConsent(true);
    threadAndTaskWait();
    // Send unique outcome event
    OneSignal.sendUniqueOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Send outcome event
    OneSignal.sendOutcome(ONESIGNAL_OUTCOME_NAME);
    threadAndTaskWait();
    // Make sure session is UNATTRIBUTED
    assertNotificationChannelUnattributedInfluence();
    // Check measure end point was most recent request and contains received notification
    assertMeasureOnV2AtIndex(3, 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 3 with OSTrackerFactory

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

the class OutcomeEventIntegrationTests method beforeEachTest.

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

Example 4 with OSTrackerFactory

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

the class OutcomeEventV2UnitTests method beforeEachTest.

// Before each test
@Before
public void beforeEachTest() throws Exception {
    outcomeEvents = null;
    dbHelper = new MockOneSignalDBHelper(ApplicationProvider.getApplicationContext());
    // Mock on a custom HashMap in order to not use custom context
    preferences = new MockOSSharedPreferences();
    // Save v2 flag
    String v2Name = preferences.getOutcomesV2KeyName();
    preferences.saveBool(preferences.getPreferencesName(), v2Name, true);
    MockOSTimeImpl time = new MockOSTimeImpl();
    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)

Example 5 with OSTrackerFactory

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

the class SessionManagerUnitTests method beforeEachTest.

// Before each test
@Before
public void beforeEachTest() throws Exception {
    MockOSLog logger = new MockOSLog();
    MockOSTimeImpl time = new MockOSTimeImpl();
    preferences = new MockOSSharedPreferences();
    trackerFactory = new OSTrackerFactory(preferences, logger, time);
    sessionManager = new MockSessionManager(sessionListener, trackerFactory, logger);
    TestHelpers.beforeTestInitAndCleanup();
}
Also used : MockOSLog(com.onesignal.MockOSLog) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) MockOSTimeImpl(com.onesignal.MockOSTimeImpl) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) 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