use of com.amplifyframework.api.ApiCategory in project amplify-android by aws-amplify.
the class ConflictResolverIntegrationTest method mockApiCategoryWithGraphQlApi.
@SuppressWarnings("unchecked")
private ApiCategory mockApiCategoryWithGraphQlApi() throws AmplifyException {
ApiCategory mockApiCategory = spy(ApiCategory.class);
ApiPlugin<?> mockApiPlugin = mock(ApiPlugin.class);
when(mockApiPlugin.getPluginKey()).thenReturn(MOCK_API_PLUGIN_NAME);
when(mockApiPlugin.getCategoryType()).thenReturn(CategoryType.API);
ApiEndpointStatusChangeEvent eventData = new ApiEndpointStatusChangeEvent(ApiEndpointStatusChangeEvent.ApiEndpointStatus.REACHABLE, ApiEndpointStatusChangeEvent.ApiEndpointStatus.UNKOWN);
HubEvent<ApiEndpointStatusChangeEvent> hubEvent = HubEvent.create(ApiChannelEventName.API_ENDPOINT_STATUS_CHANGED, eventData);
// Make believe that queries return response immediately
doAnswer(invocation -> {
// Mock the API emitting an ApiEndpointStatusChangeEvent event.
Amplify.Hub.publish(HubChannel.API, hubEvent);
int indexOfResponseConsumer = 1;
Consumer<GraphQLResponse<PaginatedResult<ModelWithMetadata<Person>>>> onResponse = invocation.getArgument(indexOfResponseConsumer);
PaginatedResult<ModelWithMetadata<Person>> data = new PaginatedResult<>(Collections.emptyList(), null);
onResponse.accept(new GraphQLResponse<>(data, Collections.emptyList()));
return null;
}).when(mockApiPlugin).query(any(GraphQLRequest.class), any(Consumer.class), any(Consumer.class));
mockApiCategory.addPlugin(mockApiPlugin);
mockApiCategory.configure(new ApiCategoryConfiguration(), getApplicationContext());
mockApiCategory.initialize(getApplicationContext());
return mockApiCategory;
}
use of com.amplifyframework.api.ApiCategory 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);
}
use of com.amplifyframework.api.ApiCategory 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);
}
use of com.amplifyframework.api.ApiCategory in project amplify-android by aws-amplify.
the class CodeGenerationInstrumentationTest 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 {
ApiCategory asyncDelegate = TestApiCategory.fromConfiguration(R.raw.amplifyconfiguration);
api = SynchronousApi.delegatingTo(asyncDelegate);
}
use of com.amplifyframework.api.ApiCategory in project amplify-android by aws-amplify.
the class RestApiInstrumentationTest method setUp.
/**
* Configure the Amplify framework and auth.
* @throws AmplifyException if configuration fails
* @throws SynchronousMobileClient.MobileClientException If AWS Mobile Client initialization fails
*/
@Before
public void setUp() throws AmplifyException, SynchronousMobileClient.MobileClientException {
ApiCategory asyncDelegate = TestApiCategory.fromConfiguration(R.raw.amplifyconfiguration);
api = SynchronousApi.delegatingTo(asyncDelegate);
SynchronousMobileClient mobileClient = SynchronousMobileClient.instance();
mobileClient.initialize();
}
Aggregations