use of com.pushtorefresh.storio3.sqlite.Changes in project storio by pushtorefresh.
the class DeleteOperationTest method deleteByQueryAsRxFlowable.
@Test
public void deleteByQueryAsRxFlowable() {
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);
DeleteResult deleteResult = storIOContentResolver.delete().byQuery(DeleteQuery.builder().uri(TestItem.CONTENT_URI).build()).prepare().asRxFlowable(BackpressureStrategy.MISSING).blockingFirst();
assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
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.sqlite.Changes in project storio by pushtorefresh.
the class DeleteOperationTest method deleteObjectAsRxFlowable.
@Test
public void deleteObjectAsRxFlowable() {
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);
// noinspection ConstantConditions
assertThat(firstDbState.moveToFirst()).isTrue();
TestItem testItem = TestItem.fromCursor(firstDbState);
DeleteResult deleteResult = storIOContentResolver.delete().object(testItem).prepare().asRxFlowable(BackpressureStrategy.MISSING).blockingFirst();
assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
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.sqlite.Changes in project storio by pushtorefresh.
the class DeleteOperationTest method deleteObjectsAsSingle.
@Test
public void deleteObjectsAsSingle() {
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);
// noinspection ConstantConditions
assertThat(firstDbState.moveToFirst()).isTrue();
TestItem testItem = TestItem.fromCursor(firstDbState);
DeleteResults<TestItem> deleteResults = storIOContentResolver.delete().objects(singletonList(testItem)).prepare().asRxSingle().blockingGet();
assertThat(deleteResults.wasDeleted(testItem)).isTrue();
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.sqlite.Changes in project storio by pushtorefresh.
the class PutOperationTest method insertOneWithNullField.
@Test
public void insertOneWithNullField() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(1).subscribe(changesTestSubscriber);
// optional value is null
TestItem testItem = TestItem.create(null, "value", null);
PutResult insertResult = storIOContentResolver.put().object(testItem).prepare().executeAsBlocking();
assertThat(insertResult.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.storio3.sqlite.Changes in project storio by pushtorefresh.
the class PutOperationTest method insertContentValuesAsSingle.
@Test
public void insertContentValuesAsSingle() {
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();
PutResult insertResult = storIOContentResolver.put().contentValues(cv).withPutResolver(testItemContentValuesPutResolver).prepare().asRxSingle().blockingGet();
assertThat(insertResult.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();
changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
changesTestSubscriber.assertNoErrors();
changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
Aggregations