Search in sources :

Example 21 with AWSAppSyncClient

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);
}
Also used : AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) Test(org.junit.Test)

Example 22 with AWSAppSyncClient

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"));
}
Also used : AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BasicAPIKeyAuthProvider(com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider) Test(org.junit.Test)

Example 23 with AWSAppSyncClient

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");
    }
}
Also used : Response(com.apollographql.apollo.api.Response) AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) AllPostsQuery(com.amazonaws.mobileconnectors.appsync.demo.AllPostsQuery) GetPostQuery(com.amazonaws.mobileconnectors.appsync.demo.GetPostQuery) Test(org.junit.Test)

Example 24 with AWSAppSyncClient

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);
}
Also used : GraphQLCall(com.apollographql.apollo.GraphQLCall) CreatePostInput(com.amazonaws.mobileconnectors.appsync.demo.type.CreatePostInput) CountDownLatch(java.util.concurrent.CountDownLatch) AddPostMutation(com.amazonaws.mobileconnectors.appsync.demo.AddPostMutation) AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) ApolloException(com.apollographql.apollo.exception.ApolloException) Test(org.junit.Test)

Example 25 with AWSAppSyncClient

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());
}
Also used : AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) AddPostMutation(com.amazonaws.mobileconnectors.appsync.demo.AddPostMutation) Test(org.junit.Test)

Aggregations

AWSAppSyncClient (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient)28 Test (org.junit.Test)19 AddPostMutation (com.amazonaws.mobileconnectors.appsync.demo.AddPostMutation)8 AWSConfiguration (com.amazonaws.mobile.config.AWSConfiguration)6 AllPostsQuery (com.amazonaws.mobileconnectors.appsync.demo.AllPostsQuery)6 Response (com.apollographql.apollo.api.Response)5 GetPostQuery (com.amazonaws.mobileconnectors.appsync.demo.GetPostQuery)4 ResponseFetcher (com.apollographql.apollo.fetcher.ResponseFetcher)4 HashMap (java.util.HashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 JSONObject (org.json.JSONObject)4 DelegatingGraphQLCallback (com.amazonaws.mobileconnectors.appsync.client.DelegatingGraphQLCallback)3 LatchedGraphQLCallback (com.amazonaws.mobileconnectors.appsync.client.LatchedGraphQLCallback)3 UpdatePostMutation (com.amazonaws.mobileconnectors.appsync.demo.UpdatePostMutation)3 CreatePostInput (com.amazonaws.mobileconnectors.appsync.demo.type.CreatePostInput)3 AppSyncResponseFetchers (com.amazonaws.mobileconnectors.appsync.fetcher.AppSyncResponseFetchers)3 BasicAPIKeyAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider)3 Await (com.amazonaws.mobileconnectors.appsync.util.Await)3 Cancelable (com.apollographql.apollo.internal.util.Cancelable)3 Map (java.util.Map)3