use of com.optimizely.ab.event.EventProcessor 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);
}
use of com.optimizely.ab.event.EventProcessor in project android-sdk by optimizely.
the class OptimizelyManagerTest method initializeAsyncWithEnvironment.
@Test
public void initializeAsyncWithEnvironment() {
Logger logger = mock(Logger.class);
DatafileHandler datafileHandler = mock(DefaultDatafileHandler.class);
EventHandler eventHandler = mock(DefaultEventHandler.class);
EventProcessor eventProcessor = mock(EventProcessor.class);
final OptimizelyManager optimizelyManager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, 3600L, datafileHandler, null, 3600L, eventHandler, eventProcessor, null, null, null);
/*
* Scenario#1: when datafile is not Empty
* Scenario#2: when datafile is Empty
*/
doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
((DatafileLoadedListener) invocation.getArguments()[2]).onDatafileLoaded(null);
return null;
}
}).when(optimizelyManager.getDatafileHandler()).downloadDatafile(any(Context.class), any(DatafileConfig.class), any(DatafileLoadedListener.class));
OptimizelyStartListener listener = new OptimizelyStartListener() {
@Override
public void onStart(OptimizelyClient optimizely) {
assertNotNull(optimizelyManager.getOptimizely());
assertNotNull(optimizelyManager.getDatafileHandler());
assertNull(optimizelyManager.getOptimizelyStartListener());
}
};
optimizelyManager.initialize(InstrumentationRegistry.getInstrumentation().getContext(), R.raw.datafile, listener);
verify(optimizelyManager.getDatafileHandler()).startBackgroundUpdates(any(Context.class), eq(new DatafileConfig(testProjectId, testSdkKey)), eq(3600L), any(DatafileLoadedListener.class));
assertEquals(optimizelyManager.isDatafileCached(InstrumentationRegistry.getInstrumentation().getTargetContext()), false);
assertEquals(optimizelyManager.getDatafileUrl(), String.format((DatafileConfig.defaultHost + DatafileConfig.environmentUrlSuffix), testSdkKey));
}
use of com.optimizely.ab.event.EventProcessor in project java-sdk by optimizely.
the class OptimizelyTest method testClose.
@Test
public void testClose() throws Exception {
EventHandler mockEventHandler = mock(EventHandler.class, withSettings().extraInterfaces(AutoCloseable.class));
ProjectConfigManager mockProjectConfigManager = mock(ProjectConfigManager.class, withSettings().extraInterfaces(AutoCloseable.class));
EventProcessor mockEventProcessor = mock(EventProcessor.class, withSettings().extraInterfaces(AutoCloseable.class));
Optimizely optimizely = Optimizely.builder().withEventHandler(mockEventHandler).withEventProcessor(mockEventProcessor).withConfigManager(mockProjectConfigManager).build();
optimizely.close();
verify((AutoCloseable) mockEventHandler).close();
verify((AutoCloseable) mockProjectConfigManager).close();
verify((AutoCloseable) mockEventProcessor).close();
}
use of com.optimizely.ab.event.EventProcessor in project android-sdk by optimizely.
the class OptimizelyManagerTest method initializeSyncWithEnvironment.
@Test
public void initializeSyncWithEnvironment() {
Logger logger = mock(Logger.class);
DatafileHandler datafileHandler = mock(DefaultDatafileHandler.class);
EventHandler eventHandler = mock(DefaultEventHandler.class);
EventProcessor eventProcessor = mock(EventProcessor.class);
OptimizelyManager optimizelyManager = new OptimizelyManager(testProjectId, testSdkKey, null, logger, 3600L, datafileHandler, null, 3600L, eventHandler, eventProcessor, null, null, null);
/*
* Scenario#1: when datafile is not Empty
* Scenario#2: when datafile is Empty
*/
optimizelyManager.initialize(InstrumentationRegistry.getInstrumentation().getTargetContext(), R.raw.datafile);
assertEquals(optimizelyManager.isDatafileCached(InstrumentationRegistry.getInstrumentation().getTargetContext()), false);
assertEquals(optimizelyManager.getDatafileUrl(), String.format((DatafileConfig.defaultHost + DatafileConfig.environmentUrlSuffix), testSdkKey));
assertNotNull(optimizelyManager.getOptimizely());
assertNotNull(optimizelyManager.getDatafileHandler());
optimizelyManager.initialize(InstrumentationRegistry.getInstrumentation().getTargetContext(), (Integer) null);
verify(logger).error(eq("Invalid datafile resource ID."));
}
Aggregations