use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DatafileWorkerTest method mockDatafileWorker.
// Helpers
DatafileWorker mockDatafileWorker(String sdkKey) {
DatafileConfig datafileConfig = new DatafileConfig(null, sdkKey);
Data inputData = DatafileWorker.getData(datafileConfig);
return (DatafileWorker) TestWorkerBuilder.from(context, DatafileWorker.class, executor).setInputData(inputData).build();
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DatafileWorkerTest method testInputData.
@Test
public void testInputData() {
DatafileConfig datafileConfig1 = new DatafileConfig(null, sdkKey);
Data data = DatafileWorker.getData(datafileConfig1);
DatafileConfig datafileConfig2 = DatafileWorker.getDataConfig(data);
assertEquals(datafileConfig2.getKey(), sdkKey);
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DefaultDatafileHandlerTest method testSaveExistsRemoveWithEnvironments.
@Test
public void testSaveExistsRemoveWithEnvironments() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
DatafileConfig projectId = new DatafileConfig("1", "2");
datafileHandler.saveDatafile(appContext, projectId, "{}");
assertTrue(datafileHandler.isDatafileSaved(appContext, projectId));
assertNotNull(datafileHandler.loadSavedDatafile(appContext, projectId));
datafileHandler.removeSavedDatafile(appContext, projectId);
assertFalse(datafileHandler.isDatafileSaved(appContext, projectId));
assertEquals("com.optimizely.ab.android.datafile_handler.test", appContext.getPackageName());
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DefaultDatafileHandlerTest method testBackgroundWithEnvironment.
@Test
public void testBackgroundWithEnvironment() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
datafileHandler.startBackgroundUpdates(appContext, new DatafileConfig("1", "2"), 24 * 60 * 60L, null);
assertTrue(true);
datafileHandler.stopBackgroundUpdates(appContext, new DatafileConfig("1", "2"));
assertTrue(true);
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DatafileService method onStartCommand.
/**
* @hide
* @see Service#onStartCommand(Intent, int, int)
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
if (intent.hasExtra(EXTRA_DATAFILE_CONFIG)) {
String extraDatafileConfig = intent.getStringExtra(EXTRA_DATAFILE_CONFIG);
DatafileConfig datafileConfig = DatafileConfig.fromJSONString(extraDatafileConfig);
DatafileClient datafileClient = new DatafileClient(new Client(new OptlyStorage(this.getApplicationContext()), LoggerFactory.getLogger(OptlyStorage.class)), LoggerFactory.getLogger(DatafileClient.class));
DatafileCache datafileCache = new DatafileCache(datafileConfig.getKey(), new Cache(this.getApplicationContext(), LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(DatafileCache.class));
String datafileUrl = datafileConfig.getUrl();
DatafileLoader datafileLoader = new DatafileLoader(this, datafileClient, datafileCache, LoggerFactory.getLogger(DatafileLoader.class));
datafileLoader.getDatafile(datafileUrl, null);
} else {
logger.warn("Data file service received an intent with no project id extra");
}
} else {
logger.warn("Data file service received a null intent");
}
return super.onStartCommand(intent, flags, startId);
}
Aggregations