use of com.amplifyframework.api.graphql.MutationType in project amplify-android by aws-amplify.
the class OrchestratorTest method itemsPlacedInStorageArePublishedToNetwork.
/**
* When an item is placed into storage, a cascade of
* things happen which should ultimately result in a mutation call
* to the API category, with an {@link MutationType} corresponding to the type of
* modification that was made to the storage.
* @throws AmplifyException On failure to load model schema into registry
*/
// Casting ? in HubEvent<?> to PendingMutation<? extends Model>
@SuppressWarnings("unchecked")
@Test
public void itemsPlacedInStorageArePublishedToNetwork() throws AmplifyException {
// Arrange: orchestrator is running
orchestrator.start().test();
orchestratorInitObserver.await(10, TimeUnit.SECONDS);
HubAccumulator accumulator = HubAccumulator.create(HubChannel.DATASTORE, isProcessed(susan), 1).start();
// Act: Put BlogOwner into storage, and wait for it to complete.
SynchronousStorageAdapter.delegatingTo(localStorageAdapter).save(susan);
// Assert that the event is published out to the API
assertEquals(Collections.singletonList(susan), Observable.fromIterable(accumulator.await(10, TimeUnit.SECONDS)).map(HubEvent::getData).map(data -> (OutboxMutationEvent<BlogOwner>) data).map(OutboxMutationEvent::getElement).map(OutboxMutationEvent.OutboxMutationEventElement::getModel).toList().blockingGet());
assertTrue(orchestrator.stop().blockingAwait(5, TimeUnit.SECONDS));
}
use of com.amplifyframework.api.graphql.MutationType in project amplify-android by aws-amplify.
the class OutboxMutationFailedEvent method create.
/**
* Constructs an outbox mutation error event.
* @param pendingMutation pending mutation that failed to publish
* @param errors the list of graphQL errors that caused the failure
* @param <M> Class type of the model.
* @return Outbox mutation error event.
*/
@NonNull
public static <M extends Model> OutboxMutationFailedEvent<M> create(@NonNull PendingMutation<M> pendingMutation, @NonNull List<GraphQLResponse.Error> errors) {
Objects.requireNonNull(pendingMutation);
Objects.requireNonNull(errors);
MutationErrorType errorType = MutationErrorType.fromGraphQlErrors(errors);
String operation = pendingMutation.getMutationType().name();
MutationType opType = MutationType.valueOf(operation);
String name = pendingMutation.getModelSchema().getName();
M model = pendingMutation.getMutatedItem();
return new OutboxMutationFailedEvent<>(errorType, opType, name, model);
}
Aggregations