Search in sources :

Example 1 with FormMetadataProvider

use of org.activityinfo.model.formTree.FormMetadataProvider in project activityinfo by bedatadriven.

the class FormInputViewModelTest method hiddenSubForm.

/**
 * Test the ViewModel for when the user does not have access to a referenced sub form.
 */
@Test
public void hiddenSubForm() {
    FormClass parentForm = new FormClass(ResourceId.valueOf("PARENT_FORM"));
    parentForm.addField(ResourceId.valueOf("F1")).setLabel("What is your name?").setType(TextType.SIMPLE);
    parentForm.addField(ResourceId.valueOf("F2")).setLabel("What are your secrets?").setType(new SubFormReferenceType(ResourceId.valueOf("SECRET_FORM")));
    FormTreeBuilder treeBuilder = new FormTreeBuilder(new FormMetadataProvider() {

        @Override
        public FormMetadata getFormMetadata(ResourceId formId) {
            if (formId.equals(parentForm.getId())) {
                return FormMetadata.of(1, parentForm, FormPermissions.owner());
            } else {
                return FormMetadata.forbidden(formId);
            }
        }
    });
    FormTree formTree = treeBuilder.queryTree(parentForm.getId());
    FormStore formStore = EasyMock.createMock(FormStore.class);
    EasyMock.replay(formStore);
    FormInputViewModelBuilder viewModelBuilder = new FormInputViewModelBuilder(formStore, formTree, new TestingActivePeriodMemory());
    FormInputViewModel viewModel = viewModelBuilder.build(new FormInputModel(new RecordRef(parentForm.getId(), ResourceId.valueOf("R1"))));
}
Also used : FormMetadataProvider(org.activityinfo.model.formTree.FormMetadataProvider) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) FormMetadata(org.activityinfo.model.form.FormMetadata) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) FormStore(org.activityinfo.ui.client.store.FormStore) Test(org.junit.Test)

Aggregations

FormClass (org.activityinfo.model.form.FormClass)1 FormMetadata (org.activityinfo.model.form.FormMetadata)1 FormMetadataProvider (org.activityinfo.model.formTree.FormMetadataProvider)1 FormTree (org.activityinfo.model.formTree.FormTree)1 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 RecordRef (org.activityinfo.model.type.RecordRef)1 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)1 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)1 FormStore (org.activityinfo.ui.client.store.FormStore)1 TestingFormStore (org.activityinfo.ui.client.store.TestingFormStore)1 Test (org.junit.Test)1