use of com.amplifyframework.core.category.CategoryConfiguration 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;
}
use of com.amplifyframework.core.category.CategoryConfiguration in project amplify-android by aws-amplify.
the class TestApiCategory method fromConfiguration.
/**
* Creates an instance of {@link ApiCategory}, using the provided configuration
* file, referred to by its android resource ID.
* @return A configured and initialized ApiCategory instance
*/
@NonNull
static ApiCategory fromConfiguration(@RawRes int resourceId) throws AmplifyException {
CognitoUserPoolsAuthProvider cognitoUserPoolsAuthProvider = new DefaultCognitoUserPoolsAuthProvider(AWSMobileClient.getInstance());
ApiAuthProviders providers = ApiAuthProviders.builder().awsCredentialsProvider(AWSMobileClient.getInstance()).cognitoUserPoolsAuthProvider(cognitoUserPoolsAuthProvider).build();
AWSApiPlugin plugin = AWSApiPlugin.builder().apiAuthProviders(providers).build();
ApiCategory apiCategory = new ApiCategory();
apiCategory.addPlugin(plugin);
CategoryConfiguration apiConfiguration = AmplifyConfiguration.fromConfigFile(getApplicationContext(), resourceId).forCategoryType(CategoryType.API);
apiCategory.configure(apiConfiguration, getApplicationContext());
// apiCategory.initialize(...); Doesn't currently contain any logic, so, skip it.
return apiCategory;
}
Aggregations