use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class PutOperationTest method updateObjectAsSingle.
@Test
public void updateObjectAsSingle() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(2).subscribe(changesTestSubscriber);
Uri insertedUri = contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value").toContentValues());
TestItem testItem = TestItem.create(ContentUris.parseId(insertedUri), "value2");
PutResult updateResult = storIOContentResolver.put().object(testItem).prepare().asRxSingle().blockingGet();
assertThat(updateResult.wasUpdated()).isTrue();
Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(cursor).hasCount(1);
cursor.moveToFirst();
assertThat(testItem).isEqualTo(TestItem.fromCursor(cursor));
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValues(Changes.newInstance(TestItem.CONTENT_URI), Changes.newInstance(TestItem.CONTENT_URI));
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class PutOperationTest method insertContentValuesAsCompletable.
@Test
public void insertContentValuesAsCompletable() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(1).subscribe(changesTestSubscriber);
TestItem testItem = TestItem.create(null, "value");
ContentValues cv = testItem.toContentValues();
storIOContentResolver.put().contentValues(cv).withPutResolver(testItemContentValuesPutResolver).prepare().asRxCompletable().blockingAwait(15, SECONDS);
Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(cursor).hasCount(1);
cursor.moveToFirst();
assertThat(testItem.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class DeleteOperationTest method deleteByQueryAsCompletable.
@Test
public void deleteByQueryAsCompletable() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(2).subscribe(changesTestSubscriber);
TestItem testItemToInsert = TestItem.create(null, "value");
contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
Cursor firstDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(firstDbState).hasCount(1);
storIOContentResolver.delete().byQuery(DeleteQuery.builder().uri(TestItem.CONTENT_URI).build()).prepare().asRxCompletable().blockingAwait(15, SECONDS);
Cursor secondDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
Assertions.assertThat(secondDbState).hasCount(0);
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValues(Changes.newInstance(TestItem.CONTENT_URI), Changes.newInstance(TestItem.CONTENT_URI));
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method observeChangesInTable.
@Test
public void observeChangesInTable() {
TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
storIOSQLite.observeChangesInTable("table1", LATEST).subscribe(testSubscriber);
testSubscriber.assertNoValues();
Changes changes1 = Changes.newInstance("table2");
storIOSQLite.lowLevel().notifyAboutChanges(changes1);
testSubscriber.assertNoValues();
Changes changes2 = Changes.newInstance("table1");
storIOSQLite.lowLevel().notifyAboutChanges(changes2);
testSubscriber.assertValue(changes2);
Changes changes3 = Changes.newInstance("table3");
storIOSQLite.lowLevel().notifyAboutChanges(changes3);
// Subscriber should not see changes of table2 and table3
testSubscriber.assertValue(changes2);
testSubscriber.assertNoErrors();
testSubscriber.dispose();
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class ObserveChangesInTableTest method insertEmission.
@Test
public void insertEmission() {
final List<User> users = TestFactory.newUsers(10);
final Queue<Changes> expectedChanges = new LinkedList<Changes>();
expectedChanges.add(Changes.newInstance(UserTableMeta.TABLE, UserTableMeta.NOTIFICATION_TAG));
final EmissionChecker emissionChecker = new EmissionChecker(expectedChanges);
final Disposable disposable = emissionChecker.subscribe();
putUsersBlocking(users);
// Should receive changes of Users table
emissionChecker.awaitNextExpectedValue();
emissionChecker.assertThatNoExpectedValuesLeft();
disposable.dispose();
}
Aggregations