Search in sources :

Example 26 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver in project storio by pushtorefresh.

the class DefaultStorIOContentResolverTest method defaultRxSchedulerReturnsSpecifiedScheduler.

@Test
public void defaultRxSchedulerReturnsSpecifiedScheduler() {
    Scheduler scheduler = mock(Scheduler.class);
    StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(mock(ContentResolver.class)).defaultRxScheduler(scheduler).build();
    assertThat(storIOContentResolver.defaultRxScheduler()).isSameAs(scheduler);
}
Also used : Scheduler(io.reactivex.Scheduler) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Example 27 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver in project storio by pushtorefresh.

the class DeleteOperationDesignTest method deleteByQueryFlowable.

@Test
public void deleteByQueryFlowable() {
    final DeleteQuery deleteQuery = DeleteQuery.builder().uri(mock(Uri.class)).where("some_field = ?").whereArgs("someValue").build();
    Flowable<DeleteResult> deleteResultFlowable = storIOContentResolver().delete().byQuery(deleteQuery).prepare().asRxFlowable(BackpressureStrategy.MISSING);
}
Also used : DeleteQuery(com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery) DeleteResult(com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult) Test(org.junit.Test)

Example 28 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver 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.storio3.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 29 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver in project storio by pushtorefresh.

the class PutOperationDesignTest method putContentValuesBlocking.

@Test
public void putContentValuesBlocking() {
    ContentValues contentValues = mock(ContentValues.class);
    PutResult putResult = storIOContentResolver().put().contentValues(contentValues).withPutResolver(putResolverForContentValues).prepare().executeAsBlocking();
}
Also used : ContentValues(android.content.ContentValues) PutResult(com.pushtorefresh.storio3.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 30 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver in project storio by pushtorefresh.

the class DefaultPutResolver method performPut.

/**
 * {@inheritDoc}
 */
@NonNull
@Override
public PutResult performPut(@NonNull StorIOContentResolver storIOContentResolver, @NonNull T object) {
    final UpdateQuery updateQuery = mapToUpdateQuery(object);
    final Query query = Query.builder().uri(updateQuery.uri()).where(nullableString(updateQuery.where())).whereArgs((Object[]) nullableArrayOfStringsFromListOfStrings(updateQuery.whereArgs())).build();
    final StorIOContentResolver.LowLevel lowLevel = storIOContentResolver.lowLevel();
    final Cursor cursor = lowLevel.query(query);
    try {
        final ContentValues contentValues = mapToContentValues(object);
        if (cursor.getCount() == 0) {
            final InsertQuery insertQuery = mapToInsertQuery(object);
            final Uri insertedUri = lowLevel.insert(insertQuery, contentValues);
            return PutResult.newInsertResult(insertedUri, insertQuery.uri());
        } else {
            final int numberOfRowsUpdated = lowLevel.update(updateQuery, contentValues);
            return PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.uri());
        }
    } finally {
        cursor.close();
    }
}
Also used : ContentValues(android.content.ContentValues) InsertQuery(com.pushtorefresh.storio3.contentresolver.queries.InsertQuery) InsertQuery(com.pushtorefresh.storio3.contentresolver.queries.InsertQuery) Query(com.pushtorefresh.storio3.contentresolver.queries.Query) UpdateQuery(com.pushtorefresh.storio3.contentresolver.queries.UpdateQuery) UpdateQuery(com.pushtorefresh.storio3.contentresolver.queries.UpdateQuery) Cursor(android.database.Cursor) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull)

Aggregations

Test (org.junit.Test)31 StorIOContentResolver (com.pushtorefresh.storio3.contentresolver.StorIOContentResolver)23 Query (com.pushtorefresh.storio3.contentresolver.queries.Query)11 ContentResolver (android.content.ContentResolver)9 NonNull (android.support.annotation.NonNull)9 ContentValues (android.content.ContentValues)8 Cursor (android.database.Cursor)7 Uri (android.net.Uri)7 DeleteQuery (com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery)6 TypeMappingFinder (com.pushtorefresh.storio3.TypeMappingFinder)5 InsertQuery (com.pushtorefresh.storio3.contentresolver.queries.InsertQuery)5 UpdateQuery (com.pushtorefresh.storio3.contentresolver.queries.UpdateQuery)5 DeleteResult (com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult)4 PutResult (com.pushtorefresh.storio3.contentresolver.operations.put.PutResult)4 StorIOException (com.pushtorefresh.storio3.StorIOException)3 GetResolver (com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver)3 Handler (android.os.Handler)2 TypeMappingFinderImpl (com.pushtorefresh.storio3.internal.TypeMappingFinderImpl)2 Completable (io.reactivex.Completable)2 ContentObserver (android.database.ContentObserver)1