Search in sources :

Example 1 with AWSApiPlugin

use of com.amplifyframework.api.aws.AWSApiPlugin in project amplify-android by aws-amplify.

the class HybridAssociationSyncInstrumentationTest method setup.

/**
 * DataStore is configured with a real AppSync endpoint. API and AppSync clients
 * are used to arrange/validate state before/after exercising the DataStore. The {@link Amplify}
 * facade is intentionally *not* used, since we don't want to pollute the instrumentation
 * test process with global state. We need an *instance* of the DataStore.
 * @throws AmplifyException On failure to configure Amplify, API/DataStore categories.
 */
@Ignore("It passes. Not automating due to operational concerns as noted in class-level @Ignore.")
@Before
public void setup() throws AmplifyException {
    Amplify.addPlugin(new AndroidLoggingPlugin(LogLevel.VERBOSE));
    StrictMode.enable();
    Context context = getApplicationContext();
    @RawRes int configResourceId = Resources.getRawResourceId(context, "amplifyconfiguration");
    // Setup an API
    CategoryConfiguration apiCategoryConfiguration = AmplifyConfiguration.fromConfigFile(context, configResourceId).forCategoryType(CategoryType.API);
    ApiCategory apiCategory = new ApiCategory();
    apiCategory.addPlugin(new AWSApiPlugin());
    apiCategory.configure(apiCategoryConfiguration, context);
    // To arrange and verify state, we need to access the supporting AppSync API
    api = SynchronousApi.delegatingTo(apiCategory);
    appSync = SynchronousAppSync.using(AppSyncClient.via(apiCategory));
    schemaProvider = SchemaLoader.loadFromAssetsDirectory("schemas/commentsblog");
    DataStoreCategory dataStoreCategory = DataStoreCategoryConfigurator.begin().api(apiCategory).clearDatabase(true).context(context).modelProvider(schemaProvider).resourceId(configResourceId).timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS).finish();
    AWSDataStorePlugin plugin = (AWSDataStorePlugin) dataStoreCategory.getPlugin("awsDataStorePlugin");
    normalBehaviors = SynchronousDataStore.delegatingTo(dataStoreCategory);
    hybridBehaviors = SynchronousHybridBehaviors.delegatingTo(plugin);
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) AWSApiPlugin(com.amplifyframework.api.aws.AWSApiPlugin) RawRes(androidx.annotation.RawRes) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration) ApiCategory(com.amplifyframework.api.ApiCategory) AndroidLoggingPlugin(com.amplifyframework.logging.AndroidLoggingPlugin) Before(org.junit.Before) Ignore(org.junit.Ignore)

Example 2 with AWSApiPlugin

use of com.amplifyframework.api.aws.AWSApiPlugin in project amplify-android by aws-amplify.

the class HybridTemporalSyncInstrumentationTest method setup.

/**
 * DataStore is configured with a real AppSync endpoint. API and AppSync clients
 * are used to arrange/validate state before/after exercising the DataStore. The {@link Amplify}
 * facade is intentionally *not* used, since we don't want to pollute the instrumentation
 * test process with global state. We need an *instance* of the DataStore.
 * @throws AmplifyException On failure to configure Amplify, API/DataStore categories.
 */
@Ignore("It passes. Not automating due to operational concerns as noted in class-level @Ignore.")
@Before
public void setup() throws AmplifyException {
    Amplify.addPlugin(new AndroidLoggingPlugin(LogLevel.VERBOSE));
    StrictMode.enable();
    Context context = getApplicationContext();
    @RawRes int configResourceId = Resources.getRawResourceId(context, "amplifyconfiguration");
    // Setup an API
    CategoryConfiguration apiCategoryConfiguration = AmplifyConfiguration.fromConfigFile(context, configResourceId).forCategoryType(CategoryType.API);
    ApiCategory apiCategory = new ApiCategory();
    apiCategory.addPlugin(new AWSApiPlugin());
    apiCategory.configure(apiCategoryConfiguration, context);
    // To arrange and verify state, we need to access the supporting AppSync API
    api = SynchronousApi.delegatingTo(apiCategory);
    appSync = SynchronousAppSync.using(AppSyncClient.via(apiCategory));
    SchemaProvider schemaProvider = SchemaLoader.loadFromAssetsDirectory("schemas/meeting");
    DataStoreCategory dataStoreCategory = DataStoreCategoryConfigurator.begin().api(apiCategory).clearDatabase(true).context(context).modelProvider(schemaProvider).resourceId(configResourceId).timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS).finish();
    AWSDataStorePlugin plugin = (AWSDataStorePlugin) dataStoreCategory.getPlugin("awsDataStorePlugin");
    hybridBehaviors = SynchronousHybridBehaviors.delegatingTo(plugin);
    // Get a handle to the Meeting model schema that we loaded into the DataStore in @Before.
    String modelName = Meeting.class.getSimpleName();
    modelSchema = schemaProvider.modelSchemas().get(modelName);
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) AWSApiPlugin(com.amplifyframework.api.aws.AWSApiPlugin) RawRes(androidx.annotation.RawRes) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration) ApiCategory(com.amplifyframework.api.ApiCategory) AndroidLoggingPlugin(com.amplifyframework.logging.AndroidLoggingPlugin) Before(org.junit.Before) Ignore(org.junit.Ignore)

Example 3 with AWSApiPlugin

use of com.amplifyframework.api.aws.AWSApiPlugin in project amplify-android by aws-amplify.

