Search in sources :

Example 26 with Changes

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

the class PutOperationTest method updateObjectAsSingle.

@Test
public void updateObjectAsSingle() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(2).subscribe(changesTestSubscriber);
    Uri insertedUri = contentResolver.insert(TestItem.CONTENT_URI, TestItem.create(null, "value").toContentValues());
    TestItem testItem = TestItem.create(ContentUris.parseId(insertedUri), "value2");
    PutResult updateResult = storIOContentResolver.put().object(testItem).prepare().asRxSingle().blockingGet();
    assertThat(updateResult.wasUpdated()).isTrue();
    Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(cursor).hasCount(1);
    cursor.moveToFirst();
    assertThat(testItem).isEqualTo(TestItem.fromCursor(cursor));
    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValues(Changes.newInstance(TestItem.CONTENT_URI), Changes.newInstance(TestItem.CONTENT_URI));
}
Also used : Changes(com.pushtorefresh.storio3.contentresolver.Changes) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Cursor(android.database.Cursor) Uri(android.net.Uri) PutResult(com.pushtorefresh.storio3.contentresolver.operations.put.PutResult) Test(org.junit.Test)

Example 27 with Changes

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

the class PutOperationTest method insertContentValuesAsCompletable.

@Test
public void insertContentValuesAsCompletable() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).take(1).subscribe(changesTestSubscriber);
    TestItem testItem = TestItem.create(null, "value");
    ContentValues cv = testItem.toContentValues();
    storIOContentResolver.put().contentValues(cv).withPutResolver(testItemContentValuesPutResolver).prepare().asRxCompletable().blockingAwait(15, SECONDS);
    Cursor cursor = contentResolver.query(TestItem.CONTENT_URI, null, null, null, null);
    Assertions.assertThat(cursor).hasCount(1);
    cursor.moveToFirst();
    assertThat(testItem.equalsWithoutId(TestItem.fromCursor(cursor))).isTrue();
    changesTestSubscriber.awaitTerminalEvent(60, SECONDS);
    changesTestSubscriber.assertNoErrors();
    changesTestSubscriber.assertValue(Changes.newInstance(TestItem.CONTENT_URI));
}
Also used : Changes(com.pushtorefresh.storio3.contentresolver.Changes) ContentValues(android.content.ContentValues) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 28 with Changes

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

the class DeleteOperationTest method deleteByQueryAsCompletable.

@Test
public void deleteByQueryAsCompletable() {
    TestSubscriber<Changes> changesTestSubscriber = new TestSubscriber<Changes>();
    storIOContentResolver.observeChangesOfUri(TestItem.CONTENT_URI, BackpressureStrategy.MISSING).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);
    storIOContentResolver.delete().byQuery(DeleteQuery.builder().uri(TestItem.CONTENT_URI).build()).prepare().asRxCompletable().blockingAwait(15, SECONDS);
    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.storio3.contentresolver.Changes) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 29 with Changes

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

the class DefaultStorIOSQLiteTest method observeChangesInTable.

@Test
public void observeChangesInTable() {
    TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
    storIOSQLite.observeChangesInTable("table1", LATEST).subscribe(testSubscriber);
    testSubscriber.assertNoValues();
    Changes changes1 = Changes.newInstance("table2");
    storIOSQLite.lowLevel().notifyAboutChanges(changes1);
    testSubscriber.assertNoValues();
    Changes changes2 = Changes.newInstance("table1");
    storIOSQLite.lowLevel().notifyAboutChanges(changes2);
    testSubscriber.assertValue(changes2);
    Changes changes3 = Changes.newInstance("table3");
    storIOSQLite.lowLevel().notifyAboutChanges(changes3);
    // Subscriber should not see changes of table2 and table3
    testSubscriber.assertValue(changes2);
    testSubscriber.assertNoErrors();
    testSubscriber.dispose();
}
Also used : Changes(com.pushtorefresh.storio3.sqlite.Changes) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 30 with Changes

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

the class ObserveChangesInTableTest method insertEmission.

@Test
public void insertEmission() {
    final List<User> users = TestFactory.newUsers(10);
    final Queue<Changes> expectedChanges = new LinkedList<Changes>();
    expectedChanges.add(Changes.newInstance(UserTableMeta.TABLE, UserTableMeta.NOTIFICATION_TAG));
    final EmissionChecker emissionChecker = new EmissionChecker(expectedChanges);
    final Disposable disposable = emissionChecker.subscribe();
    putUsersBlocking(users);
    // Should receive changes of Users table
    emissionChecker.awaitNextExpectedValue();
    emissionChecker.assertThatNoExpectedValuesLeft();
    disposable.dispose();
}
Also used : Changes(com.pushtorefresh.storio3.sqlite.Changes) Disposable(io.reactivex.disposables.Disposable) AbstractEmissionChecker(com.pushtorefresh.storio3.test.AbstractEmissionChecker) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)56 TestSubscriber (io.reactivex.subscribers.TestSubscriber)47 Changes (com.pushtorefresh.storio3.contentresolver.Changes)37 Cursor (android.database.Cursor)33 Uri (android.net.Uri)16 Changes (com.pushtorefresh.storio3.sqlite.Changes)16 PutResult (com.pushtorefresh.storio3.contentresolver.operations.put.PutResult)15 Disposable (io.reactivex.disposables.Disposable)11 HashSet (java.util.HashSet)7 DeleteResult (com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult)6 AbstractEmissionChecker (com.pushtorefresh.storio3.test.AbstractEmissionChecker)6 LinkedList (java.util.LinkedList)6 ContentResolver (android.content.ContentResolver)5 ContentObserver (android.database.ContentObserver)5 ArrayList (java.util.ArrayList)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Mockito.doAnswer (org.mockito.Mockito.doAnswer)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Answer (org.mockito.stubbing.Answer)5 ContentValues (android.content.ContentValues)4