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()));
}
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();
}
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());
}
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));
}
Aggregations