the class AppSyncClientInstrumentationTest method onceBeforeTests.

/**
 * Configure Amplify for API tests, if it has not been configured, yet.
 * @throws AmplifyException From Amplify configuration
 */
@BeforeClass
public static void onceBeforeTests() throws AmplifyException {
    Context context = getApplicationContext();
    @RawRes int resourceId = Resources.getRawResourceId(context, "amplifyconfiguration");
    ApiCategory asyncDelegate = new ApiCategory();
    asyncDelegate.addPlugin(new AWSApiPlugin());
    asyncDelegate.configure(AmplifyConfiguration.fromConfigFile(context, resourceId).forCategoryType(CategoryType.API), context);
    asyncDelegate.initialize(context);
    api = AppSyncClient.via(asyncDelegate);
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) AWSApiPlugin(com.amplifyframework.api.aws.AWSApiPlugin) RawRes(androidx.annotation.RawRes) ApiCategory(com.amplifyframework.api.ApiCategory) BeforeClass(org.junit.BeforeClass)

Example 4 with AWSApiPlugin

use of com.amplifyframework.api.aws.AWSApiPlugin in project amplify-android by aws-amplify.

the class BasicCloudSyncInstrumentationTest method setup.

/**
 * Once, before any/all tests in this class, setup miscellaneous dependencies,
 * including synchronous API, AppSync, and DataStore interfaces. The API and AppSync instances
 * are used to arrange/validate data. The DataStore interface will delegate to an
 * {@link AWSDataStorePlugin}, which is the thing we're actually testing.
 * @throws AmplifyException On failure to read config, setup API or DataStore categories
 */
@BeforeClass
public static void setup() throws AmplifyException {
    Amplify.addPlugin(new AndroidLoggingPlugin(LogLevel.VERBOSE));
    StrictMode.enable();
    Context context = getApplicationContext();
    @RawRes int configResourceId = Resources.getRawResourceId(context, "amplifyconfiguration");
    // Setup an API
    CategoryConfiguration apiCategoryConfiguration = AmplifyConfiguration.fromConfigFile(context, configResourceId).forCategoryType(CategoryType.API);
    ApiCategory apiCategory = new ApiCategory();
    apiCategory.addPlugin(new AWSApiPlugin());
    apiCategory.configure(apiCategoryConfiguration, context);
    // To arrange and verify state, we need to access the supporting AppSync API
    api = SynchronousApi.delegatingTo(apiCategory);
    appSync = SynchronousAppSync.using(AppSyncClient.via(apiCategory));
    long tenMinutesAgo = new Date().getTime() - TimeUnit.MINUTES.toMillis(10);
    Temporal.DateTime tenMinutesAgoDateTime = new Temporal.DateTime(new Date(tenMinutesAgo), 0);
    DataStoreCategory dataStoreCategory = DataStoreCategoryConfigurator.begin().api(apiCategory).clearDatabase(true).context(context).modelProvider(AmplifyModelProvider.getInstance()).resourceId(configResourceId).timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS).dataStoreConfiguration(DataStoreConfiguration.builder().syncExpression(BlogOwner.class, () -> BlogOwner.CREATED_AT.gt(tenMinutesAgoDateTime)).syncExpression(Blog.class, () -> Blog.CREATED_AT.gt(tenMinutesAgoDateTime)).syncExpression(Post.class, () -> Post.CREATED_AT.gt(tenMinutesAgoDateTime)).syncExpression(Comment.class, () -> Comment.CREATED_AT.gt(tenMinutesAgoDateTime)).syncExpression(Author.class, () -> Author.CREATED_AT.gt(tenMinutesAgoDateTime)).syncExpression(PostAuthorJoin.class, () -> PostAuthorJoin.CREATED_AT.gt(tenMinutesAgoDateTime)).build()).finish();
    dataStore = SynchronousDataStore.delegatingTo(dataStoreCategory);
}
Also used : ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) Context(android.content.Context) Comment(com.amplifyframework.testmodels.commentsblog.Comment) RawRes(androidx.annotation.RawRes) CategoryConfiguration(com.amplifyframework.core.category.CategoryConfiguration) PostAuthorJoin(com.amplifyframework.testmodels.commentsblog.PostAuthorJoin) AndroidLoggingPlugin(com.amplifyframework.logging.AndroidLoggingPlugin) Date(java.util.Date) AWSApiPlugin(com.amplifyframework.api.aws.AWSApiPlugin) Temporal(com.amplifyframework.core.model.temporal.Temporal) ApiCategory(com.amplifyframework.api.ApiCategory) Blog(com.amplifyframework.testmodels.commentsblog.Blog) BeforeClass(org.junit.BeforeClass)

Aggregations

Context (android.content.Context)4 RawRes (androidx.annotation.RawRes)4 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)4 ApiCategory (com.amplifyframework.api.ApiCategory)4 AWSApiPlugin (com.amplifyframework.api.aws.AWSApiPlugin)4 CategoryConfiguration (com.amplifyframework.core.category.CategoryConfiguration)3 AndroidLoggingPlugin (com.amplifyframework.logging.AndroidLoggingPlugin)3 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)2 Ignore (org.junit.Ignore)2 Temporal (com.amplifyframework.core.model.temporal.Temporal)1 Blog (com.amplifyframework.testmodels.commentsblog.Blog)1 Comment (com.amplifyframework.testmodels.commentsblog.Comment)1 PostAuthorJoin (com.amplifyframework.testmodels.commentsblog.PostAuthorJoin)1 Date (java.util.Date)1