Search in sources :

Example 6 with DeleteResult

use of com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.

the class DeleteOperationDesignTest method deleteByQuerySingle.

@Test
public void deleteByQuerySingle() {
    final DeleteQuery deleteQuery = DeleteQuery.builder().uri(mock(Uri.class)).where("some_field = ?").whereArgs("someValue").build();
    Single<DeleteResult> deleteResultSingle = storIOContentResolver().delete().byQuery(deleteQuery).prepare().asRxSingle();
}
Also used : DeleteQuery(com.pushtorefresh.storio.contentresolver.queries.DeleteQuery) DeleteResult(com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 7 with DeleteResult

use of com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.

the class DeleteOperationTest method deleteByQueryAsObservable.

@Test
public void deleteByQueryAsObservable() {
    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);
    DeleteResult deleteResult = storIOContentResolver.delete().byQuery(DeleteQuery.builder().uri(TestItem.CONTENT_URI).build()).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 8 with DeleteResult

use of com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult in project storio by pushtorefresh.

the class DeleteOperationDesignTest method deleteByQueryObservable.

@Test
public void deleteByQueryObservable() {
    final DeleteQuery deleteQuery = DeleteQuery.builder().uri(mock(Uri.class)).where("some_field = ?").whereArgs("someValue").build();
    Observable<DeleteResult> deleteResultObservable = storIOContentResolver().delete().byQuery(deleteQuery).prepare().asRxObservable();
}
Also used : DeleteQuery(com.pushtorefresh.storio.contentresolver.queries.DeleteQuery) DeleteResult(com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 9 with DeleteResult

use of com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult 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 10 with DeleteResult

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

Aggregations

DeleteResult (com.pushtorefresh.storio.contentresolver.operations.delete.DeleteResult)10 Test (org.junit.Test)10 Cursor (android.database.Cursor)6 Changes (com.pushtorefresh.storio.contentresolver.Changes)6 TestSubscriber (rx.observers.TestSubscriber)6 DeleteQuery (com.pushtorefresh.storio.contentresolver.queries.DeleteQuery)3