Search in sources :

Example 11 with PutResult

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

the class PutOperationDesignTest method putObjectBlocking.

@Test
public void putObjectBlocking() {
    Article article = Article.newInstance(null, "test");
    PutResult putResult = storIOContentResolver().put().object(article).withPutResolver(ArticleMeta.PUT_RESOLVER).prepare().executeAsBlocking();
}
Also used : PutResult(com.pushtorefresh.storio.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 12 with PutResult

use of com.pushtorefresh.storio.contentresolver.operations.put.PutResult 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));
}
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 13 with PutResult

use of com.pushtorefresh.storio.contentresolver.operations.put.PutResult 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));
}
Also used : Changes(com.pushtorefresh.storio.contentresolver.Changes) TestSubscriber(rx.observers.TestSubscriber) Cursor(android.database.Cursor) PutResult(com.pushtorefresh.storio.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 14 with PutResult

use of com.pushtorefresh.storio.contentresolver.operations.put.PutResult 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));
}
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 15 with PutResult

use of com.pushtorefresh.storio.contentresolver.operations.put.PutResult 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));
}
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