Search in sources :

Example 31 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method nextResponseMultiplePendingMessages.

private void nextResponseMultiplePendingMessages() throws JSONException {
    final OSTestInAppMessageInternal testFirstMessage = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 3);
    final OSTestInAppMessageInternal testSecondMessage = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.CUSTOM, "test_2", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2);
    setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {

        {
            add(testFirstMessage);
            add(testSecondMessage);
        }
    });
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal)

Example 32 with OSTestInAppMessageInternal

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

the class DatabaseRunner method shouldUpgradeDbFromV6ToV7.

@Test
public void shouldUpgradeDbFromV6ToV7() throws JSONException {
    // 1. Init DB as version 6
    ShadowOneSignalDbHelper.DATABASE_VERSION = 6;
    SQLiteDatabase writableDatabase = dbHelper.getSQLiteDatabaseWithRetries();
    // Create table with the schema we had in DB v6
    writableDatabase.execSQL(SQL_CREATE_OUTCOME_REVISION2_ENTRIES);
    writableDatabase.execSQL(SQL_CREATE_UNIQUE_OUTCOME_REVISION1_ENTRIES);
    Cursor cursor = writableDatabase.rawQuery("SELECT name FROM sqlite_master WHERE type ='table' AND name='" + InAppMessageTable.TABLE_NAME + "'", null);
    boolean exist = false;
    if (cursor != null) {
        exist = cursor.getCount() > 0;
        cursor.close();
    }
    // 2. Table must not exist
    assertFalse(exist);
    writableDatabase.setVersion(6);
    writableDatabase.close();
    // Create an IAM
    final OSTestInAppMessageInternal inAppMessage = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.SESSION_TIME, null, OneSignalPackagePrivateHelper.OSTestTrigger.OSTriggerOperator.NOT_EXISTS.toString(), null);
    inAppMessage.setDisplayedInSession(true);
    ContentValues values = new ContentValues();
    values.put(InAppMessageTable.COLUMN_NAME_MESSAGE_ID, inAppMessage.getMessageId());
    values.put(InAppMessageTable.COLUMN_NAME_DISPLAY_QUANTITY, inAppMessage.getRedisplayStats().getDisplayQuantity());
    values.put(InAppMessageTable.COLUMN_NAME_LAST_DISPLAY, inAppMessage.getRedisplayStats().getLastDisplayTime());
    values.put(InAppMessageTable.COLUMN_CLICK_IDS, inAppMessage.getClickedClickIds().toString());
    values.put(InAppMessageTable.COLUMN_DISPLAYED_IN_SESSION, inAppMessage.isDisplayedInSession());
    // 3. Clear the cache of the DB so it reloads the file and next getSQLiteDatabaseWithRetries will auto trigger the update
    ShadowOneSignalDbHelper.restSetStaticFields();
    // 4. Opening the DB will auto trigger the update.
    List<OSTestInAppMessageInternal> savedInAppMessages = TestHelpers.getAllInAppMessages(dbHelper);
    assertEquals(savedInAppMessages.size(), 0);
    writableDatabase = dbHelper.getSQLiteDatabaseWithRetries();
    // 5. Table now must exist
    writableDatabase.insert(InAppMessageTable.TABLE_NAME, null, values);
    writableDatabase.close();
    List<OSTestInAppMessageInternal> savedInAppMessagesAfterCreation = TestHelpers.getAllInAppMessages(dbHelper);
    assertEquals(savedInAppMessagesAfterCreation.size(), 1);
    OSTestInAppMessageInternal savedInAppMessage = savedInAppMessagesAfterCreation.get(0);
    assertEquals(savedInAppMessage.getRedisplayStats().getDisplayQuantity(), inAppMessage.getRedisplayStats().getDisplayQuantity());
    assertEquals(savedInAppMessage.getRedisplayStats().getLastDisplayTime(), inAppMessage.getRedisplayStats().getLastDisplayTime());
    assertEquals(savedInAppMessage.getClickedClickIds().toString(), inAppMessage.getClickedClickIds().toString());
    assertEquals(savedInAppMessage.isDisplayedInSession(), inAppMessage.isDisplayedInSession());
}
Also used : ContentValues(android.content.ContentValues) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 33 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method testLiquidIAMDisplayWaitsForGetTags.

@Test
public void testLiquidIAMDisplayWaitsForGetTags() throws Exception {
    final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndLiquid(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2);
    setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {

        {
            add(message);
        }
    });
    // Init OneSignal IAM with redisplay
    OneSignalInit();
    threadAndTaskWait();
    // Add trigger to make IAM display
    OneSignal.addTrigger("test_1", 2);
    assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
    // Wait for both getTags and get IAM HTML to be called
    Awaitility.await().atMost(new Duration(150, TimeUnit.MILLISECONDS)).pollInterval(new Duration(10, TimeUnit.MILLISECONDS)).until(() -> ShadowOneSignalRestClient.requests.size() == 4);
    int requestSize = ShadowOneSignalRestClient.requests.size();
    ShadowOneSignalRestClient.Request getTagsRequest = ShadowOneSignalRestClient.requests.get(requestSize - 1);
    assertEquals("players/" + "df8f05be55ba-b2f7f966-d8cc-11e4-bed1" + "?app_id=" + "b2f7f966-d8cc-11e4-bed1-df8f05be55ba", getTagsRequest.url);
    // Runnable for get tags is run
    threadAndTaskWait();
    // Runnable for webView is run from background thread to main thread
    threadAndTaskWait();
    ShadowOneSignalRestClient.Request lastRequest = ShadowOneSignalRestClient.requests.get(ShadowOneSignalRestClient.requests.size() - 1);
    while (!lastRequest.url.equals("in_app_messages/" + message.getMessageId() + "/impression")) {
        // Check impression request by waiting until animationEnd
        threadAndTaskWait();
        lastRequest = ShadowOneSignalRestClient.requests.get(ShadowOneSignalRestClient.requests.size() - 1);
    }
    assertEquals("in_app_messages/" + message.getMessageId() + "/impression", lastRequest.url);
}
Also used : ShadowOneSignalRestClient(com.onesignal.ShadowOneSignalRestClient) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) Duration(org.awaitility.Duration) SuppressLint(android.annotation.SuppressLint) Test(org.junit.Test)

