use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testNoClientDatabasePrefixViaAwsConfiguration.
@Test
public void testNoClientDatabasePrefixViaAwsConfiguration() {
// Uses the configuration under the "MultiAuthAndroidIntegTestApp_NoClientDatabasePrefix" configuration key.
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
awsConfiguration.setConfiguration("MultiAuthAndroidIntegTestApp_NoClientDatabasePrefix");
AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(getTargetContext()).awsConfiguration(awsConfiguration).build();
SyncStore.validate(awsAppSyncClient, null);
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class MultiClientInstrumentationTest method testCodeHasNoClientDatabasePrefixAndUseClientDatabasePrefixFalse.
@Test
public void testCodeHasNoClientDatabasePrefixAndUseClientDatabasePrefixFalse() throws JSONException {
AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(getTargetContext()).apiKey(new BasicAPIKeyAuthProvider(appSyncConfig.getString("ApiKey"))).serverUrl(appSyncConfig.getString("ApiUrl")).region(Regions.fromName(appSyncConfig.getString("Region"))).useClientDatabasePrefix(false).build();
AWSAppSyncClients.validateAppSyncClient(awsAppSyncClient, null, appSyncConfig.getString("AuthMode"));
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class QueryInstrumentationTest method testQueryPostsWithUserPoolsAuthorization.
@Test
public void testQueryPostsWithUserPoolsAuthorization() {
AWSAppSyncClient userPoolsAppSyncClientForPosts = AWSAppSyncClients.withUserPoolsFromAWSConfiguration();
Log.d(TAG, "AWSAppSyncClient for AMAZON_COGNITO_USER_POOLS: " + userPoolsAppSyncClientForPosts);
// Query Posts through API Key Client
Response<AllPostsQuery.Data> allPostsResponse = Posts.list(userPoolsAppSyncClientForPosts, AppSyncResponseFetchers.NETWORK_ONLY).get("NETWORK");
assertNotNull(allPostsResponse);
assertNotNull(allPostsResponse.data());
AllPostsQuery.ListPosts listPosts = allPostsResponse.data().listPosts();
assertNotNull(listPosts);
List<AllPostsQuery.Item> items = listPosts.items();
assertNotNull(items);
// query them individually.
for (AllPostsQuery.Item item : items) {
String postID = item.id();
Map<String, Response<GetPostQuery.Data>> responses = Posts.query(userPoolsAppSyncClientForPosts, AppSyncResponseFetchers.CACHE_AND_NETWORK, postID);
Posts.validate(responses.get("CACHE"), postID, "AMAZON_COGNITO_USER_POOLS");
Posts.validate(responses.get("NETWORK"), postID, "AMAZON_COGNITO_USER_POOLS");
}
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class QueryInstrumentationTest method testCancelMutationWithinCallback.
/**
* TODO: not clear why this (unusual) edge-case is worth testing.
*/
@Test
public void testCancelMutationWithinCallback() {
AWSAppSyncClient awsAppSyncClient = AWSAppSyncClients.withIAMFromAWSConfiguration();
final CountDownLatch add2CountDownLatch = new CountDownLatch(1);
AddPostMutation.Data expected = new AddPostMutation.Data(new AddPostMutation.CreatePost("Post", "", "", "", "", "", null, null, 0));
CreatePostInput createPostInput1 = CreatePostInput.builder().title("L.A. Woman").author("Doors" + System.currentTimeMillis()).url("Doors.com").content("City at night").ups(1).downs(0).build();
AddPostMutation addPostMutation1 = AddPostMutation.builder().input(createPostInput1).build();
final AppSyncMutationCall<AddPostMutation.Data> call1 = awsAppSyncClient.mutate(addPostMutation1, expected);
CreatePostInput createPostInput2 = CreatePostInput.builder().title("Break On Through").author("Doors" + System.currentTimeMillis()).url("Doors.com").content("To the other side").ups(1).downs(0).build();
AddPostMutation addPostMutation2 = AddPostMutation.builder().input(createPostInput2).build();
final AppSyncMutationCall<AddPostMutation.Data> call2 = awsAppSyncClient.mutate(addPostMutation2, expected);
call1.enqueue(new GraphQLCall.Callback<AddPostMutation.Data>() {
@Override
public void onResponse(@NonNull Response<AddPostMutation.Data> response) {
call1.cancel();
}
@Override
public void onFailure(@NonNull ApolloException e) {
fail("OnError received for first mutation. Unexpected exception: " + e.getMessage());
}
});
call2.enqueue(new GraphQLCall.Callback<AddPostMutation.Data>() {
@Override
public void onResponse(@NonNull Response<AddPostMutation.Data> response) {
call2.cancel();
add2CountDownLatch.countDown();
}
@Override
public void onFailure(@NonNull ApolloException e) {
fail("OnError received for Second mutation. Unexpected exception: " + e.getMessage());
add2CountDownLatch.countDown();
}
});
Await.latch(add2CountDownLatch, REASONABLE_WAIT_TIME_MS);
}
use of com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient in project aws-mobile-appsync-sdk-android by awslabs.
the class QueryInstrumentationTest method mutationQueueCanBeCleared.
/**
* When the mutation queue is populated with some mutations, and then
* {@link AWSAppSyncClient#clearMutationQueue()} is called, the mutation
* queue should be emptied without executing the mutations.
*/
@Test
public void mutationQueueCanBeCleared() {
AWSAppSyncClient awsAppSyncClient = AWSAppSyncClients.withIAMFromAWSConfiguration(true, TimeUnit.SECONDS.toMillis(2));
assertTrue(awsAppSyncClient.isMutationQueueEmpty());
// so they'll work.
for (int i = 0; i < 10; i++) {
awsAppSyncClient.mutate(AddPostMutation.builder().input(CreatePostInput.builder().title("Lonely Day").author("SOAD" + System.currentTimeMillis()).url("SOAD.com").content("Such a lonely day").ups(1).downs(0).build()).build(), new AddPostMutation.Data(new AddPostMutation.CreatePost("Post", "", "", "", "", "", null, null, 0))).enqueue(NoOpGraphQLCallback.instance());
}
assertFalse(awsAppSyncClient.isMutationQueueEmpty());
// noinspection deprecation TODO: @deprecated, but SDK does not propose migration path.
awsAppSyncClient.clearMutationQueue();
assertTrue(awsAppSyncClient.isMutationQueueEmpty());
}
Aggregations