use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.
the class OptimizelyManagerBuilderTest method testBuilderWith.
@Test
public void testBuilderWith() {
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(testProjectId).withUserProfileService(DefaultUserProfileService.newInstance(testProjectId, InstrumentationRegistry.getInstrumentation().getTargetContext())).withDatafileDownloadInterval(30L).withEventDispatchInterval(30L).withDatafileHandler(new DefaultDatafileHandler()).withErrorHandler(errorHandler).withEventHandler(DefaultEventHandler.getInstance(InstrumentationRegistry.getInstrumentation().getTargetContext())).withLogger(logger).build(InstrumentationRegistry.getInstrumentation().getTargetContext());
assertNotNull(manager);
assertNotNull(manager.getDatafileHandler());
assertNotNull(manager.getUserProfileService());
assertNotNull(manager.getErrorHandler(InstrumentationRegistry.getInstrumentation().getTargetContext()));
assertNotNull(manager.getEventHandler(InstrumentationRegistry.getInstrumentation().getTargetContext()));
}
use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.
the class OptimizelyManagerBuilderTest method testBuilderWithOutDatafileConfigWithSdkKey.
@Test
public void testBuilderWithOutDatafileConfigWithSdkKey() {
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).withSDKKey("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 initializeSyncWithUpdateOnNewDatafileEnabled.
@Test
public void initializeSyncWithUpdateOnNewDatafileEnabled() {
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 initializeSyncWithResourceDatafileNoCacheWithDefaultParams.
@Test
public void initializeSyncWithResourceDatafileNoCacheWithDefaultParams() {
// 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);
verify(manager).initialize(eq(context), eq(defaultDatafile), eq(true), eq(false));
}
use of com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler in project android-sdk by optimizely.
the class OptimizelyManagerTest method setup.
@Before
public void setup() throws Exception {
logger = mock(Logger.class);
executor = Executors.newSingleThreadExecutor();
defaultDatafileHandler = mock(DefaultDatafileHandler.class);
EventHandler eventHandler = mock(DefaultEventHandler.class);
EventProcessor eventProcessor = mock(EventProcessor.class);
optimizelyManager = OptimizelyManager.builder(testProjectId).withLogger(logger).withDatafileDownloadInterval(3600L).withDatafileHandler(defaultDatafileHandler).withEventDispatchInterval(3600L).withEventHandler(eventHandler).withEventProcessor(eventProcessor).build(InstrumentationRegistry.getInstrumentation().getTargetContext());
defaultDatafile = optimizelyManager.getDatafile(InstrumentationRegistry.getInstrumentation().getTargetContext(), R.raw.datafile);
ProjectConfig config = new DatafileProjectConfig.Builder().withDatafile(defaultDatafile).build();
when(defaultDatafileHandler.getConfig()).thenReturn(config);
}
Aggregations