Search in sources :

Example 1 with Survey

use of org.activityinfo.store.testing.Survey in project activityinfo by bedatadriven.

the class SurveyTest method setupForm.

@Before
public void setupForm() {
    TestDatabase database = harness.createDatabase();
    client = harness.client();
    survey = new Survey(new SiteIds(database));
    client.createForm(survey.getFormClass());
}
Also used : Survey(org.activityinfo.store.testing.Survey) Before(org.junit.Before)

Example 2 with Survey

use of org.activityinfo.store.testing.Survey 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 3 with Survey

use of org.activityinfo.store.testing.Survey in project activityinfo by bedatadriven.

the class FormulaValidatorTest method validate.

private FormulaValidator validate(String formula) {
    Survey surveyForm = catalog.getSurvey();
    FormulaValidator validator = new FormulaValidator(catalog.getFormTree(surveyForm.getFormId()));
    validator.validate(FormulaParser.parse(formula));
    for (FormulaError error : validator.getErrors()) {
        System.out.println("Error at " + error.getSourceRange() + ": " + error.getMessage());
    }
    return validator;
}
Also used : Survey(org.activityinfo.store.testing.Survey) FormulaValidator(org.activityinfo.analysis.FormulaValidator) FormulaError(org.activityinfo.model.formula.FormulaError)

Example 4 with Survey

use of org.activityinfo.store.testing.Survey in project activityinfo by bedatadriven.

the class RecordTreeLoaderTest method simpleSurvey.

@Test
public void simpleSurvey() {
    Survey survey = setup.getSurveyForm();
    Observable<Maybe<RecordTree>> recordTree = setup.getFormStore().getRecordTree(survey.getRecordRef(0));
    Connection<Maybe<RecordTree>> recordTreeView = setup.connect(recordTree);
    RecordTree tree = recordTreeView.assertLoaded().get();
    assertThat(tree.getRoot().get(survey.getNameFieldId()), equalTo(TextValue.valueOf("Melanie")));
}
Also used : RecordTree(org.activityinfo.model.formTree.RecordTree) Survey(org.activityinfo.store.testing.Survey) Maybe(org.activityinfo.promise.Maybe) Test(org.junit.Test)

Aggregations

Survey (org.activityinfo.store.testing.Survey)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 FormulaValidator (org.activityinfo.analysis.FormulaValidator)1 RecordTree (org.activityinfo.model.formTree.RecordTree)1 FormulaError (org.activityinfo.model.formula.FormulaError)1 Maybe (org.activityinfo.promise.Maybe)1 FormStoreImpl (org.activityinfo.ui.client.store.FormStoreImpl)1 HttpStore (org.activityinfo.ui.client.store.http.HttpStore)1 Before (org.junit.Before)1 Test (org.junit.Test)1