use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DefaultDatafileHandlerTest method testBackgroundWithoutEnvironment.
@Test
public void testBackgroundWithoutEnvironment() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
datafileHandler.startBackgroundUpdates(appContext, new DatafileConfig("1", null), 24 * 60 * 60L, null);
assertTrue(true);
datafileHandler.stopBackgroundUpdates(appContext, new DatafileConfig("1", null));
assertTrue(true);
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class BackgroundWatchersCache method getWatchingDatafileConfigs.
/**
* Get a list of all project ids that are being watched for backgrounding.
* @return a list of DatafileConfig
*/
List<DatafileConfig> getWatchingDatafileConfigs() {
List<DatafileConfig> datafileConfigs = new ArrayList<>();
try {
JSONObject backgroundWatchers = load();
if (backgroundWatchers != null) {
Iterator<String> iterator = backgroundWatchers.keys();
while (iterator.hasNext()) {
final String projectKey = iterator.next();
if (backgroundWatchers.getBoolean(projectKey)) {
DatafileConfig datafileConfig = null;
boolean sdkKey = projectKey.matches(".*[A-Za-z].*");
// TODO: This should be changed to store a jsonized datafile config.
if (sdkKey) {
datafileConfig = new DatafileConfig(null, projectKey);
} else {
datafileConfig = new DatafileConfig(projectKey, null);
}
datafileConfigs.add(datafileConfig);
}
}
}
} catch (JSONException e) {
logger.error("Unable to get watching project ids", e);
}
return datafileConfigs;
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class OptimizelyManagerDatafileServiceConnectionTest method onServiceConnected.
@Test
public void onServiceConnected() {
DatafileService.LocalBinder binder = mock(DatafileService.LocalBinder.class);
DatafileService service = mock(DatafileService.class);
Context context = mock(Context.class);
when(service.getApplicationContext()).thenReturn(context);
when(binder.getService()).thenReturn(service);
when(optimizelyManager.getDatafileConfig()).thenReturn(new DatafileConfig("1", (String) null));
when(optimizelyManager.getDatafileLoadedListener(context, null)).thenReturn(mock(DatafileLoadedListener.class));
ArgumentCaptor<DatafileLoadedListener> captor = ArgumentCaptor.forClass(DatafileLoadedListener.class);
datafileServiceConnection = new DatafileServiceConnection(optimizelyManager.getDatafileConfig(), context, optimizelyManager.getDatafileLoadedListener(context, null));
datafileServiceConnection.onServiceConnected(null, binder);
String sameString = optimizelyManager.getDatafileConfig().getUrl();
verify(service).getDatafile(eq(sameString), any(DatafileLoader.class), any(DatafileLoadedListener.class));
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class BackgroundWatchersCacheTest method testExceptionHandling.
@Test
public void testExceptionHandling() throws IOException {
Cache cache = mock(Cache.class);
BackgroundWatchersCache backgroundWatchersCache = new BackgroundWatchersCache(cache, logger);
// Cause a JSONException to be thrown
when(cache.load(BackgroundWatchersCache.BACKGROUND_WATCHERS_FILE_NAME)).thenReturn("{");
assertFalse(backgroundWatchersCache.setIsWatching(new DatafileConfig("1", null), true));
verify(logger).error(contains("Unable to update watching state for project id"), any(JSONException.class));
assertFalse(backgroundWatchersCache.isWatching(new DatafileConfig("1", null)));
verify(logger).error(contains("Unable check if project id is being watched"), any(JSONException.class));
List<DatafileConfig> watchingProjectIds = backgroundWatchersCache.getWatchingDatafileConfigs();
assertTrue(watchingProjectIds.isEmpty());
verify(logger).error(contains("Unable to get watching project ids"), any(JSONException.class));
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DefaultDatafileHandlerUnitTest method testHandler.
@Test
public void testHandler() throws Exception {
handler = new DefaultDatafileHandler();
Context context = mock(Context.class);
when(context.getApplicationContext()).thenReturn(context);
assertFalse(handler.isDatafileSaved(context, new DatafileConfig("1", null)));
}
Aggregations