use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.
the class OptimizelyManagerTest method initializeSyncWithResourceDatafileNoCache.
@Test
public void initializeSyncWithResourceDatafileNoCache() {
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 = spy(new OptimizelyManager(testProjectId, testSdkKey, null, logger, pollingInterval, datafileHandler, null, 0, null, null, null, null, null));
datafileHandler.removeSavedDatafile(context, manager.getDatafileConfig());
OptimizelyClient client = manager.initialize(context, R.raw.datafile, downloadToCache, updateConfigOnNewDatafile);
verify(manager).initialize(eq(context), eq(defaultDatafile), eq(downloadToCache), eq(updateConfigOnNewDatafile));
}
use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.
the class OptimizelyManagerTest method initializeSyncWithUpdateOnNewDatafileEnabledWithPeriodicPollingDisabled.
@Test
public void initializeSyncWithUpdateOnNewDatafileEnabledWithPeriodicPollingDisabled() {
boolean downloadToCache = true;
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(), "241");
}
use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.
the class OptimizelyManagerTest method initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingEnabled.
@Test
public void initializeSyncWithUpdateOnNewDatafileDisabledWithPeriodicPollingEnabled() {
boolean downloadToCache = true;
boolean updateConfigOnNewDatafile = false;
// 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((Answer<Object>) 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(), "241");
}
use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.
the class OptimizelyManagerTest method initializeSyncWithUpdateOnNewDatafileDisabled.
// Init Sync Flows
@Test
public void initializeSyncWithUpdateOnNewDatafileDisabled() {
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) {
//
}
assertEquals(client.getOptimizelyConfig().getRevision(), "7");
}
use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.
the class OptimizelyManager method buildOptimizely.
private OptimizelyClient buildOptimizely(@NonNull Context context, @NonNull String datafile) throws ConfigParseException {
EventHandler eventHandler = getEventHandler(context);
EventBatch.ClientEngine clientEngine = OptimizelyClientEngine.getClientEngineFromContext(context);
Optimizely.Builder builder = Optimizely.builder();
builder.withEventHandler(eventHandler);
builder.withEventProcessor(eventProcessor);
if (datafileHandler instanceof DefaultDatafileHandler) {
DefaultDatafileHandler handler = (DefaultDatafileHandler) datafileHandler;
handler.setDatafile(datafile);
builder.withConfigManager(handler);
} else {
builder.withDatafile(datafile);
}
// override client sdk name/version to be included in events
builder.withClientInfo(clientEngine, sdkVersion);
if (errorHandler != null) {
builder.withErrorHandler(errorHandler);
}
builder.withUserProfileService(userProfileService);
builder.withNotificationCenter(notificationCenter);
builder.withDefaultDecideOptions(defaultDecideOptions);
Optimizely optimizely = builder.build();
return new OptimizelyClient(optimizely, LoggerFactory.getLogger(OptimizelyClient.class));
}
Aggregations