Example 34 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method testInAppMessageOnlyReceivesOneImpression_onColdRestart.

@Test
public void testInAppMessageOnlyReceivesOneImpression_onColdRestart() throws Exception {
    // Init OneSignal
    OneSignalInit();
    threadAndTaskWait();
    // Create an IAM
    final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.SESSION_TIME, null, OSTestTrigger.OSTriggerOperator.NOT_EXISTS.toString(), null);
    // Trigger the impression request and caching of the impressioned messageId
    OneSignalPackagePrivateHelper.onMessageWasShown(message);
    // Cold restart app and re-init OneSignal
    fastColdRestartApp();
    OneSignalInit();
    threadAndTaskWait();
    OneSignalPackagePrivateHelper.onMessageWasShown(message);
    // Since the app restart and another message shown callback only 1 more request should exist
    // So verify 4 requests exist (3 old and 1 new)
    ShadowOneSignalRestClient.Request mostRecentRequest = ShadowOneSignalRestClient.requests.get(3);
    assertEquals(4, ShadowOneSignalRestClient.requests.size());
    // Now verify the most recent request was not a impression request
    boolean isImpressionUrl = mostRecentRequest.url.equals("in_app_messages/" + message.getMessageId() + "/impression");
    assertFalse(isImpressionUrl);
}
Also used : ShadowOneSignalRestClient(com.onesignal.ShadowOneSignalRestClient) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) Test(org.junit.Test)

Example 35 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method testInAppMessageDisplayMultipleTimes_onColdRestart.

@Test
public void testInAppMessageDisplayMultipleTimes_onColdRestart() throws Exception {
    final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2, LIMIT, DELAY);
    setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {

        {
            add(message);
        }
    });
    // Init OneSignal with IAM with redisplay
    OneSignalInit();
    threadAndTaskWait();
    // Add trigger to make IAM display
    OneSignal.addTrigger("test_1", 2);
    assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
    // Check impression request
    int requestSize = ShadowOneSignalRestClient.requests.size();
    ShadowOneSignalRestClient.Request iamImpressionRequest = ShadowOneSignalRestClient.requests.get(requestSize - 1);
    assertEquals("in_app_messages/" + message.getMessageId() + "/impression", iamImpressionRequest.url);
    // Dismiss IAM will make display quantity increase and last display time to change
    OneSignalPackagePrivateHelper.dismissCurrentMessage();
    // Check IAM removed from queue
    assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
    // Check if data after dismiss is set correctly
    assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().size());
    assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getDisplayQuantity());
    long lastDisplayTime = OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getLastDisplayTime();
    assertTrue(lastDisplayTime > 0);
    // Wait for the delay between redisplay
    time.advanceSystemTimeBy(DELAY);
    // Swipe away app
    fastColdRestartApp();
    // Cold Start app
    setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {

        {
            add(message);
        }
    });
    OneSignalInit();
    threadAndTaskWait();
    // Check No IAMs
    assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
    // Set same trigger, should display again
    OneSignal.addTrigger("test_1", 2);
    assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
    // Check impression request is sent again
    int requestSizeAfterRedisplay = ShadowOneSignalRestClient.requests.size();
    ShadowOneSignalRestClient.Request iamImpressionRequestAfterRedisplay = ShadowOneSignalRestClient.requests.get(requestSizeAfterRedisplay - 1);
    assertEquals("in_app_messages/" + message.getMessageId() + "/impression", iamImpressionRequestAfterRedisplay.url);
    OneSignalPackagePrivateHelper.dismissCurrentMessage();
    // Check if data after dismiss is set correctly
    assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().size());
    assertEquals(2, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getDisplayQuantity());
    assertTrue(OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getLastDisplayTime() - lastDisplayTime >= DELAY);
}
Also used : ShadowOneSignalRestClient(com.onesignal.ShadowOneSignalRestClient) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) SuppressLint(android.annotation.SuppressLint) Test(org.junit.Test)

Aggregations

OSTestInAppMessageInternal (com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal)50 Test (org.junit.Test)43 JSONObject (org.json.JSONObject)19 ShadowOneSignalRestClient (com.onesignal.ShadowOneSignalRestClient)15 JSONArray (org.json.JSONArray)14 OneSignalPackagePrivateHelper (com.onesignal.OneSignalPackagePrivateHelper)8 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 OSTestTrigger (com.onesignal.OneSignalPackagePrivateHelper.OSTestTrigger)4 Duration (org.awaitility.Duration)4 MockOSLog (com.onesignal.MockOSLog)3 MockOSSharedPreferences (com.onesignal.MockOSSharedPreferences)3 MockSessionManager (com.onesignal.MockSessionManager)3 OneSignal (com.onesignal.OneSignal)3 OSTrackerFactory (com.onesignal.influence.data.OSTrackerFactory)3 JSONException (org.json.JSONException)3 Cursor (android.database.Cursor)2 OSInAppMessageAction (com.onesignal.OSInAppMessageAction)2 HashSet (java.util.HashSet)2 ThrowingRunnable (org.awaitility.core.ThrowingRunnable)2