Search in sources :

Example 6 with DatafileConfig

use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.

the class DatafileReschedulerTest method dispatchingOneWithoutEnvironment.

@Test
@SdkSuppress(maxSdkVersion = Build.VERSION_CODES.N)
public void dispatchingOneWithoutEnvironment() throws InterruptedException {
    // projectId: number string
    // sdkKey: alphabet string
    backgroundWatchersCache.setIsWatching(new DatafileConfig("1", null), true);
    dispatcher.dispatch();
    TimeUnit.SECONDS.sleep(1);
    verify(dispatcher).rescheduleService(captor.capture());
    assertEquals(new DatafileConfig("1", null), captor.getValue());
}
Also used : DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 7 with DatafileConfig

use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.

the class DatafileReschedulerTest method dispatchingManyForLegacy.

@Test
@SdkSuppress(maxSdkVersion = Build.VERSION_CODES.N)
public void dispatchingManyForLegacy() throws InterruptedException {
    backgroundWatchersCache.setIsWatching(new DatafileConfig("1", null), true);
    backgroundWatchersCache.setIsWatching(new DatafileConfig("2", "A"), true);
    backgroundWatchersCache.setIsWatching(new DatafileConfig(null, "B"), true);
    backgroundWatchersCache.setIsWatching(new DatafileConfig("3", null), true);
    dispatcher.dispatch();
    TimeUnit.SECONDS.sleep(1);
    verify(dispatcher, times(4)).rescheduleService(captor.capture());
    List array = new ArrayList<String>();
    for (DatafileConfig config : captor.getAllValues()) {
        array.add(config.toString());
    }
    assert (array.contains(new DatafileConfig("1", null).toString()));
    assert (array.contains(new DatafileConfig(null, "A").toString()));
    assert (array.contains(new DatafileConfig(null, "B").toString()));
    assert (array.contains(new DatafileConfig("3", null).toString()));
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 8 with DatafileConfig

use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.

the class DatafileReschedulerTest method dispatchingManyForJobScheduler.

@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void dispatchingManyForJobScheduler() throws InterruptedException {
    backgroundWatchersCache.setIsWatching(new DatafileConfig("1", null), true);
    backgroundWatchersCache.setIsWatching(new DatafileConfig(null, "A"), true);
    dispatcher.dispatch();
    TimeUnit.SECONDS.sleep(1);
    verify(dispatcher, never()).rescheduleService(captor.capture());
}
Also used : DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 9 with DatafileConfig

use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.

the class DatafileReschedulerTest method dispatchingOneWithEnvironment.

@Test
@SdkSuppress(maxSdkVersion = Build.VERSION_CODES.N)
public void dispatchingOneWithEnvironment() throws InterruptedException {
    // projectId: number string
    // sdkKey: alphabet string
    backgroundWatchersCache.setIsWatching(new DatafileConfig(null, "A"), true);
    dispatcher.dispatch();
    TimeUnit.SECONDS.sleep(1);
    verify(dispatcher).rescheduleService(captor.capture());
    assertEquals(new DatafileConfig(null, "A"), captor.getValue());
}
Also used : DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 10 with DatafileConfig

use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.

the class DatafileServiceTest method testGetDatafileEnvironmentUrl.

@Test
public void testGetDatafileEnvironmentUrl() {
    // HARD-CODING link here to make sure we don't unintentionally mess up the datafile version
    // and url by accidentally changing those constants.
    // us to update this test.
    String datafileUrl = new DatafileConfig("1", "2").getUrl();
    assertEquals("https://cdn.optimizely.com/datafiles/2.json", datafileUrl);
}
Also used : DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Test(org.junit.Test)

Aggregations

DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)38 Test (org.junit.Test)34 Context (android.content.Context)15 URL (java.net.URL)8 Client (com.optimizely.ab.android.shared.Client)7 Cache (com.optimizely.ab.android.shared.Cache)5 SdkSuppress (androidx.test.filters.SdkSuppress)4 DatafileLoadedListener (com.optimizely.ab.android.datafile_handler.DatafileLoadedListener)4 Intent (android.content.Intent)2 Data (androidx.work.Data)2 DefaultDatafileHandler (com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler)2 DefaultUserProfileService (com.optimizely.ab.android.user_profile.DefaultUserProfileService)2 UserProfileService (com.optimizely.ab.bucketing.UserProfileService)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Logger (org.slf4j.Logger)2 AlarmManager (android.app.AlarmManager)1 IBinder (android.os.IBinder)1 NonNull (androidx.annotation.NonNull)1