use of com.amplifyframework.core.model.Model in project amplify-android by aws-amplify.
the class RxDataStoreBindingTest method deleteEmitsErrorWhenBehaviorDoes.
/**
* When the DataStore delete behavior emits a result, the Rx binding
* should just complete.
* @throws InterruptedException If interrupted while test observer is awaiting terminal event
*/
@Test
public void deleteEmitsErrorWhenBehaviorDoes() throws InterruptedException {
// Arrange: delete() category behavior will callback failure consumer
Model model = RandomModel.model();
DataStoreException expectedFailure = new DataStoreException("Expected", "Failure");
doAnswer(invocation -> {
final int indexOfFailureConsumer = 2;
Consumer<DataStoreException> failureConsumer = invocation.getArgument(indexOfFailureConsumer);
failureConsumer.accept(expectedFailure);
return null;
}).when(delegate).delete(eq(model), anyConsumer(), anyConsumer());
// Act: try to delete a model via the Rx binding
TestObserver<Void> observer = rxDataStore.delete(model).test();
// Assert: the same failure bubbled out from the category behavior
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertError(expectedFailure);
verify(delegate).delete(eq(model), anyConsumer(), anyConsumer());
}
use of com.amplifyframework.core.model.Model in project amplify-android by aws-amplify.
the class SQLiteStorageAdapterSaveTest method patchItemOnlyHasChangedFields.
/**
* Verify that saving an item that already exists emits a StorageItemChange event with a patchItem that only
* contains the fields that are different.
*
* @throws AmplifyException On failure to obtain ModelSchema from model class.
* @throws InterruptedException If interrupted while awaiting terminal result in test observer
*/
@Test
public void patchItemOnlyHasChangedFields() throws AmplifyException, InterruptedException {
// Create a BlogOwner.
final BlogOwner johnSmith = BlogOwner.builder().name("John Smith").wea("ther").build();
adapter.save(johnSmith);
// Start observing for changes
TestObserver<StorageItemChange<? extends Model>> observer = adapter.observe().test();
// Update one field on the BlogOwner.
BlogOwner johnAdams = johnSmith.copyOfBuilder().name("John Adams").build();
adapter.save(johnAdams);
// Observe that the StorageItemChange contains an item with only the fields that changed (`id`, and `name`, but
// not `wea`)
Map<String, Object> serializedData = new HashMap<>();
serializedData.put("id", johnAdams.getId());
serializedData.put("name", "John Adams");
SerializedModel expectedItem = SerializedModel.builder().serializedData(serializedData).modelSchema(ModelSchema.fromModelClass(BlogOwner.class)).build();
observer.await(1, TimeUnit.SECONDS);
observer.assertValueCount(1);
observer.assertValueAt(0, storageItemChange -> storageItemChange.patchItem().equals(expectedItem));
}
Aggregations