Search in sources :

Example 11 with DefaultDatafileHandler

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

the class OptimizelyManagerBuilderTest method testBuildWithDatafileHandler.

@Test
public void testBuildWithDatafileHandler() {
    DefaultDatafileHandler dfHandler = mock(DefaultDatafileHandler.class);
    OptimizelyManager manager = OptimizelyManager.builder().withSDKKey(testSdkKey).withDatafileDownloadInterval(61L, TimeUnit.SECONDS).withDatafileHandler(dfHandler).build(mockContext);
    manager.initialize(mockContext, minDatafile);
    assertEquals(manager.getDatafileHandler(), dfHandler);
}
Also used : DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) Test(org.junit.Test)

Example 12 with DefaultDatafileHandler

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

the class OptimizelyManagerBuilderTest method testBuilderWithOutDatafileConfig.

@Test
public void testBuilderWithOutDatafileConfig() {
    ErrorHandler errorHandler = new ErrorHandler() {

        @Override
        public <T extends OptimizelyRuntimeException> void handleError(T exception) throws T {
            logger.error("Inside error handler", exception);
        }
    };
    OptimizelyManager manager = OptimizelyManager.builder().withUserProfileService(DefaultUserProfileService.newInstance(testProjectId, InstrumentationRegistry.getInstrumentation().getTargetContext())).withDatafileDownloadInterval(30L, TimeUnit.MINUTES).withEventDispatchInterval(30L, TimeUnit.MINUTES).withDatafileHandler(new DefaultDatafileHandler()).withErrorHandler(errorHandler).withEventHandler(DefaultEventHandler.getInstance(InstrumentationRegistry.getInstrumentation().getTargetContext())).withLogger(logger).build(InstrumentationRegistry.getInstrumentation().getTargetContext());
    assertNull(manager);
}
Also used : ErrorHandler(com.optimizely.ab.error.ErrorHandler) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) OptimizelyRuntimeException(com.optimizely.ab.OptimizelyRuntimeException) Test(org.junit.Test)

Example 13 with DefaultDatafileHandler

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

the class OptimizelyManagerBuilderTest method testBuilderWithDatafileConfig.

@Test
public void testBuilderWithDatafileConfig() {
    ErrorHandler errorHandler = new ErrorHandler() {

        @Override
        public <T extends OptimizelyRuntimeException> void handleError(T exception) throws T {
            logger.error("Inside error handler", exception);
        }
    };
    OptimizelyManager manager = OptimizelyManager.builder().withUserProfileService(DefaultUserProfileService.newInstance(testProjectId, InstrumentationRegistry.getInstrumentation().getTargetContext())).withDatafileDownloadInterval(30L, TimeUnit.MINUTES).withEventDispatchInterval(30L, TimeUnit.MINUTES).withDatafileHandler(new DefaultDatafileHandler()).withErrorHandler(errorHandler).withDatafileConfig(new DatafileConfig(null, "sdkKey7")).withEventHandler(DefaultEventHandler.getInstance(InstrumentationRegistry.getInstrumentation().getTargetContext())).withLogger(logger).build(InstrumentationRegistry.getInstrumentation().getTargetContext());
    assertNotNull(manager);
    assertNotNull(manager.getDatafileHandler());
    assertNotNull(manager.getUserProfileService());
    assertNotNull(manager.getEventHandler(InstrumentationRegistry.getInstrumentation().getTargetContext()));
    manager.stop(InstrumentationRegistry.getInstrumentation().getTargetContext());
}
Also used : ErrorHandler(com.optimizely.ab.error.ErrorHandler) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) OptimizelyRuntimeException(com.optimizely.ab.OptimizelyRuntimeException) Test(org.junit.Test)

Example 14 with DefaultDatafileHandler

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

the class OptimizelyManagerTest method initializeSyncWithDownloadToCacheDisabled.

@Test
public void initializeSyncWithDownloadToCacheDisabled() {
    boolean downloadToCache = false;
    boolean updateConfigOnNewDatafile = true;
    // 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) {
    // 
    }
    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)

Example 15 with DefaultDatafileHandler

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

the class OptimizelyManagerTest method initializeSyncWithUpdateOnNewDatafileEnabledWithPeriodicPollingEnabled.

@Test
public void initializeSyncWithUpdateOnNewDatafileEnabledWithPeriodicPollingEnabled() {
    boolean downloadToCache = true;
    boolean updateConfigOnNewDatafile = true;
    // enable polling
    int pollingInterval = 30;
    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) {
    // 
    }
    assertEquals(client.getOptimizelyConfig().getRevision(), "241");
}
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