Search in sources :

Example 1 with IDBFactoryStub

use of org.activityinfo.indexedb.IDBFactoryStub in project activityinfo by bedatadriven.

the class FormStoreTest method relatedFormsAreAlsoCached.

@Test
public void relatedFormsAreAlsoCached() {
    AsyncClientStub client = new AsyncClientStub();
    IntakeForm intakeForm = client.getStorageProvider().getIntakeForm();
    HttpStore httpStore = new HttpStore(client, scheduler);
    OfflineStore offlineStore = new OfflineStore(httpStore, new IDBFactoryStub());
    FormStoreImpl formStore = new FormStoreImpl(httpStore, offlineStore, scheduler);
    // Start online, and enable offline mode for incidents
    formStore.setFormOffline(IncidentForm.FORM_ID, true);
    // Now synchronize...
    RecordSynchronizer synchronizer = new RecordSynchronizer(httpStore, offlineStore);
    runScheduled();
    // Ensure that related forms and subforms are also synchronized
    SnapshotStatus snapshot = connect(offlineStore.getCurrentSnapshot()).assertLoaded();
    assertTrue("incident form is cached", snapshot.isFormCached(IncidentForm.FORM_ID));
    assertTrue("sub form is cached", snapshot.isFormCached(ReferralSubForm.FORM_ID));
    assertTrue("related form is cached", snapshot.isFormCached(intakeForm.getFormId()));
}
Also used : IDBFactoryStub(org.activityinfo.indexedb.IDBFactoryStub) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) Test(org.junit.Test)

Example 2 with IDBFactoryStub

use of org.activityinfo.indexedb.IDBFactoryStub in project activityinfo by bedatadriven.

the class FormStoreTest method formSchemaFetchesAreRetried.

/**
 * If at first the remote fetch does not succeed because
 * of network problems, we should keep retrying.
 */
@Test
public void formSchemaFetchesAreRetried() {
    AsyncClientStub client = new AsyncClientStub();
    HttpStore httpStore = new HttpStore(client, scheduler);
    OfflineStore offlineStore = new OfflineStore(httpStore, new IDBFactoryStub());
    Survey survey = client.getStorageProvider().getSurvey();
    // We start offline
    client.setConnected(false);
    // Now the view connects and should remain in loading state...
    FormStoreImpl formStore = new FormStoreImpl(httpStore, offlineStore, scheduler);
    Connection<FormTree> view = connect(formStore.getFormTree(survey.getFormId()));
    view.assertLoading();
    // Start retries, but we're still offline
    scheduler.executeCommands();
    view.assertLoading();
    // Now connect and retry
    client.setConnected(true);
    scheduler.executeCommands();
    // View should be loaded
    view.assertLoaded();
}
Also used : IDBFactoryStub(org.activityinfo.indexedb.IDBFactoryStub) FormTree(org.activityinfo.model.formTree.FormTree) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) Test(org.junit.Test)

Example 3 with IDBFactoryStub

use of org.activityinfo.indexedb.IDBFactoryStub in project activityinfo by bedatadriven.

the class FormStoreTest method offlineRecordFetching.

@Test
public void offlineRecordFetching() {
    AsyncClientStub client = new AsyncClientStub();
    HttpStore httpStore = new HttpStore(client, scheduler);
    OfflineStore offlineStore = new OfflineStore(httpStore, new IDBFactoryStub());
    FormStoreImpl formStore = new FormStoreImpl(httpStore, offlineStore, scheduler);
    Survey survey = client.getStorageProvider().getSurvey();
    // Start online
    Connection<FormOfflineStatus> offlineStatusView = connect(formStore.getOfflineStatus(survey.getFormId()));
    // Initially form should not be loaded
    assertFalse(offlineStatusView.assertLoaded().isEnabled());
    // and mark the survey form for offline usage
    offlineStore.enableOffline(survey.getFormId(), true);
    assertTrue(offlineStatusView.assertLoaded().isEnabled());
    assertFalse(offlineStatusView.assertLoaded().isCached());
    // Now synchronize...
    RecordSynchronizer synchronizer = new RecordSynchronizer(httpStore, offlineStore);
    runScheduled();
    // We go offline...
    client.setConnected(false);
    // Should be able to view the form class and a record
    Connection<FormTree> schemaView = connect(formStore.getFormTree(survey.getFormId()));
    Connection<Maybe<FormRecord>> recordView = connect(formStore.getRecord(survey.getRecordRef(0)));
    runScheduled();
    schemaView.assertLoaded();
    recordView.assertLoaded();
    assertTrue(offlineStatusView.assertLoaded().isEnabled());
    assertTrue(offlineStatusView.assertLoaded().isCached());
}
Also used : Maybe(org.activityinfo.promise.Maybe) IDBFactoryStub(org.activityinfo.indexedb.IDBFactoryStub) FormTree(org.activityinfo.model.formTree.FormTree) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) Test(org.junit.Test)

Example 4 with IDBFactoryStub

use of org.activityinfo.indexedb.IDBFactoryStub in project activityinfo by bedatadriven.

the class FormStoreTest method newRecordHitsQuery.

@Test
public void newRecordHitsQuery() {
    TestingStorageProvider catalog = new TestingStorageProvider();
    Survey survey = catalog.getSurvey();
    AsyncClientStub client = new AsyncClientStub(catalog);
    HttpStore httpStore = new HttpStore(client, scheduler);
    OfflineStore offlineStore = new OfflineStore(httpStore, new IDBFactoryStub());
    FormStoreImpl formStore = new FormStoreImpl(httpStore, offlineStore, scheduler);
    // Open a query on a set of records
    QueryModel queryModel = new QueryModel(survey.getFormId());
    queryModel.selectResourceId().as("id");
    Connection<ColumnSet> tableView = connect(formStore.query(queryModel));
    tableView.assertLoaded();
    // Add an new record to Survey
    tableView.resetChangeCounter();
    formStore.updateRecords(new RecordTransactionBuilder().add(catalog.addNew(survey.getFormId())).build());
    // Verify that the table view has been updated
    tableView.assertLoaded();
    tableView.assertChanged();
    assertThat(tableView.assertLoaded().getNumRows(), equalTo(survey.getRowCount() + 1));
}
Also used : IDBFactoryStub(org.activityinfo.indexedb.IDBFactoryStub) RecordTransactionBuilder(org.activityinfo.model.resource.RecordTransactionBuilder) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Aggregations

IDBFactoryStub (org.activityinfo.indexedb.IDBFactoryStub)4 HttpStore (org.activityinfo.ui.client.store.http.HttpStore)4 Test (org.junit.Test)4 FormTree (org.activityinfo.model.formTree.FormTree)2 ColumnSet (org.activityinfo.model.query.ColumnSet)1 QueryModel (org.activityinfo.model.query.QueryModel)1 RecordTransactionBuilder (org.activityinfo.model.resource.RecordTransactionBuilder)1 Maybe (org.activityinfo.promise.Maybe)1