use of com.pushtorefresh.storio3.sqlite.operations.put.PutResult in project storio by pushtorefresh.
the class AutoParcelTest method insertObject.
@Test
public void insertObject() {
final Book book = Book.builder().id(1).title("What a great book").author("Somebody").build();
final PutResult putResult = storIOSQLite.put().object(book).prepare().executeAsBlocking();
assertThat(putResult.wasInserted()).isTrue();
final List<Book> storedBooks = storIOSQLite.get().listOfObjects(Book.class).withQuery(Query.builder().table(BookTableMeta.TABLE).build()).prepare().executeAsBlocking();
assertThat(storedBooks).hasSize(1);
assertThat(storedBooks.get(0)).isEqualTo(book);
}
use of com.pushtorefresh.storio3.sqlite.operations.put.PutResult in project storio by pushtorefresh.
the class AutoParcelTest method updateObject.
@Test
public void updateObject() {
final Book book = Book.builder().id(1).title("What a great book").author("Somebody").build();
final PutResult putResult1 = storIOSQLite.put().object(book).prepare().executeAsBlocking();
assertThat(putResult1.wasInserted()).isTrue();
final Book bookWithUpdatedInfo = Book.builder().id(// Same id, should be updated
1).title("Corrected title").author("Corrected author").build();
final PutResult putResult2 = storIOSQLite.put().object(bookWithUpdatedInfo).prepare().executeAsBlocking();
assertThat(putResult2.wasUpdated()).isTrue();
final List<Book> storedBooks = storIOSQLite.get().listOfObjects(Book.class).withQuery(Query.builder().table(BookTableMeta.TABLE).build()).prepare().executeAsBlocking();
assertThat(storedBooks).hasSize(1);
assertThat(storedBooks.get(0)).isEqualTo(bookWithUpdatedInfo);
}
use of com.pushtorefresh.storio3.sqlite.operations.put.PutResult 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.operations.put.PutResult 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));
}
use of com.pushtorefresh.storio3.sqlite.operations.put.PutResult in project storio by pushtorefresh.
the class PutOperationTest method updateContentValuesExecuteAsBlocking.
@Test
public void updateContentValuesExecuteAsBlocking() {
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().contentValues(testItem.toContentValues()).withPutResolver(testItemContentValuesPutResolver).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));
}
Aggregations