Search in sources :

Example 1 with EventProcessor

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);
}
Also used : ProjectConfig(com.optimizely.ab.config.ProjectConfig) DatafileProjectConfig(com.optimizely.ab.config.DatafileProjectConfig) EventProcessor(com.optimizely.ab.event.EventProcessor) EventHandler(com.optimizely.ab.event.EventHandler) DefaultEventHandler(com.optimizely.ab.android.event_handler.DefaultEventHandler) Logger(org.slf4j.Logger) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) Before(org.junit.Before)

Example 2 with EventProcessor

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));
}
Also used : Context(android.content.Context) DatafileLoadedListener(com.optimizely.ab.android.datafile_handler.DatafileLoadedListener) EventHandler(com.optimizely.ab.event.EventHandler) DefaultEventHandler(com.optimizely.ab.android.event_handler.DefaultEventHandler) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Logger(org.slf4j.Logger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EventProcessor(com.optimizely.ab.event.EventProcessor) DatafileHandler(com.optimizely.ab.android.datafile_handler.DatafileHandler) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) Test(org.junit.Test)

Example 3 with EventProcessor

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();
}
Also used : BatchEventProcessor(com.optimizely.ab.event.BatchEventProcessor) EventProcessor(com.optimizely.ab.event.EventProcessor) EventHandler(com.optimizely.ab.event.EventHandler) Test(org.junit.Test)

Example 4 with EventProcessor

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."));
}
Also used : EventProcessor(com.optimizely.ab.event.EventProcessor) EventHandler(com.optimizely.ab.event.EventHandler) DefaultEventHandler(com.optimizely.ab.android.event_handler.DefaultEventHandler) Logger(org.slf4j.Logger) DatafileHandler(com.optimizely.ab.android.datafile_handler.DatafileHandler) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) Test(org.junit.Test)

Aggregations

EventHandler (com.optimizely.ab.event.EventHandler)4 EventProcessor (com.optimizely.ab.event.EventProcessor)4 DefaultDatafileHandler (com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler)3 DefaultEventHandler (com.optimizely.ab.android.event_handler.DefaultEventHandler)3 Test (org.junit.Test)3 Logger (org.slf4j.Logger)3 DatafileHandler (com.optimizely.ab.android.datafile_handler.DatafileHandler)2 Context (android.content.Context)1 DatafileLoadedListener (com.optimizely.ab.android.datafile_handler.DatafileLoadedListener)1 DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)1 DatafileProjectConfig (com.optimizely.ab.config.DatafileProjectConfig)1 ProjectConfig (com.optimizely.ab.config.ProjectConfig)1 BatchEventProcessor (com.optimizely.ab.event.BatchEventProcessor)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1