Search in sources :

Example 1 with SyncConfigurator

use of com.amplifyframework.datastore.appsync.AppSyncMocking.SyncConfigurator 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);
}
Also used : Arrays(java.util.Arrays) Single(io.reactivex.rxjava3.core.Single) SyncConfigurator(com.amplifyframework.datastore.appsync.AppSyncMocking.SyncConfigurator) AmplifyException(com.amplifyframework.AmplifyException) QueryPredicates(com.amplifyframework.core.model.query.predicate.QueryPredicates) GraphQLRequest(com.amplifyframework.api.graphql.GraphQLRequest) BlogOwner(com.amplifyframework.testmodels.commentsblog.BlogOwner) Test(org.junit.Test) Completable(io.reactivex.rxjava3.core.Completable) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) DataStoreException(com.amplifyframework.datastore.DataStoreException) Consumer(com.amplifyframework.core.Consumer) Observable(io.reactivex.rxjava3.core.Observable) ModelSchema(com.amplifyframework.core.model.ModelSchema) GraphQLResponse(com.amplifyframework.api.graphql.GraphQLResponse) Temporal(com.amplifyframework.core.model.temporal.Temporal) PaginatedResult(com.amplifyframework.api.graphql.PaginatedResult) NoOpAction(com.amplifyframework.core.NoOpAction) NoOpConsumer(com.amplifyframework.core.NoOpConsumer) Collections(java.util.Collections) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) DataStoreException(com.amplifyframework.datastore.DataStoreException) PaginatedResult(com.amplifyframework.api.graphql.PaginatedResult) BlogOwner(com.amplifyframework.testmodels.commentsblog.BlogOwner) Test(org.junit.Test)

Aggregations

AmplifyException (com.amplifyframework.AmplifyException)1 GraphQLRequest (com.amplifyframework.api.graphql.GraphQLRequest)1 GraphQLResponse (com.amplifyframework.api.graphql.GraphQLResponse)1 PaginatedResult (com.amplifyframework.api.graphql.PaginatedResult)1 Consumer (com.amplifyframework.core.Consumer)1 NoOpAction (com.amplifyframework.core.NoOpAction)1 NoOpConsumer (com.amplifyframework.core.NoOpConsumer)1 ModelSchema (com.amplifyframework.core.model.ModelSchema)1 QueryPredicates (com.amplifyframework.core.model.query.predicate.QueryPredicates)1 Temporal (com.amplifyframework.core.model.temporal.Temporal)1 DataStoreException (com.amplifyframework.datastore.DataStoreException)1 SyncConfigurator (com.amplifyframework.datastore.appsync.AppSyncMocking.SyncConfigurator)1 BlogOwner (com.amplifyframework.testmodels.commentsblog.BlogOwner)1 Completable (io.reactivex.rxjava3.core.Completable)1 Observable (io.reactivex.rxjava3.core.Observable)1 Single (io.reactivex.rxjava3.core.Single)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 TimeUnit (java.util.concurrent.TimeUnit)1