Search in sources :

Example 1 with RawQuery

use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.

the class DefaultGetResolverTest method rawQuery.

@Test
public void rawQuery() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
    final RawQuery rawQuery = RawQuery.builder().query("test sql").build();
    final Cursor expectedCursor = mock(Cursor.class);
    when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
    when(lowLevel.rawQuery(rawQuery)).thenReturn(expectedCursor);
    final DefaultGetResolver<TestItem> defaultGetResolver = new DefaultGetResolver<TestItem>() {

        @NonNull
        @Override
        public TestItem mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
            return mock(TestItem.class);
        }
    };
    final Cursor actualCursor = defaultGetResolver.performGet(storIOSQLite, rawQuery);
    // only one request should occur
    verify(lowLevel, times(1)).rawQuery(any(RawQuery.class));
    // and this request should be equals to original
    verify(lowLevel, times(1)).rawQuery(rawQuery);
    assertThat(actualCursor).isSameAs(expectedCursor);
}
Also used : NonNull(android.support.annotation.NonNull) RawQuery(com.pushtorefresh.storio3.sqlite.queries.RawQuery) Cursor(android.database.Cursor) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 2 with RawQuery

use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.

the class GetNumberOfResultsObserveChangesTest method repeatsOperationWithRawQueryByChangeOfTag.

@Test
public void repeatsOperationWithRawQueryByChangeOfTag() {
    putUserBlocking();
    PreparedGetNumberOfResults operation = storIOSQLite.get().numberOfResults().withQuery(rawQuery).prepare();
    verifyChangesReceived(operation, tagChanges, 1);
}
Also used : PreparedGetNumberOfResults(com.pushtorefresh.storio3.sqlite.operations.get.PreparedGetNumberOfResults) Test(org.junit.Test)

Example 3 with RawQuery

use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.

the class DefaultStorIOSQLiteTest method shouldPassSQLWithArgsToExecSQL.

@Test
public void shouldPassSQLWithArgsToExecSQL() {
    RawQuery rawQuery = RawQuery.builder().query("DROP TABLE users").args("arg1", "arg2").build();
    storIOSQLite.lowLevel().executeSQL(rawQuery);
    verify(sqLiteOpenHelper).getWritableDatabase();
    verify(sqLiteDatabase).execSQL(eq(rawQuery.query()), eq(new String[] { "arg1", "arg2" }));
    verifyNoMoreInteractions(sqLiteOpenHelper, sqLiteDatabase);
}
Also used : RawQuery(com.pushtorefresh.storio3.sqlite.queries.RawQuery) Test(org.junit.Test)

Example 4 with RawQuery

use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.

the class GetNumberOfResultsObserveChangesTest method repeatsOperationWithRawQueryByChangeOfTable.

@Test
public void repeatsOperationWithRawQueryByChangeOfTable() {
    putUserBlocking();
    PreparedGetNumberOfResults operation = storIOSQLite.get().numberOfResults().withQuery(rawQuery).prepare();
    verifyChangesReceived(operation, tableChanges, 1);
}
Also used : PreparedGetNumberOfResults(com.pushtorefresh.storio3.sqlite.operations.get.PreparedGetNumberOfResults) Test(org.junit.Test)

Example 5 with RawQuery

use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.

the class ExecSQLTest method shouldReturnQueryInGetData.

@Test
public void shouldReturnQueryInGetData() {
    final RawQuery query = RawQuery.builder().query(// we don't want to really delete table
    "DROP TABLE IF EXISTS no_such_table").build();
    final PreparedExecuteSQL operation = storIOSQLite.executeSQL().withQuery(query).prepare();
    assertThat(operation.getData()).isEqualTo(query);
}
Also used : RawQuery(com.pushtorefresh.storio3.sqlite.queries.RawQuery) PreparedExecuteSQL(com.pushtorefresh.storio3.sqlite.operations.execute.PreparedExecuteSQL) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 RawQuery (com.pushtorefresh.storio3.sqlite.queries.RawQuery)6 BaseTest (com.pushtorefresh.storio3.sqlite.integration.BaseTest)2 User (com.pushtorefresh.storio3.sqlite.integration.User)2 PreparedGetNumberOfResults (com.pushtorefresh.storio3.sqlite.operations.get.PreparedGetNumberOfResults)2 TestSubscriber (io.reactivex.subscribers.TestSubscriber)2 Cursor (android.database.Cursor)1 NonNull (android.support.annotation.NonNull)1 Optional (com.pushtorefresh.storio3.Optional)1 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)1 PreparedExecuteSQL (com.pushtorefresh.storio3.sqlite.operations.execute.PreparedExecuteSQL)1 List (java.util.List)1