Search in sources :

Example 46 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class PreparedPutContentValuesIterableTest method verifyBehaviorInCaseOfExceptionWithoutTransactionSingle.

@Test
public void verifyBehaviorInCaseOfExceptionWithoutTransactionSingle() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
    // noinspection unchecked
    final PutResolver<ContentValues> putResolver = mock(PutResolver.class);
    final List<ContentValues> contentValues = singletonList(mock(ContentValues.class));
    when(putResolver.performPut(same(storIOSQLite), any(ContentValues.class))).thenThrow(new IllegalStateException("test exception"));
    final TestObserver<PutResults<ContentValues>> testObserver = new TestObserver<PutResults<ContentValues>>();
    new PreparedPutContentValuesIterable.Builder(storIOSQLite, contentValues).withPutResolver(putResolver).useTransaction(false).prepare().asRxSingle().subscribe(testObserver);
    testObserver.awaitTerminalEvent();
    testObserver.assertNoValues();
    testObserver.assertError(StorIOException.class);
    // noinspection ThrowableResultOfMethodCallIgnored
    StorIOException expected = (StorIOException) testObserver.errors().get(0);
    IllegalStateException cause = (IllegalStateException) expected.getCause();
    assertThat(cause).hasMessage("test exception");
    // Main check of this test
    verify(lowLevel, never()).endTransaction();
    verify(storIOSQLite).lowLevel();
    verify(storIOSQLite).defaultRxScheduler();
    verify(storIOSQLite).interceptors();
    verify(putResolver).performPut(same(storIOSQLite), any(ContentValues.class));
    verifyNoMoreInteractions(storIOSQLite, lowLevel, putResolver);
}
Also used : ContentValues(android.content.ContentValues) StorIOException(com.pushtorefresh.storio3.StorIOException) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 47 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class PreparedPutContentValuesIterableTest method shouldFinishTransactionIfExceptionHasOccurredFlowable.

