Search in sources :

Example 31 with Changes

use of com.pushtorefresh.storio.contentresolver.Changes 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 32 with Changes

use of com.pushtorefresh.storio.contentresolver.Changes in project storio by pushtorefresh.

the class DeleteOperationTest method deleteObjectasRxObservable.

@Test
public void deleteObjectasRxObservable() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).take(2).subscribe(changesTestSubscriber);
    TestItem testItemToInsert = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
    Cursor firstDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(firstDbState).hasCount(1);
    //noinspection ConstantConditions
    assertThat(firstDbState.moveToFirst()).isTrue();
    TestItem testItem = TestItem.fromCursor(firstDbState);
    DeleteResult deleteResult = storIOContentResolver.delete().object(testItem).prepare().asRxObservable().toBlocking().first();
    assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
    Cursor secondDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(secondDbState).hasCount(0);
    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) DeleteResult(com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 33 with Changes

use of com.pushtorefresh.storio.contentresolver.Changes in project storio by pushtorefresh.

the class DeleteOperationTest method deleteObjectExecuteAsBlocking.

@Test
public void deleteObjectExecuteAsBlocking() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).take(2).subscribe(changesTestSubscriber);
    TestItem testItemToInsert = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
    Cursor firstDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(firstDbState).hasCount(1);
    //noinspection ConstantConditions
    assertThat(firstDbState.moveToFirst()).isTrue();
    TestItem testItem = TestItem.fromCursor(firstDbState);
    DeleteResult deleteResult = storIOContentResolver.delete().object(testItem).prepare().executeAsBlocking();
    assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(1);
    Cursor secondDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(secondDbState).hasCount(0);
    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) DeleteResult(com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 34 with Changes

use of com.pushtorefresh.storio.contentresolver.Changes in project storio by pushtorefresh.

the class DeleteOperationTest method deleteObjectsExecuteAsBlocking.

@Test
public void deleteObjectsExecuteAsBlocking() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI).take(2).subscribe(changesTestSubscriber);
    TestItem testItemToInsert = TestItem.create(null, "value");
    contentResolver.insert(TestItem.CONTENT_URI, testItemToInsert.toContentValues());
    Cursor firstDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(firstDbState).hasCount(1);
    //noinspection ConstantConditions
    assertThat(firstDbState.moveToFirst()).isTrue();
    TestItem testItem = TestItem.fromCursor(firstDbState);
    DeleteResults<TestItem> deleteResults = storIOContentResolver.delete().objects(singletonList(testItem)).prepare().executeAsBlocking();
    assertThat(deleteResults.wasDeleted(testItem)).isTrue();
    Cursor secondDbState = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(secondDbState).hasCount(0);
    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) Test(org.junit.Test)

Example 35 with Changes

use of com.pushtorefresh.storio.contentresolver.Changes 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)

Aggregations

Changes (com.pushtorefresh.storio.contentresolver.Changes)37 Test (org.junit.Test)37 TestSubscriber (rx.observers.TestSubscriber)34 Cursor (android.database.Cursor)32 Uri (android.net.Uri)15 PutResult (com.pushtorefresh.storio.contentresolver.operations.put.PutResult)15 DeleteResult (com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult)6 ContentResolver (android.content.ContentResolver)5 ContentObserver (android.database.ContentObserver)5 Mockito.doAnswer (org.mockito.Mockito.doAnswer)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Answer (org.mockito.stubbing.Answer)5 ContentValues (android.content.ContentValues)4 HashSet (java.util.HashSet)4 Handler (android.os.Handler)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Subscription (rx.Subscription)3 TargetApi (android.annotation.TargetApi)2 HashMap (java.util.HashMap)2 DeleteResults (com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResults)1