use of com.pushtorefresh.storio.contentresolver.Changes in project storio by pushtorefresh.
the class PutOperationTest method updateContentValuesAsSingle.
@Test
public void updateContentValuesAsSingle() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).take(2).subscribe(changesTestSubscriber);
Uri insertedUri = contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value").toContentValues());
TestItem testItem = TestItem.create(ContentUris.parseId(insertedUri), "value2");
BlockingSingle<PutResult> updateResult = storIOContentResolver.put().contentValues(testItem.toContentValues()).withPutResolver(testItemContentValuesPutResolver).prepare().asRxSingle().toBlocking();
assertThat(updateResult.value().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.storio.contentresolver.Changes in project storio by pushtorefresh.
the class PutOperationTest method insertObjectAsSingle.
@Test
public void insertObjectAsSingle() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).take(1).subscribe(changesTestSubscriber);
TestItem testItem = TestItem.create(null, "value");
BlockingSingle<PutResult> insertResult = storIOContentResolver.put().object(testItem).prepare().asRxSingle().toBlocking();
assertThat(insertResult.value().wasInserted()).isTrue();
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();
cursor.close();
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
use of com.pushtorefresh.storio.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).take(2).subscribe(changesTestSubscriber);
Uri insertedUri = contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value").toContentValues());
TestItem testItem = TestItem.create(ContentUris.parseId(insertedUri), "value2");
BlockingSingle<PutResult> updateResult = storIOContentResolver.put().object(testItem).prepare().asRxSingle().toBlocking();
assertThat(updateResult.value().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.storio.contentresolver.Changes in project storio by pushtorefresh.
the class PutOperationTest method updateNotNullFieldToNull.
@Test
public void updateNotNullFieldToNull() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).take(2).subscribe(changesTestSubscriber);
Uri insertedUri = contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value", "optionalValue").toContentValues());
// optional value changes to null
TestItem testItem = TestItem.create(ContentUris.parseId(insertedUri), "value", null);
PutResult updateResult = storIOContentResolver.put().object(testItem).prepare().executeAsBlocking();
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.storio.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).take(1).subscribe(changesTestSubscriber);
TestItem testItem = TestItem.create(null, "value");
ContentValues cv = testItem.toContentValues();
storIOContentResolver.put().contentValues(cv).withPutResolver(testItemContentValuesPutResolver).prepare().asRxCompletable().toObservable().toBlocking().subscribe();
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));
}
Aggregations