Search in sources :

Example 6 with PredictionsCategory

use of com.amplifyframework.predictions.PredictionsCategory in project amplify-android by aws-amplify.

the class AWSPredictionsIdentifyTextTest method setUp.

/**
 * Configure Predictions category before each test.
 * @throws Exception if mobile client initialization fails
 */
@Before
public void setUp() throws Exception {
    Context context = getApplicationContext();
    // Set up Auth
    SynchronousMobileClient.instance().initialize();
    // Delegate to Predictions category
    PredictionsCategory asyncDelegate = TestPredictionsCategory.create(context, R.raw.amplifyconfiguration);
    predictions = SynchronousPredictions.delegatingTo(asyncDelegate);
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) PredictionsCategory(com.amplifyframework.predictions.PredictionsCategory) Before(org.junit.Before)

Example 7 with PredictionsCategory

use of com.amplifyframework.predictions.PredictionsCategory in project amplify-android by aws-amplify.

the class AWSPredictionsTranslateTest method setUp.

/**
 * Configure Predictions category before each test.
 * @throws Exception if mobile client initialization fails
 */
@Before
public void setUp() throws Exception {
    Context context = getApplicationContext();
    // Set up Auth
    SynchronousMobileClient.instance().initialize();
    // Delegate to Predictions category
    PredictionsCategory asyncDelegate = TestPredictionsCategory.create(context, R.raw.amplifyconfiguration);
    predictions = SynchronousPredictions.delegatingTo(asyncDelegate);
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) PredictionsCategory(com.amplifyframework.predictions.PredictionsCategory) Before(org.junit.Before)

Example 8 with PredictionsCategory

use of com.amplifyframework.predictions.PredictionsCategory in project amplify-android by aws-amplify.

the class TestPredictionsCategory method create.

/**
 * Creates an instance of {@link PredictionsCategory} using the provided configuration resource.
 * @param context Android Context
 * @param resourceId Android resource ID for a configuration file
 * @return A PredictionsCategory instance using the provided configuration
 */
static PredictionsCategory create(@NonNull Context context, @RawRes int resourceId) {
    Objects.requireNonNull(context);
    final PredictionsCategory predictionsCategory = new PredictionsCategory();
    try {
        predictionsCategory.addPlugin(new AWSPredictionsPlugin(AWSMobileClient.getInstance()));
        CategoryConfiguration predictionsConfiguration = AmplifyConfiguration.fromConfigFile(context, resourceId).forCategoryType(CategoryType.PREDICTIONS);
        predictionsCategory.configure(predictionsConfiguration, context);
        predictionsCategory.initialize(context);
    } catch (AmplifyException initializationFailure) {
        throw new RuntimeException(initializationFailure);
    }
    return predictionsCategory;
}
Also used : AmplifyException(com.amplifyframework.AmplifyException) PredictionsCategory(com.amplifyframework.predictions.PredictionsCategory) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration)

Aggregations

PredictionsCategory (com.amplifyframework.predictions.PredictionsCategory)8 Context (android.content.Context)7 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)7 Before (org.junit.Before)7 AmplifyException (com.amplifyframework.AmplifyException)1 CategoryConfiguration (com.amplifyframework.core.category.CategoryConfiguration)1