Search in sources :

Example 1 with PutResult

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

the class PutOperationDesignTest method putContentValuesSingle.

@Test
public void putContentValuesSingle() {
    ContentValues contentValues = mock(ContentValues.class);
    Single<PutResult> putResultSingle = storIOContentResolver().put().contentValues(contentValues).withPutResolver(putResolverForContentValues).prepare().asRxSingle();
}
Also used : ContentValues(android.content.ContentValues) PutResult(com.pushtorefresh.storio.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 2 with PutResult

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

the class PutOperationDesignTest method putContentValuesObservable.

@Test
public void putContentValuesObservable() {
    ContentValues contentValues = mock(ContentValues.class);
    Observable<PutResult> putResultObservable = storIOContentResolver().put().contentValues(contentValues).withPutResolver(putResolverForContentValues).prepare().asRxObservable();
}
Also used : ContentValues(android.content.ContentValues) PutResult(com.pushtorefresh.storio.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 3 with PutResult

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

the class PutOperationTest method insertObjectExecuteAsBlocking.

@Test
public void insertObjectExecuteAsBlocking() {
    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().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));
}
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 4 with PutResult

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

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

the class PutOperationTest method insertContentValuesExecuteAsBlocking.

@Test
public void insertContentValuesExecuteAsBlocking() {
    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().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();
    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)

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