Search in sources :

Example 1 with DataStoreCategoryConfiguration

use of com.amplifyframework.datastore.DataStoreCategoryConfiguration in project amplify-android by aws-amplify.

the class AmplifyConfiguration method configsFromJson.

private static Map<String, CategoryConfiguration> configsFromJson(JSONObject json) throws AmplifyException {
    final List<CategoryConfiguration> possibleConfigs = Arrays.asList(new AnalyticsCategoryConfiguration(), new ApiCategoryConfiguration(), new AuthCategoryConfiguration(), new DataStoreCategoryConfiguration(), new GeoCategoryConfiguration(), new HubCategoryConfiguration(), new LoggingCategoryConfiguration(), new PredictionsCategoryConfiguration(), new StorageCategoryConfiguration());
    final Map<String, CategoryConfiguration> actualConfigs = new HashMap<>();
    try {
        for (CategoryConfiguration possibleConfig : possibleConfigs) {
            String categoryJsonKey = possibleConfig.getCategoryType().getConfigurationKey();
            if (json.has(categoryJsonKey)) {
                possibleConfig.populateFromJSON(json.getJSONObject(categoryJsonKey));
                actualConfigs.put(categoryJsonKey, possibleConfig);
            }
        }
    } catch (JSONException error) {
        throw new AmplifyException("Could not parse amplifyconfiguration.json ", error, "Check any modifications made to the file.");
    }
    return Immutable.of(actualConfigs);
}
Also used : DataStoreCategoryConfiguration(com.amplifyframework.datastore.DataStoreCategoryConfiguration) StorageCategoryConfiguration(com.amplifyframework.storage.StorageCategoryConfiguration) AmplifyException(com.amplifyframework.AmplifyException) PredictionsCategoryConfiguration(com.amplifyframework.predictions.PredictionsCategoryConfiguration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AuthCategoryConfiguration(com.amplifyframework.auth.AuthCategoryConfiguration) LoggingCategoryConfiguration(com.amplifyframework.logging.LoggingCategoryConfiguration) AnalyticsCategoryConfiguration(com.amplifyframework.analytics.AnalyticsCategoryConfiguration) AuthCategoryConfiguration(com.amplifyframework.auth.AuthCategoryConfiguration) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration) GeoCategoryConfiguration(com.amplifyframework.geo.GeoCategoryConfiguration) DataStoreCategoryConfiguration(com.amplifyframework.datastore.DataStoreCategoryConfiguration) HubCategoryConfiguration(com.amplifyframework.hub.HubCategoryConfiguration) PredictionsCategoryConfiguration(com.amplifyframework.predictions.PredictionsCategoryConfiguration) StorageCategoryConfiguration(com.amplifyframework.storage.StorageCategoryConfiguration) ApiCategoryConfiguration(com.amplifyframework.api.ApiCategoryConfiguration) EmptyCategoryConfiguration(com.amplifyframework.core.category.EmptyCategoryConfiguration) JSONException(org.json.JSONException) GeoCategoryConfiguration(com.amplifyframework.geo.GeoCategoryConfiguration) AnalyticsCategoryConfiguration(com.amplifyframework.analytics.AnalyticsCategoryConfiguration) ApiCategoryConfiguration(com.amplifyframework.api.ApiCategoryConfiguration) HubCategoryConfiguration(com.amplifyframework.hub.HubCategoryConfiguration) LoggingCategoryConfiguration(com.amplifyframework.logging.LoggingCategoryConfiguration)

Example 2 with DataStoreCategoryConfiguration

use of com.amplifyframework.datastore.DataStoreCategoryConfiguration in project amplify-android by aws-amplify.

the class RxAmplifyTest method canAddPluginsAndConfigure.

/**
 * Calling {@link RxAmplify#addPlugin(Plugin)} and {@link RxAmplify#configure(AmplifyConfiguration, Context)}
 * will pass config JSON down into the plugin via its {@link Plugin#configure(JSONObject, Context)}
 * method.
 * @throws AmplifyException Not exected; possible from RxAmplilfy's addPlugin(), configure().
 * @throws JSONException Not expected; on failure to arrange test JSON inputs.
 */
