use of com.pushtorefresh.storio.contentresolver.operations.put.PutResult in project storio by pushtorefresh.
the class PutOperationTest method insertContentValuesAsObservable.
@Test
public void insertContentValuesAsObservable() {
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();
PutResult insertResult = storIOContentResolver.put().contentValues(cv).withPutResolver(testItemContentValuesPutResolver).prepare().asRxObservable().toBlocking().first();
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.storio.contentresolver.operations.put.PutResult in project storio by pushtorefresh.
the class PutOperationTest method insertObjectAsObservable.
@Test
public void insertObjectAsObservable() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).take(1).subscribe(changesTestSubscriber);
TestItem testItem = TestItem.create(null, "value");
PutResult insertResult = storIOContentResolver.put().object(testItem).prepare().asRxObservable().toBlocking().first();
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.storio.contentresolver.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).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));
}
use of com.pushtorefresh.storio.contentresolver.operations.put.PutResult in project storio by pushtorefresh.
the class PutOperationTest method updateNullFieldToNotNull.
@Test
public void updateNullFieldToNotNull() {
TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).take(2).subscribe(changesTestSubscriber);
Uri insertedUri = // firstly, optional value is null
contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value", null).toContentValues());
// change to not null
TestItem testItem = TestItem.create(ContentUris.parseId(insertedUri), "value", "optionalValue");
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.operations.put.PutResult in project storio by pushtorefresh.
the class PutOperationDesignTest method putContentValuesBlocking.
@Test
public void putContentValuesBlocking() {
ContentValues contentValues = mock(ContentValues.class);
PutResult putResult = storIOContentResolver().put().contentValues(contentValues).withPutResolver(putResolverForContentValues).prepare().executeAsBlocking();
}
Aggregations