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);
}
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);
}
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());
}
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");
}
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");
}
Aggregations