Search in sources :

Example 16 with PutResult

use of com.pushtorefresh.storio.contentresolver.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).take(1).subscribe(changesTestSubscriber);
    TestItem testItem = TestItem.create(null, "value");
    ContentValues cv = testItem.toContentValues();
    BlockingSingle<PutResult> insertResult = storIOContentResolver.put().contentValues(cv).withPutResolver(testItemContentValuesPutResolver).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();
    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) ContentValues(android.content.ContentValues) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) PutResult(com.pushtorefresh.storio.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 17 with PutResult

use of com.pushtorefresh.storio.contentresolver.operations.put.PutResult in project storio by pushtorefresh.

the class PutOperationTest method updateContentValuesAsObservable.

@Test
public void updateContentValuesAsObservable() {
    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().asRxObservable().toBlocking().first();
    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));
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) Uri(android.net.Uri) PutResult(com.pushtorefresh.storio.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 18 with PutResult

use of com.pushtorefresh.storio.contentresolver.operations.put.PutResult in project storio by pushtorefresh.

the class PutOperationTest method updateObjectExecuteAsBlocking.

@Test
public void updateObjectExecuteAsBlocking() {
    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().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));
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) Uri(android.net.Uri) PutResult(com.pushtorefresh.storio.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 19 with PutResult

use of com.pushtorefresh.storio.contentresolver.operations.put.PutResult in project storio by pushtorefresh.

the class PutOperationTest method updateObjectAsObservable.

@Test
public void updateObjectAsObservable() {
    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().object(testItem).prepare().asRxObservable().toBlocking().first();
    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));
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) Uri(android.net.Uri) PutResult(com.pushtorefresh.storio.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Aggregations

PutResult (com.pushtorefresh.storio.contentresolver.operations.put.PutResult)19 Test (org.junit.Test)19 Cursor (android.database.Cursor)15 Changes (com.pushtorefresh.storio.contentresolver.Changes)15 TestSubscriber (rx.observers.TestSubscriber)15 Uri (android.net.Uri)8 ContentValues (android.content.ContentValues)6