@SuppressWarnings("unchecked")
@Test
public void canAddPluginsAndConfigure() throws AmplifyException, JSONException {
    // Setup a mock plugin, add it to Amplify.
    CategoryType categoryType = CategoryType.STORAGE;
    String pluginKey = RandomString.string();
    Plugin<Void> one = mock(Plugin.class);
    when(one.getPluginKey()).thenReturn(pluginKey);
    when(one.getCategoryType()).thenReturn(categoryType);
    RxAmplify.addPlugin(one);
    // Configure Amplify, with a config to match the plugin above.
    Map<String, CategoryConfiguration> categoryConfigs = new HashMap<>();
    String categoryName = categoryType.getConfigurationKey();
    CategoryConfiguration categoryConfig = new DataStoreCategoryConfiguration();
    JSONObject pluginJson = new JSONObject().put("someKey", "someVal");
    categoryConfig.populateFromJSON(new JSONObject().put("plugins", new JSONObject().put(pluginKey, pluginJson)));
    categoryConfigs.put(categoryName, categoryConfig);
    AmplifyConfiguration config = new AmplifyConfiguration(categoryConfigs);
    Context mockContext = mock(Context.class);
    when(mockContext.getApplicationContext()).thenReturn(mockContext);
    when(mockContext.getApplicationInfo()).thenReturn(new ApplicationInfo());
    RxAmplify.configure(config, mockContext);
    // Validate that the plugin gets configured with the provided JSON
    ArgumentCaptor<JSONObject> configJsonCapture = ArgumentCaptor.forClass(JSONObject.class);
    verify(one).configure(configJsonCapture.capture(), any(Context.class));
    assertEquals(pluginJson, configJsonCapture.getValue());
}
Also used : DataStoreCategoryConfiguration(com.amplifyframework.datastore.DataStoreCategoryConfiguration) Context(android.content.Context) AmplifyConfiguration(com.amplifyframework.core.AmplifyConfiguration) HashMap(java.util.HashMap) DataStoreCategoryConfiguration(com.amplifyframework.datastore.DataStoreCategoryConfiguration) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration) ApplicationInfo(android.content.pm.ApplicationInfo) CategoryType(com.amplifyframework.core.category.CategoryType) RandomString(com.amplifyframework.testutils.random.RandomString) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Example 3 with DataStoreCategoryConfiguration

use of com.amplifyframework.datastore.DataStoreCategoryConfiguration in project amplify-android by aws-amplify.

the class RxDataStoreBindingTest method createBindingInFrontOfMockPlugin.

/**
 * Creates a DataStoreCategory that has a mock plugin backing it.
 * Creates an Rx Binding around this category, for test.
 * @throws AmplifyException On failure to add plugin, init/config the category
 */
@Before
public void createBindingInFrontOfMockPlugin() throws AmplifyException {
    this.delegate = mock(DataStorePlugin.class);
    when(delegate.getPluginKey()).thenReturn(RandomString.string());
    final DataStoreCategory dataStoreCategory = new DataStoreCategory();
    dataStoreCategory.addPlugin(delegate);
    dataStoreCategory.configure(new DataStoreCategoryConfiguration(), mock(Context.class));
    dataStoreCategory.initialize(mock(Context.class));
    this.rxDataStore = new RxDataStoreBinding(dataStoreCategory);
}
Also used : DataStoreCategoryConfiguration(com.amplifyframework.datastore.DataStoreCategoryConfiguration) Context(android.content.Context) DataStorePlugin(com.amplifyframework.datastore.DataStorePlugin) DataStoreCategory(com.amplifyframework.datastore.DataStoreCategory) Before(org.junit.Before)

Aggregations

DataStoreCategoryConfiguration (com.amplifyframework.datastore.DataStoreCategoryConfiguration)3 Context (android.content.Context)2 CategoryConfiguration (com.amplifyframework.core.category.CategoryConfiguration)2 HashMap (java.util.HashMap)2 ApplicationInfo (android.content.pm.ApplicationInfo)1 AmplifyException (com.amplifyframework.AmplifyException)1 AnalyticsCategoryConfiguration (com.amplifyframework.analytics.AnalyticsCategoryConfiguration)1 ApiCategoryConfiguration (com.amplifyframework.api.ApiCategoryConfiguration)1 AuthCategoryConfiguration (com.amplifyframework.auth.AuthCategoryConfiguration)1 AmplifyConfiguration (com.amplifyframework.core.AmplifyConfiguration)1 CategoryType (com.amplifyframework.core.category.CategoryType)1 EmptyCategoryConfiguration (com.amplifyframework.core.category.EmptyCategoryConfiguration)1 DataStoreCategory (com.amplifyframework.datastore.DataStoreCategory)1 DataStorePlugin (com.amplifyframework.datastore.DataStorePlugin)1 GeoCategoryConfiguration (com.amplifyframework.geo.GeoCategoryConfiguration)1 HubCategoryConfiguration (com.amplifyframework.hub.HubCategoryConfiguration)1 LoggingCategoryConfiguration (com.amplifyframework.logging.LoggingCategoryConfiguration)1 PredictionsCategoryConfiguration (com.amplifyframework.predictions.PredictionsCategoryConfiguration)1 StorageCategoryConfiguration (com.amplifyframework.storage.StorageCategoryConfiguration)1 RandomString (com.amplifyframework.testutils.random.RandomString)1