Search in sources :

Example 1 with DefaultDatafileHandler

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()));
}
Also used : ErrorHandler(com.optimizely.ab.error.ErrorHandler) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) OptimizelyRuntimeException(com.optimizely.ab.OptimizelyRuntimeException) Test(org.junit.Test)

Example 2 with DefaultDatafileHandler

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());
}
Also used : ErrorHandler(com.optimizely.ab.error.ErrorHandler) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) OptimizelyRuntimeException(com.optimizely.ab.OptimizelyRuntimeException) Test(org.junit.Test)

Example 3 with DefaultDatafileHandler

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

Example 4 with DefaultDatafileHandler

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));
}
Also used : Context(android.content.Context) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 5 with DefaultDatafileHandler

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);
}
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)

Aggregations

DefaultDatafileHandler (com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler)16 Test (org.junit.Test)14 Logger (org.slf4j.Logger)10 Context (android.content.Context)9 DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)8 DatafileLoadedListener (com.optimizely.ab.android.datafile_handler.DatafileLoadedListener)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 OptimizelyRuntimeException (com.optimizely.ab.OptimizelyRuntimeException)4 ErrorHandler (com.optimizely.ab.error.ErrorHandler)4 DefaultEventHandler (com.optimizely.ab.android.event_handler.DefaultEventHandler)3 EventHandler (com.optimizely.ab.event.EventHandler)3 DatafileProjectConfig (com.optimizely.ab.config.DatafileProjectConfig)2 ProjectConfig (com.optimizely.ab.config.ProjectConfig)2 EventProcessor (com.optimizely.ab.event.EventProcessor)2 Before (org.junit.Before)2 AlarmManager (android.app.AlarmManager)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Build (android.os.Build)1