@Test
public void shouldFinishTransactionIfExceptionHasOccurredFlowable() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
    when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
    // noinspection unchecked
    final PutResolver<ContentValues> putResolver = mock(PutResolver.class);
    final List<ContentValues> contentValues = singletonList(mock(ContentValues.class));
    when(putResolver.performPut(same(storIOSQLite), any(ContentValues.class))).thenThrow(new IllegalStateException("test exception"));
    final TestSubscriber<PutResults<ContentValues>> testSubscriber = new TestSubscriber<PutResults<ContentValues>>();
    new PreparedPutContentValuesIterable.Builder(storIOSQLite, contentValues).withPutResolver(putResolver).useTransaction(true).prepare().asRxFlowable(MISSING).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertNoValues();
    testSubscriber.assertError(StorIOException.class);
    // noinspection ThrowableResultOfMethodCallIgnored
    StorIOException expected = (StorIOException) testSubscriber.errors().get(0);
    IllegalStateException cause = (IllegalStateException) expected.getCause();
    assertThat(cause).hasMessage("test exception");
    verify(lowLevel).beginTransaction();
    verify(lowLevel, never()).setTransactionSuccessful();
    verify(lowLevel).endTransaction();
    verify(storIOSQLite).lowLevel();
    verify(storIOSQLite).defaultRxScheduler();
    verify(storIOSQLite).interceptors();
    verify(putResolver).performPut(same(storIOSQLite), any(ContentValues.class));
    verifyNoMoreInteractions(storIOSQLite, lowLevel, putResolver);
}
Also used : ContentValues(android.content.ContentValues) StorIOException(com.pushtorefresh.storio3.StorIOException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 48 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class PreparedGetCursorTest method shouldWrapExceptionIntoStorIOExceptionForSingle.

@Test
public void shouldWrapExceptionIntoStorIOExceptionForSingle() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    // noinspection unchecked
    final GetResolver<Cursor> getResolver = mock(GetResolver.class);
    when(getResolver.performGet(eq(storIOSQLite), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
    final TestObserver<Cursor> testObserver = new TestObserver<Cursor>();
    new PreparedGetCursor.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").build()).withGetResolver(getResolver).prepare().asRxSingle().subscribe(testObserver);
    testObserver.awaitTerminalEvent(60, SECONDS);
    testObserver.assertError(StorIOException.class);
    StorIOException storIOException = (StorIOException) testObserver.errors().get(0);
    IllegalStateException cause = (IllegalStateException) storIOException.getCause();
    assertThat(cause).hasMessage("test exception");
}
Also used : Query(com.pushtorefresh.storio3.sqlite.queries.Query) StorIOException(com.pushtorefresh.storio3.StorIOException) Cursor(android.database.Cursor) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 49 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class RxJavaUtilsTest method createGetFlowableOptionalCompletedAfterInitialEmissionIfNoTablesAndTags.

@Test
public void createGetFlowableOptionalCompletedAfterInitialEmissionIfNoTablesAndTags() {
    RawQuery queryWithoutTablesAnTags = RawQuery.builder().query("select * from " + UserTableMeta.TABLE + " where " + UserTableMeta.COLUMN_ID + "=?").args(1).build();
    PreparedGetObject<User> preparedGet = storIOSQLite.get().object(User.class).withQuery(queryWithoutTablesAnTags).prepare();
    TestSubscriber<Optional<User>> subscriber = new TestSubscriber<Optional<User>>();
    RxJavaUtils.createGetFlowableOptional(storIOSQLite, preparedGet, null, queryWithoutTablesAnTags, BackpressureStrategy.LATEST).subscribe(subscriber);
    subscriber.assertNoErrors();
    subscriber.assertValues(Optional.<User>empty());
    subscriber.assertComplete();
}
Also used : User(com.pushtorefresh.storio3.sqlite.integration.User) Optional(com.pushtorefresh.storio3.Optional) RawQuery(com.pushtorefresh.storio3.sqlite.queries.RawQuery) TestSubscriber(io.reactivex.subscribers.TestSubscriber) BaseTest(com.pushtorefresh.storio3.sqlite.integration.BaseTest) Test(org.junit.Test)

Example 50 with StorIOSQLite

use of com.pushtorefresh.storio3.sqlite.StorIOSQLite in project storio by pushtorefresh.

the class RxJavaUtilsTest method createGetFlowableCompletedAfterInitialEmissionIfNoTablesAndTags.

@Test
public void createGetFlowableCompletedAfterInitialEmissionIfNoTablesAndTags() {
    RawQuery queryWithoutTablesAnTags = RawQuery.builder().query("select * from " + UserTableMeta.TABLE).build();
    PreparedGetListOfObjects<User> preparedGet = storIOSQLite.get().listOfObjects(User.class).withQuery(queryWithoutTablesAnTags).prepare();
    TestSubscriber<List<User>> subscriber = new TestSubscriber<List<User>>();
    RxJavaUtils.createGetFlowable(storIOSQLite, preparedGet, null, queryWithoutTablesAnTags, BackpressureStrategy.LATEST).subscribe(subscriber);
    subscriber.assertNoErrors();
    subscriber.assertValues(EMPTY_LIST);
    subscriber.assertComplete();
}
Also used : User(com.pushtorefresh.storio3.sqlite.integration.User) RawQuery(com.pushtorefresh.storio3.sqlite.queries.RawQuery) TestSubscriber(io.reactivex.subscribers.TestSubscriber) List(java.util.List) BaseTest(com.pushtorefresh.storio3.sqlite.integration.BaseTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)32 NonNull (android.support.annotation.NonNull)18 StorIOException (com.pushtorefresh.storio3.StorIOException)18 ContentValues (android.content.ContentValues)13 Query (com.pushtorefresh.storio3.sqlite.queries.Query)9 Cursor (android.database.Cursor)8 TestObserver (io.reactivex.observers.TestObserver)8 DeleteQuery (com.pushtorefresh.storio3.sqlite.queries.DeleteQuery)7 TestSubscriber (io.reactivex.subscribers.TestSubscriber)7 TypeMappingFinder (com.pushtorefresh.storio3.TypeMappingFinder)4 Car (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Car)4 InsertQuery (com.pushtorefresh.storio3.sqlite.queries.InsertQuery)4 RawQuery (com.pushtorefresh.storio3.sqlite.queries.RawQuery)4 Tweet (com.pushtorefresh.storio3.sample.db.entities.Tweet)3 TweetWithUser (com.pushtorefresh.storio3.sample.db.entities.TweetWithUser)3 Person (com.pushtorefresh.storio3.sample.many_to_many_sample.entities.Person)3 PutResult (com.pushtorefresh.storio3.sqlite.operations.put.PutResult)3 User (com.pushtorefresh.storio3.sample.db.entities.User)2 BaseTest (com.pushtorefresh.storio3.sqlite.integration.BaseTest)2