Search in sources :

Example 1 with AppSyncClient

use of com.amplifyframework.datastore.appsync.AppSyncClient in project amplify-android by aws-amplify.

the class OrchestratorTest method setup.

/**
 * Setup mocks and other common elements.
 * @throws AmplifyException Not expected.
 */
@SuppressWarnings("unchecked")
@Before
public void setup() throws AmplifyException {
    ShadowLog.stream = System.out;
    // Arrange: create a BlogOwner
    susan = BlogOwner.builder().name("Susan Quimby").build();
    // SYNC_QUERIES_READY indicates that the sync queries have completed.
    orchestratorInitObserver = HubAccumulator.create(HubChannel.DATASTORE, DataStoreChannelEventName.SYNC_QUERIES_READY, 1).start();
    ModelMetadata metadata = new ModelMetadata(susan.getId(), false, 1, Temporal.Timestamp.now());
    ModelWithMetadata<BlogOwner> modelWithMetadata = new ModelWithMetadata<>(susan, metadata);
    // Mock behaviors from for the API category
    mockApi = mock(GraphQLBehavior.class);
    ApiMocking.mockSubscriptionStart(mockApi);
    ApiMocking.mockSuccessfulMutation(mockApi, susan.getId(), modelWithMetadata);
    ApiMocking.mockSuccessfulQuery(mockApi, modelWithMetadata);
    AppSyncClient appSync = AppSyncClient.via(mockApi);
    localStorageAdapter = InMemoryStorageAdapter.create();
    ModelProvider modelProvider = SimpleModelProvider.withRandomVersion(BlogOwner.class);
    SchemaRegistry schemaRegistry = SchemaRegistry.instance();
    schemaRegistry.clear();
    schemaRegistry.register(modelProvider.models());
    orchestrator = new Orchestrator(modelProvider, schemaRegistry, localStorageAdapter, appSync, DataStoreConfiguration::defaults, () -> Orchestrator.State.SYNC_VIA_API, true);
}
Also used : GraphQLBehavior(com.amplifyframework.api.graphql.GraphQLBehavior) ModelWithMetadata(com.amplifyframework.datastore.appsync.ModelWithMetadata) AppSyncClient(com.amplifyframework.datastore.appsync.AppSyncClient) ModelProvider(com.amplifyframework.core.model.ModelProvider) SimpleModelProvider(com.amplifyframework.datastore.model.SimpleModelProvider) BlogOwner(com.amplifyframework.testmodels.commentsblog.BlogOwner) ModelMetadata(com.amplifyframework.datastore.appsync.ModelMetadata) SchemaRegistry(com.amplifyframework.core.model.SchemaRegistry) Before(org.junit.Before)

Aggregations

GraphQLBehavior (com.amplifyframework.api.graphql.GraphQLBehavior)1 ModelProvider (com.amplifyframework.core.model.ModelProvider)1 SchemaRegistry (com.amplifyframework.core.model.SchemaRegistry)1 AppSyncClient (com.amplifyframework.datastore.appsync.AppSyncClient)1 ModelMetadata (com.amplifyframework.datastore.appsync.ModelMetadata)1 ModelWithMetadata (com.amplifyframework.datastore.appsync.ModelWithMetadata)1 SimpleModelProvider (com.amplifyframework.datastore.model.SimpleModelProvider)1 BlogOwner (com.amplifyframework.testmodels.commentsblog.BlogOwner)1 Before (org.junit.Before)1