Search in sources :

Example 36 with DatafileConfig

use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.

the class OptimizelyManagerBuilderTest method testBuilderWithDatafileConfig.

@Test
public void testBuilderWithDatafileConfig() {
    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).withDatafileConfig(new DatafileConfig(null, "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) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler) OptimizelyRuntimeException(com.optimizely.ab.OptimizelyRuntimeException) Test(org.junit.Test)

Example 37 with DatafileConfig

use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.

the class OptimizelyManagerTest method injectOptimizely.

@Test
public void injectOptimizely() {
    Context context = mock(Context.class);
    UserProfileService userProfileService = mock(UserProfileService.class);
    OptimizelyStartListener startListener = mock(OptimizelyStartListener.class);
    optimizelyManager.setOptimizelyStartListener(startListener);
    optimizelyManager.injectOptimizely(context, userProfileService, minDatafile);
    try {
        executor.awaitTermination(5, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        fail("Timed out");
    }
    verify(logger).info("Sending Optimizely instance to listener");
    verify(startListener).onStart(any(OptimizelyClient.class));
    verify(optimizelyManager.getDatafileHandler()).startBackgroundUpdates(eq(context), eq(new DatafileConfig(testProjectId, null)), eq(3600L), any(DatafileLoadedListener.class));
}
Also used : Context(android.content.Context) DatafileLoadedListener(com.optimizely.ab.android.datafile_handler.DatafileLoadedListener) DefaultUserProfileService(com.optimizely.ab.android.user_profile.DefaultUserProfileService) UserProfileService(com.optimizely.ab.bucketing.UserProfileService) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Test(org.junit.Test)

Example 38 with DatafileConfig

use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.

the class OptimizelyManagerTest method injectOptimizelyWithDatafileListener.

@Test
public void injectOptimizelyWithDatafileListener() {
    Context context = mock(Context.class);
    UserProfileService userProfileService = mock(UserProfileService.class);
    OptimizelyStartListener startListener = mock(OptimizelyStartListener.class);
    optimizelyManager.setOptimizelyStartListener(startListener);
    optimizelyManager.injectOptimizely(context, userProfileService, minDatafile);
    try {
        executor.awaitTermination(5, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        fail("Timed out");
    }
    verify(optimizelyManager.getDatafileHandler()).startBackgroundUpdates(eq(context), eq(new DatafileConfig(testProjectId, null)), eq(3600L), any(DatafileLoadedListener.class));
    verify(logger).info("Sending Optimizely instance to listener");
    verify(startListener).onStart(any(OptimizelyClient.class));
}
Also used : Context(android.content.Context) DatafileLoadedListener(com.optimizely.ab.android.datafile_handler.DatafileLoadedListener) DefaultUserProfileService(com.optimizely.ab.android.user_profile.DefaultUserProfileService) UserProfileService(com.optimizely.ab.bucketing.UserProfileService) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Test(org.junit.Test)

Aggregations

DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)38 Test (org.junit.Test)34 Context (android.content.Context)15 URL (java.net.URL)8 Client (com.optimizely.ab.android.shared.Client)7 Cache (com.optimizely.ab.android.shared.Cache)5 SdkSuppress (androidx.test.filters.SdkSuppress)4 DatafileLoadedListener (com.optimizely.ab.android.datafile_handler.DatafileLoadedListener)4 Intent (android.content.Intent)2 Data (androidx.work.Data)2 DefaultDatafileHandler (com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler)2 DefaultUserProfileService (com.optimizely.ab.android.user_profile.DefaultUserProfileService)2 UserProfileService (com.optimizely.ab.bucketing.UserProfileService)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Logger (org.slf4j.Logger)2 AlarmManager (android.app.AlarmManager)1 IBinder (android.os.IBinder)1 NonNull (androidx.annotation.NonNull)1