Search in sources :

Example 1 with Plugin

use of com.amplifyframework.core.plugin.Plugin in project amplify-android by aws-amplify.

the class TestCategory method forPlugin.

/**
 * Creates a test category to be used for testing. A category containing given
 * plugin will be used to register and configure the plugin. The category
 * instance will have the same Amplify category-type as registered plugin,
 * and it should be cast appropriately before usage.
 *
 * <pre>
 *     AuthCategory auth = (AuthCategory) TestCategory.forPlugin(plugin);
 * </pre>
 *
 * Resulting category object should not be used in production.
 *
 * @param plugin Plugin to register in the category. The resulting category
 *               will share the category type with this plugin.
 * @param <P> Type of plugin being registered.
 * @return An Amplify category object with the given plugin registered and
 *         configured. The category will be of same type as registered plugin
 *         and it should be cast to correct type before usage.
 * @throws AmplifyException if category fails to configure given plugin.
 */
public static <P extends Plugin<?>> Category<?> forPlugin(P plugin) throws AmplifyException {
    CategoryType categoryType = plugin.getCategoryType();
    Category<Plugin<?>> category = (Category<Plugin<?>>) fromCategoryType(categoryType);
    category.addPlugin(plugin);
    CategoryConfiguration config = AmplifyConfiguration.fromConfigFile(context()).forCategoryType(categoryType);
    category.configure(config, context());
    category.initialize(context());
    return category;
}
Also used : Category(com.amplifyframework.core.category.Category) AnalyticsCategory(com.amplifyframework.analytics.AnalyticsCategory) GeoCategory(com.amplifyframework.geo.GeoCategory) StorageCategory(com.amplifyframework.storage.StorageCategory) AuthCategory(com.amplifyframework.auth.AuthCategory) LoggingCategory(com.amplifyframework.logging.LoggingCategory) ApiCategory(com.amplifyframework.api.ApiCategory) HubCategory(com.amplifyframework.hub.HubCategory) PredictionsCategory(com.amplifyframework.predictions.PredictionsCategory) DataStoreCategory(com.amplifyframework.datastore.DataStoreCategory) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration) CategoryType(com.amplifyframework.core.category.CategoryType) Plugin(com.amplifyframework.core.plugin.Plugin)

Aggregations

AnalyticsCategory (com.amplifyframework.analytics.AnalyticsCategory)1 ApiCategory (com.amplifyframework.api.ApiCategory)1 AuthCategory (com.amplifyframework.auth.AuthCategory)1 Category (com.amplifyframework.core.category.Category)1 CategoryConfiguration (com.amplifyframework.core.category.CategoryConfiguration)1 CategoryType (com.amplifyframework.core.category.CategoryType)1 Plugin (com.amplifyframework.core.plugin.Plugin)1 DataStoreCategory (com.amplifyframework.datastore.DataStoreCategory)1 GeoCategory (com.amplifyframework.geo.GeoCategory)1 HubCategory (com.amplifyframework.hub.HubCategory)1 LoggingCategory (com.amplifyframework.logging.LoggingCategory)1 PredictionsCategory (com.amplifyframework.predictions.PredictionsCategory)1 StorageCategory (com.amplifyframework.storage.StorageCategory)1