use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class AppSyncConflictUnhandledErrorFactoryTest method createUnhandledConflictError.
/**
* Validates that the {@link AppSyncConflictUnhandledErrorFactory} is capable
* of creating {@link AppSyncConflictUnhandledError}s from {@link ModelWithMetadata}.
*/
@Test
public void createUnhandledConflictError() {
BlogOwner model = BlogOwner.builder().name("Blogger Tony").build();
Temporal.Timestamp lastChangedAt = new Temporal.Timestamp(1602732606L, TimeUnit.SECONDS);
ModelMetadata metadata = new ModelMetadata(model.getId(), true, 6, lastChangedAt);
ModelWithMetadata<BlogOwner> serverData = new ModelWithMetadata<>(model, metadata);
AppSyncConflictUnhandledError<BlogOwner> error = AppSyncConflictUnhandledErrorFactory.createUnhandledConflictError(serverData);
assertEquals(serverData, error.getServerVersion());
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class AppSyncMockingTest method mockFailureForSync.
/**
* When mockFailure() is called on the SyncConfigurator, the AppSync mock
* will emit the provided failure.
* @throws DataStoreException On failure to get a SyncConfigurator via sync()
*/
@Test
public void mockFailureForSync() throws DataStoreException {
DataStoreException failure = new DataStoreException("Foo", "Bar");
AppSyncMocking.sync(appSync).mockFailure(failure);
GraphQLRequest<PaginatedResult<ModelWithMetadata<BlogOwner>>> request = appSync.buildSyncRequest(schema, null, 100, QueryPredicates.all());
Single.create(emitter -> appSync.sync(request, emitter::onSuccess, emitter::onError)).test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS).assertError(failure);
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class AppSyncRequestFactoryTest method validateUpdateWithPredicateGeneration.
/**
* Checks that we're getting the expected output for a mutation with predicate.
* @throws DataStoreException If the output does not match.
* @throws AmplifyException On failure to parse ModelSchema from model class
* @throws JSONException from JSONAssert.assertEquals.
*/
@Test
public void validateUpdateWithPredicateGeneration() throws AmplifyException, JSONException {
String blogOwnerId = "926d7ee8-4ea5-40c0-8e62-3fb80b2a2edd";
BlogOwner owner = BlogOwner.builder().name("John Doe").id(blogOwnerId).build();
ModelSchema schema = ModelSchema.fromModelClass(BlogOwner.class);
AppSyncGraphQLRequest<?> request = AppSyncRequestFactory.buildUpdateRequest(schema, owner, 42, BlogOwner.WEA.contains("ther"), DEFAULT_STRATEGY);
JSONAssert.assertEquals(Resources.readAsString("update-blog-owner-with-predicate.txt"), request.getContent(), true);
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class AppSyncClientTest method validateBaseSyncQueryGen.
/**
* Validates the construction of a base-sync query.
* @throws JSONException On bad request JSON found in API category call
* @throws DataStoreException If no valid response returned from AppSync endpoint during sync
* @throws AmplifyException On failure to arrange model schema
*/
@Test
public void validateBaseSyncQueryGen() throws JSONException, AmplifyException {
ModelSchema schema = ModelSchema.fromModelClass(BlogOwner.class);
Await.result((Consumer<GraphQLResponse<PaginatedResult<ModelWithMetadata<BlogOwner>>>> onResult, Consumer<DataStoreException> onError) -> {
try {
GraphQLRequest<PaginatedResult<ModelWithMetadata<BlogOwner>>> request = endpoint.buildSyncRequest(schema, null, null, QueryPredicates.all());
endpoint.sync(request, onResult, onError);
} catch (DataStoreException datastoreException) {
onError.accept(datastoreException);
}
});
// Now, capture the request argument on API, so we can see what was passed.
// Recall that we pass a raw doc to API.
ArgumentCaptor<GraphQLRequest<ModelWithMetadata<BlogOwner>>> requestCaptor = ArgumentCaptor.forClass(GraphQLRequest.class);
verify(api).query(requestCaptor.capture(), any(Consumer.class), any(Consumer.class));
GraphQLRequest<ModelWithMetadata<BlogOwner>> capturedRequest = requestCaptor.getValue();
Type type = TypeMaker.getParameterizedType(PaginatedResult.class, ModelWithMetadata.class, BlogOwner.class);
assertEquals(type, capturedRequest.getResponseType());
// The request was sent as JSON. It has a null variables field, and a present query field.
JSONAssert.assertEquals(Resources.readAsString("base-sync-request-document-for-blog-owner.txt"), capturedRequest.getContent(), true);
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class BasicCloudSyncInstrumentationTest method updateAfterCreate.
/**
* Verify that updating an item shortly after creating it succeeds. This can be tricky because the _version
* returned in the response from the create request must be included in the input for the subsequent update request.
* @throws DataStoreException On failure to save or query items from DataStore.
* @throws ApiException On failure to query the API.
*/
@Test
public void updateAfterCreate() throws DataStoreException, ApiException {
// Setup
BlogOwner richard = BlogOwner.builder().name("Richard").build();
BlogOwner updatedRichard = richard.copyOfBuilder().name("Richard McClellan").build();
String modelName = BlogOwner.class.getSimpleName();
// Expect two mutations to be published to AppSync.
HubAccumulator richardAccumulator = HubAccumulator.create(HubChannel.DATASTORE, publicationOf(modelName, richard.getId()), 2).start();
// Create an item, then update it and save it again.
dataStore.save(richard);
dataStore.save(updatedRichard);
// Verify that 2 mutations were published.
richardAccumulator.await(30, TimeUnit.SECONDS);
// Verify that the updatedRichard is saved in the DataStore.
BlogOwner localRichard = dataStore.get(BlogOwner.class, richard.getId());
ModelAssert.assertEqualsIgnoringTimestamps(updatedRichard, localRichard);
// Verify that the updatedRichard is saved on the backend.
BlogOwner remoteRichard = api.get(BlogOwner.class, richard.getId());
ModelAssert.assertEqualsIgnoringTimestamps(updatedRichard, remoteRichard);
}
Aggregations