use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class RxDataStoreBindingTest method clearFailsWhenCategoryBehaviorDoes.
/**
* The Rx binding for the DataStore's clear() method will propagate failures
* faithfully from the underlying delegate.
* @throws InterruptedException If interrupted while test observer is awaiting terminal event
*/
@Test
public void clearFailsWhenCategoryBehaviorDoes() throws InterruptedException {
// Arrange a failure in the category behavior
DataStoreException expectedFailure = new DataStoreException("Expected", "Failure");
doAnswer(invocation -> {
// 0 = onComplete, 1 = onFailure
final int positionOfOnFailure = 1;
Consumer<DataStoreException> onFailure = invocation.getArgument(positionOfOnFailure);
onFailure.accept(expectedFailure);
// "void"
return null;
}).when(delegate).clear(anyAction(), anyConsumer());
// Act: clear the store.
TestObserver<Void> observer = rxDataStore.clear().test();
// Assert: failure propagates through binding.
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertError(expectedFailure);
}
use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class RxDataStoreBindingTest method queryEmitsFailureWhenCategoryBehaviorDoes.
/**
* When the DataStore emits a failure for a query, the Rx binding should terminate
* with that failure.
* @throws InterruptedException If interrupted while test observer is awaiting terminal event
*/
@Test
public void queryEmitsFailureWhenCategoryBehaviorDoes() throws InterruptedException {
DataStoreException expectedFailure = new DataStoreException("Expected", "Failure");
doAnswer(invocation -> {
final int positionOrFailureConsumer = 2;
Consumer<DataStoreException> failureConsumer = invocation.getArgument(positionOrFailureConsumer);
failureConsumer.accept(expectedFailure);
return null;
}).when(delegate).query(eq(Model.class), anyConsumer(), anyConsumer());
TestObserver<Model> observer = rxDataStore.query(Model.class).test();
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertError(expectedFailure);
verify(delegate).query(eq(Model.class), anyConsumer(), anyConsumer());
}
use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class RxDataStoreBindingTest method startFailsWhenCategoryBehaviorDoes.
/**
* The Rx binding for the DataStore's start() method will propagate failures
* faithfully from the underlying delegate.
* @throws InterruptedException If interrupted while test observer is awaiting terminal event
*/
@Test
public void startFailsWhenCategoryBehaviorDoes() throws InterruptedException {
// Arrange a failure in the category behavior
DataStoreException expectedFailure = new DataStoreException("Expected", "Failure");
doAnswer(invocation -> {
// 0 = onComplete, 1 = onFailure
final int positionOfOnFailure = 1;
Consumer<DataStoreException> onFailure = invocation.getArgument(positionOfOnFailure);
onFailure.accept(expectedFailure);
// "void"
return null;
}).when(delegate).start(anyAction(), anyConsumer());
// Act: start the store.
TestObserver<Void> observer = rxDataStore.start().test();
// Assert: failure propagates through binding.
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertError(expectedFailure);
}
use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class RxDataStoreBindingTest method stopFailsWhenCategoryBehaviorDoes.
/**
* The Rx binding for the DataStore's stop() method will propagate failures
* faithfully from the underlying delegate.
* @throws InterruptedException If interrupted while test observer is awaiting terminal event
*/
@Test
public void stopFailsWhenCategoryBehaviorDoes() throws InterruptedException {
// Arrange a failure in the category behavior
DataStoreException expectedFailure = new DataStoreException("Expected", "Failure");
doAnswer(invocation -> {
// 0 = onComplete, 1 = onFailure
final int positionOfOnFailure = 1;
Consumer<DataStoreException> onFailure = invocation.getArgument(positionOfOnFailure);
onFailure.accept(expectedFailure);
// "void"
return null;
}).when(delegate).stop(anyAction(), anyConsumer());
// Act: stop the store.
TestObserver<Void> observer = rxDataStore.stop().test();
// Assert: failure propagates through binding.
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertError(expectedFailure);
}
use of com.amplifyframework.datastore.DataStoreException in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterDeleteTest method deleteModelCascades.
/**
* Assert that delete deletes item in the SQLite database without
* violating foreign key constraints.
* @throws DataStoreException On unexpected failure manipulating items in/out of DataStore
*/
@Test
public void deleteModelCascades() throws DataStoreException {
// Create 1 blog owner, which has 3 blogs each, which has 3 posts each.
// Insert 1 blog owner, 3 blogs, 9 posts
Set<String> expected = new HashSet<>();
BlogOwner ownerModel = BlogOwner.builder().name("Blog Owner 1").build();
adapter.save(ownerModel);
expected.add(ownerModel.getId());
for (int blog = 1; blog <= 3; blog++) {
Blog blogModel = Blog.builder().name("Blog " + blog).owner(ownerModel).build();
adapter.save(blogModel);
expected.add(blogModel.getId());
for (int post = 1; post <= 3; post++) {
Post postModel = Post.builder().title("Post " + post).status(PostStatus.INACTIVE).rating(5).blog(blogModel).build();
adapter.save(postModel);
expected.add(postModel.getId());
}
}
// Observe deletions
TestObserver<String> deleteObserver = adapter.observe().filter(change -> StorageItemChange.Type.DELETE.equals(change.type())).map(StorageItemChange::item).map(Model::getId).test();
// Triggers a delete.
// Deletes every saved model to prevent foreign key constraint violation
adapter.delete(ownerModel);
// Assert that cascaded deletions are observed.
deleteObserver.assertValueCount(13);
assertEquals(expected, new HashSet<>(deleteObserver.values()));
// Get data from the database and assert that everything is deleted.
assertTrue(adapter.query(BlogOwner.class).isEmpty());
assertTrue(adapter.query(Blog.class).isEmpty());
assertTrue(adapter.query(Post.class).isEmpty());
}
Aggregations