Search in sources :

Example 1 with LocalStorageAdapter

use of com.amplifyframework.datastore.storage.LocalStorageAdapter in project amplify-android by aws-amplify.

the class MutationProcessorTest method setup.

/**
 * A {@link MutationProcessor} is being tested. To do so, we arrange mutations into
 * an {@link MutationOutbox}. Fake responses are returned from a mock {@link AppSync}.
 * @throws AmplifyException When loading SchemaRegistry
 */
@Before
public void setup() throws AmplifyException {
    ShadowLog.stream = System.out;
    LocalStorageAdapter localStorageAdapter = InMemoryStorageAdapter.create();
    this.synchronousStorageAdapter = SynchronousStorageAdapter.delegatingTo(localStorageAdapter);
    this.mutationOutbox = new PersistentMutationOutbox(localStorageAdapter);
    VersionRepository versionRepository = new VersionRepository(localStorageAdapter);
    Merger merger = new Merger(mutationOutbox, versionRepository, localStorageAdapter);
    this.appSync = mock(AppSync.class);
    this.configurationProvider = mock(DataStoreConfigurationProvider.class);
    ConflictResolver conflictResolver = new ConflictResolver(configurationProvider, appSync);
    schemaRegistry = SchemaRegistry.instance();
    schemaRegistry.register(Collections.singleton(BlogOwner.class));
    this.mutationProcessor = MutationProcessor.builder().merger(merger).versionRepository(versionRepository).schemaRegistry(schemaRegistry).mutationOutbox(mutationOutbox).appSync(appSync).conflictResolver(conflictResolver).build();
}
Also used : DataStoreConfigurationProvider(com.amplifyframework.datastore.DataStoreConfigurationProvider) LocalStorageAdapter(com.amplifyframework.datastore.storage.LocalStorageAdapter) AppSync(com.amplifyframework.datastore.appsync.AppSync) BlogOwner(com.amplifyframework.testmodels.commentsblog.BlogOwner) Before(org.junit.Before)

Example 2 with LocalStorageAdapter

use of com.amplifyframework.datastore.storage.LocalStorageAdapter in project amplify-android by aws-amplify.

the class MutationPersistenceInstrumentationTest method obtainLocalStorageAndValidateModelSchema.

/**
 * Prepare an instance of {@link LocalStorageAdapter}. Evaluate its
 * emitted collection of ModelSchema, to ensure that
 * {@link PendingMutation.PersistentRecord} is among them.
 *
 * TODO: later, consider hiding system schema, such as the
 * {@link PendingMutation.PersistentRecord}, from the callback. This schema might be
 * an implementation detail, that is working as a leaky abstraction.
 *
 * @throws AmplifyException On failure to initialize the storage adapter,
 *                          or on failure to load model schema into registry
 */
@Before
public void obtainLocalStorageAndValidateModelSchema() throws AmplifyException {
    this.converter = new GsonPendingMutationConverter();
    getApplicationContext().deleteDatabase(DATABASE_NAME);
    ModelProvider modelProvider = SimpleModelProvider.withRandomVersion(BlogOwner.class);
    schemaRegistry = SchemaRegistry.instance();
    schemaRegistry.clear();
    schemaRegistry.register(modelProvider.models());
    LocalStorageAdapter localStorageAdapter = SQLiteStorageAdapter.forModels(schemaRegistry, modelProvider);
    this.storage = SynchronousStorageAdapter.delegatingTo(localStorageAdapter);
    List<ModelSchema> initializationResults = storage.initialize(getApplicationContext());
    // Evaluate the returned set of ModelSchema. Ensure that there is one
    // for the PendingMutation.PersistentRecord system class.
    assertTrue(Observable.fromIterable(initializationResults).map(ModelSchema::getName).toList().blockingGet().contains(PendingMutation.PersistentRecord.class.getSimpleName()));
}
Also used : ModelSchema(com.amplifyframework.core.model.ModelSchema) LocalStorageAdapter(com.amplifyframework.datastore.storage.LocalStorageAdapter) ModelProvider(com.amplifyframework.core.model.ModelProvider) SimpleModelProvider(com.amplifyframework.datastore.model.SimpleModelProvider) Before(org.junit.Before)

Aggregations

LocalStorageAdapter (com.amplifyframework.datastore.storage.LocalStorageAdapter)2 Before (org.junit.Before)2 ModelProvider (com.amplifyframework.core.model.ModelProvider)1 ModelSchema (com.amplifyframework.core.model.ModelSchema)1 DataStoreConfigurationProvider (com.amplifyframework.datastore.DataStoreConfigurationProvider)1 AppSync (com.amplifyframework.datastore.appsync.AppSync)1 SimpleModelProvider (com.amplifyframework.datastore.model.SimpleModelProvider)1 BlogOwner (com.amplifyframework.testmodels.commentsblog.BlogOwner)1