use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class AWSApiPluginTest method headerInterceptorsAreConfigured.
/**
* Validates that the plugin adds custom headers into the outgoing OkHttp request.
* @throws ApiException Thrown from the query() call.
* @throws InterruptedException Possible thrown from takeRequest()
*/
@Test
public void headerInterceptorsAreConfigured() throws ApiException, InterruptedException {
// Arrange some response. This isn't the point of the test,
// but it keeps the mock web server from freezing up.
webServer.enqueue(new MockResponse().setBody(Resources.readAsString("blog-owners-query-results.json")));
// Fire off a request
Await.<GraphQLResponse<PaginatedResult<BlogOwner>>, ApiException>result((onResult, onError) -> plugin.query(ModelQuery.list(BlogOwner.class), onResult, onError));
RecordedRequest recordedRequest = webServer.takeRequest(5, TimeUnit.MILLISECONDS);
assertNotNull(recordedRequest);
assertEquals("specialValue", recordedRequest.getHeader("specialKey"));
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class AWSApiPluginTest method requestUsesIamForAuth.
/**
* Ensure the auth mode used for the request is AWS_IAM. We verify this by
* @throws AmplifyException Not expected.
* @throws InterruptedException Not expected.
*/
@Test
public void requestUsesIamForAuth() throws AmplifyException, InterruptedException {
webServer.enqueue(new MockResponse().setBody(Resources.readAsString("blog-owners-query-results.json")));
AppSyncGraphQLRequest<PaginatedResult<BlogOwner>> appSyncGraphQLRequest = createQueryRequestWithAuthMode(BlogOwner.class, AuthorizationType.AWS_IAM);
GraphQLResponse<PaginatedResult<BlogOwner>> actualResponse = Await.<GraphQLResponse<PaginatedResult<BlogOwner>>, ApiException>result((onResult, onError) -> plugin.query(appSyncGraphQLRequest, onResult, onError));
RecordedRequest recordedRequest = webServer.takeRequest();
assertNull(recordedRequest.getHeader("x-api-key"));
assertNotNull(recordedRequest.getHeader("authorization"));
assertTrue(recordedRequest.getHeader("authorization").startsWith("AWS4-HMAC-SHA256"));
assertEquals(Arrays.asList("Curly", "Moe", "Larry"), Observable.fromIterable(actualResponse.getData()).map(BlogOwner::getName).toList().blockingGet());
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class AWSApiPluginTest method requestUsesCognitoForAuth.
/**
* If the auth mode is set for the individual request, ensure that the resulting request
* to AppSync has the correct auth header.
* @throws AmplifyException Not expected.
* @throws InterruptedException Not expected.
*/
@Test
public void requestUsesCognitoForAuth() throws AmplifyException, InterruptedException {
webServer.enqueue(new MockResponse().setBody(Resources.readAsString("blog-owners-query-results.json")));
AppSyncGraphQLRequest<PaginatedResult<BlogOwner>> appSyncGraphQLRequest = createQueryRequestWithAuthMode(BlogOwner.class, AuthorizationType.AMAZON_COGNITO_USER_POOLS);
GraphQLResponse<PaginatedResult<BlogOwner>> actualResponse = Await.<GraphQLResponse<PaginatedResult<BlogOwner>>, ApiException>result((onResult, onError) -> plugin.query(appSyncGraphQLRequest, onResult, onError));
RecordedRequest recordedRequest = webServer.takeRequest();
assertNull(recordedRequest.getHeader("x-api-key"));
assertNotNull(recordedRequest.getHeader("authorization"));
assertEquals("FAKE_TOKEN", recordedRequest.getHeader("authorization"));
assertEquals(Arrays.asList("Curly", "Moe", "Larry"), Observable.fromIterable(actualResponse.getData()).map(BlogOwner::getName).toList().blockingGet());
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class AWSApiPluginTest method graphQlMutationGetsResponse.
/**
* It should be possible to perform a successful call to
* {@link AWSApiPlugin#mutate(GraphQLRequest, Consumer, Consumer)}.
* When the server returns a valid response, then the mutate methods should
* emit content via their value consumer.
* @throws ApiException If call to mutate(...) itself emits such an exception
* @throws JSONException On failure to arrange response JSON
*/
@Test
public void graphQlMutationGetsResponse() throws JSONException, ApiException {
HubAccumulator networkStatusObserver = HubAccumulator.create(HubChannel.API, ApiChannelEventName.API_ENDPOINT_STATUS_CHANGED, 1).start();
// Arrange a response from the "server"
String expectedName = RandomString.string();
webServer.enqueue(new MockResponse().setBody(new JSONObject().put("data", new JSONObject().put("createBlogOwner", new JSONObject().put("name", expectedName))).toString()));
// Try to perform a mutation.
BlogOwner tony = BlogOwner.builder().name(expectedName).build();
GraphQLResponse<BlogOwner> actualResponse = Await.<GraphQLResponse<BlogOwner>, ApiException>result(((onResult, onError) -> plugin.mutate(ModelMutation.create(tony), onResult, onError)));
// Assert that the expected response was received
assertEquals(expectedName, actualResponse.getData().getName());
// Verify that the expected hub event fired.
HubEvent<?> event = networkStatusObserver.awaitFirst();
assertNotNull(event);
assertTrue(event.getData() instanceof ApiEndpointStatusChangeEvent);
ApiEndpointStatusChangeEvent eventData = (ApiEndpointStatusChangeEvent) event.getData();
assertEquals(ApiEndpointStatusChangeEvent.ApiEndpointStatus.REACHABLE, eventData.getCurrentStatus());
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterClearTest method clearDeletesAndRecreatesDatabase.
/**
* Save a record to the database and verify it was saved.
* Then call clear and verify that the database file is re-created
* and is writable.
* @throws DataStoreException bubbles up exceptions thrown from the adapter
* @throws InterruptedException If interrupted while test observer awaits terminal result
*/
@Test
public void clearDeletesAndRecreatesDatabase() throws DataStoreException, InterruptedException {
assertDbFileExists();
assertEquals(0, fileObserver.createFileEventCount);
assertEquals(0, fileObserver.deleteFileEventCount);
BlogOwner blogger1 = createBlogger("Dummy Blogger Sr.");
BlogOwner blogger2 = createBlogger("Dummy Blogger Jr.");
// Save a record and check if it's there
adapter.save(blogger1);
assertRecordIsInDb(blogger1);
// Verify observer is still alive
assertFalse(observer.isDisposed());
assertObserverReceivedRecord(blogger1);
adapter.clear();
// Make sure file was deleted and re-created
assertEquals(1, fileObserver.createFileEventCount);
assertEquals(1, fileObserver.deleteFileEventCount);
assertDbFileExists();
// Verify observer is still alive
assertFalse(observer.isDisposed());
// Make sure the new file is writable
adapter.save(blogger2);
// Check the new record is in the database
// and the old record is not.
assertRecordIsInDb(blogger2);
assertRecordIsNotInDb(blogger1);
assertObserverReceivedRecord(blogger2);
// Terminate the adapter
adapter.terminate();
// Verify observer was disposed.
observer.assertComplete();
observer.await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
Aggregations