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);
}
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());
}
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);
}
Aggregations