Search in sources :

Example 16 with DefaultDatafileHandler

use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.

the class OptimizelyManagerTest method initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingDisabled.

@Test
public void initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingDisabled() {
    boolean downloadToCache = true;
    boolean updateConfigOnNewDatafile = false;
    // disable polling
    int pollingInterval = 0;
    DefaultDatafileHandler datafileHandler = spy(new DefaultDatafileHandler());
    Logger logger = mock(Logger.class);
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    OptimizelyManager manager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0, null, null, null, null, null);
    doAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            String newDatafile = manager.getDatafile(context, R.raw.datafile_api);
            datafileHandler.saveDatafile(context, manager.getDatafileConfig(), newDatafile);
            return null;
        }
    }).when(manager.getDatafileHandler()).downloadDatafile(any(Context.class), any(DatafileConfig.class), any(DatafileLoadedListener.class));
    OptimizelyClient client = manager.initialize(context, defaultDatafile, downloadToCache, updateConfigOnNewDatafile);
    try {
        executor.awaitTermination(1, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    // 
    }
    // when periodic polling enabled, project config always updated on cache datafile update (regardless of "updateConfigOnNewDatafile" setting)
    // wait for first download.
    assertEquals(client.getOptimizelyConfig().getRevision(), "7");
}
Also used : Context(android.content.Context) DatafileLoadedListener(com.optimizely.ab.android.datafile_handler.DatafileLoadedListener) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) Logger(org.slf4j.Logger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Aggregations

DefaultDatafileHandler (com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler)16 Test (org.junit.Test)14 Logger (org.slf4j.Logger)10 Context (android.content.Context)9 DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)8 DatafileLoadedListener (com.optimizely.ab.android.datafile_handler.DatafileLoadedListener)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 OptimizelyRuntimeException (com.optimizely.ab.OptimizelyRuntimeException)4 ErrorHandler (com.optimizely.ab.error.ErrorHandler)4 DefaultEventHandler (com.optimizely.ab.android.event_handler.DefaultEventHandler)3 EventHandler (com.optimizely.ab.event.EventHandler)3 DatafileProjectConfig (com.optimizely.ab.config.DatafileProjectConfig)2 ProjectConfig (com.optimizely.ab.config.ProjectConfig)2 EventProcessor (com.optimizely.ab.event.EventProcessor)2 Before (org.junit.Before)2 AlarmManager (android.app.AlarmManager)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Build (android.os.Build)1