Search in sources :

Example 6 with HttpStore

use of org.activityinfo.ui.client.store.http.HttpStore in project activityinfo by bedatadriven.

the class OfflineStoreGwtTest method testStoreForm.

public void testStoreForm() {
    survey = new Survey();
    FormMetadata surveyMetadata = FormMetadata.of(1L, survey.getFormClass(), FormPermissions.readWrite());
    // First put the schema to the store
    Snapshot snapshot = new Snapshot(Collections.singletonList(surveyMetadata), Collections.singletonList(toFormRecordSet(survey)));
    offlineStore = new OfflineStore(httpStore, IDBFactoryImpl.create());
    httpStore = new HttpStore(new OfflineClientStub());
    formStore = new FormStoreImpl(httpStore, offlineStore, Scheduler.get());
    offlineStore.store(snapshot).then(new AsyncCallback<Void>() {

        @Override
        public void onFailure(Throwable caught) {
            fail();
        }

        @Override
        public void onSuccess(Void result) {
            // Once the store is complete,
            // verify that the Form Schema can be read...
            verifyWeCanReadFormSchemas().join(OfflineStoreGwtTest.this::verifyWeCanQueryRecords).join(OfflineStoreGwtTest.this::verifyWeCanMakeChangesOffline).join(OfflineStoreGwtTest.this::verifyWeCanLoadCurrentSnapshot).join(OfflineStoreGwtTest.this::verifyWeCanQuery).then(new AsyncCallback<Void>() {

                @Override
                public void onFailure(Throwable caught) {
                    LOGGER.log(Level.SEVERE, "Operation failed", caught);
                    fail();
                }

                @Override
                public void onSuccess(Void result) {
                    finishTest();
                }
            });
        }
    });
    delayTestFinish(5000);
}
Also used : FormStoreImpl(org.activityinfo.ui.client.store.FormStoreImpl) Survey(org.activityinfo.store.testing.Survey) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) HttpStore(org.activityinfo.ui.client.store.http.HttpStore)

Example 7 with HttpStore

use of org.activityinfo.ui.client.store.http.HttpStore 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

HttpStore (org.activityinfo.ui.client.store.http.HttpStore)7 Test (org.junit.Test)5 IDBFactoryStub (org.activityinfo.indexedb.IDBFactoryStub)4 FormTree (org.activityinfo.model.formTree.FormTree)3 FormStoreImpl (org.activityinfo.ui.client.store.FormStoreImpl)2 ActivityManager (com.google.gwt.activity.shared.ActivityManager)1 ActivityMapper (com.google.gwt.activity.shared.ActivityMapper)1 PlaceController (com.google.gwt.place.shared.PlaceController)1 PlaceHistoryHandler (com.google.gwt.place.shared.PlaceHistoryHandler)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 SimpleEventBus (com.google.web.bindery.event.shared.SimpleEventBus)1 Viewport (com.sencha.gxt.widget.core.client.container.Viewport)1 ActivityInfoClientAsync (org.activityinfo.api.client.ActivityInfoClientAsync)1 ActivityInfoClientAsyncImpl (org.activityinfo.api.client.ActivityInfoClientAsyncImpl)1 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 LocalStorage (org.activityinfo.storage.LocalStorage)1