Search in sources :

Example 11 with DatafileConfig

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();
}
Also used : Data(androidx.work.Data) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig)

Example 12 with DatafileConfig

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);
}
Also used : Data(androidx.work.Data) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Test(org.junit.Test)

Example 13 with DatafileConfig

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

Example 14 with DatafileConfig

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

Example 15 with DatafileConfig

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);
}
Also used : OptlyStorage(com.optimizely.ab.android.shared.OptlyStorage) DatafileConfig(com.optimizely.ab.android.shared.DatafileConfig) Client(com.optimizely.ab.android.shared.Client) Cache(com.optimizely.ab.android.shared.Cache)

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