Search in sources :

Example 1 with DeleteResult

use of com.pushtorefresh.storio3.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.storio3.contentresolver.queries.DeleteQuery) DeleteResult(com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 2 with DeleteResult

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

the class DeleteOperationDesignTest method deleteObjectBlocking.

@Test
public void deleteObjectBlocking() {
    Article article = mock(Article.class);
    DeleteResult deleteResult = storIOContentResolver().delete().object(article).withDeleteResolver(ArticleMeta.DELETE_RESOLVER).prepare().executeAsBlocking();
}
Also used : DeleteResult(com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 3 with DeleteResult

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

the class DeleteOperationDesignTest method deleteByQueryBlocking.

@Test
public void deleteByQueryBlocking() {
    final DeleteQuery deleteQuery = DeleteQuery.builder().uri(mock(Uri.class)).where("some_field = ?").whereArgs("someValue").build();
    DeleteResult deleteResult = storIOContentResolver().delete().byQuery(deleteQuery).prepare().executeAsBlocking();
}
Also used : DeleteQuery(com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery) DeleteResult(com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 4 with DeleteResult

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

the class DefaultDeleteResolverTest method performDelete.

@Test
public void performDelete() {
    final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
    final StorIOContentResolver.LowLevel lowLevel = mock(StorIOContentResolver.LowLevel.class);
    when(storIOContentResolver.lowLevel()).thenReturn(lowLevel);
    final int expectedNumberOfRowsDeleted = 1;
    when(lowLevel.delete(any(DeleteQuery.class))).thenReturn(expectedNumberOfRowsDeleted);
    final Uri expectedUri = mock(Uri.class);
    final DeleteQuery expectedDeleteQuery = DeleteQuery.builder().uri(expectedUri).where("test where clause").whereArgs("test").build();
    final TestItem testItem = TestItem.newInstance();
    final DefaultDeleteResolver<TestItem> defaultDeleteResolver = new DefaultDeleteResolver<TestItem>() {

        @NonNull
        @Override
        protected DeleteQuery mapToDeleteQuery(@NonNull TestItem object) {
            assertThat(object).isSameAs(testItem);
            return expectedDeleteQuery;
        }
    };
    // Performing Delete Operation
    final DeleteResult deleteResult = defaultDeleteResolver.performDelete(storIOContentResolver, testItem);
    // checks that required delete was performed
    verify(lowLevel, times(1)).delete(expectedDeleteQuery);
    // only one delete should be performed
    verify(lowLevel, times(1)).delete(any(DeleteQuery.class));
    // delete result checks
    assertThat(deleteResult.numberOfRowsDeleted()).isEqualTo(expectedNumberOfRowsDeleted);
    assertThat(deleteResult.affectedUris()).hasSize(1);
    assertThat(deleteResult.affectedUris()).contains(expectedUri);
}
Also used : NonNull(android.support.annotation.NonNull) DeleteQuery(com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) Uri(android.net.Uri) Test(org.junit.Test)

Example 5 with DeleteResult

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

the class CarRelationsDeleteResolver method performDelete.

@Override
@NonNull
public DeleteResult performDelete(@NonNull StorIOSQLite storIOSQLite, @NonNull Car object) {
    final StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
    lowLevel.beginTransaction();
    try {
        final DeleteResult deleteResult = super.performDelete(storIOSQLite, object);
        storIOSQLite.delete().byQuery(DeleteQuery.builder().table(PersonCarRelationTable.TABLE).where(PersonCarRelationTable.COLUMN_CAR_ID + " = ?").whereArgs(object.id()).build()).prepare().executeAsBlocking();
        lowLevel.setTransactionSuccessful();
        return deleteResult;
    } finally {
        lowLevel.endTransaction();
    }
}
Also used : StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) DeleteResult(com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult) NonNull(android.support.annotation.NonNull)

Aggregations

Test (org.junit.Test)18 DeleteResult (com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult)10 NonNull (android.support.annotation.NonNull)7 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)7 TestSubscriber (io.reactivex.subscribers.TestSubscriber)7 Cursor (android.database.Cursor)6 Changes (com.pushtorefresh.storio3.contentresolver.Changes)6 DeleteQuery (com.pushtorefresh.storio3.sqlite.queries.DeleteQuery)6 DeleteQuery (com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery)5 DeleteResult (com.pushtorefresh.storio3.sqlite.operations.delete.DeleteResult)5 StorIOException (com.pushtorefresh.storio3.StorIOException)3 TestObserver (io.reactivex.observers.TestObserver)2 Uri (android.net.Uri)1 StorIOContentResolver (com.pushtorefresh.storio3.contentresolver.StorIOContentResolver)1 Changes (com.pushtorefresh.storio3.sqlite.Changes)1 PutResult (com.pushtorefresh.storio3.sqlite.operations.put.PutResult)1