Search in sources :

Example 1 with FormDefinitionSettings

use of org.kie.workbench.common.forms.adf.service.definitions.FormDefinitionSettings in project kie-wb-common by kiegroup.

the class AbstractFormGenerationTest method testGeneratedForm.

protected void testGeneratedForm(FormDefinition form, String modelName) {
    assertNotNull(form);
    FormDefinitionSettings settings = resourcesProvider.getDefinitionSettings().get(modelName);
    assertEquals(settings.getModelType(), form.getId());
    assertEquals(settings.getModelType(), form.getName());
    assertEquals(settings.getFormElements().size(), form.getFields().size());
    settings.getFormElements().forEach(element -> {
        FieldElement fieldElement = (FieldElement) element;
        FieldDefinition field = form.getFieldByBinding(fieldElement.getBinding());
        assertNotNull(field);
        assertEquals(fieldElement.getName(), field.getName());
        if (!fieldElement.getPreferredType().equals(FieldType.class)) {
            assertEquals(fieldElement.getPreferredType(), field.getFieldType().getClass());
        }
        assertEquals(fieldElement.getTypeInfo().getClassName(), field.getStandaloneClassName());
        assertEquals(fieldElement.isReadOnly(), field.getReadOnly());
        assertEquals(fieldElement.isRequired(), field.getRequired());
        assertEquals(fieldElement.getBinding(), field.getBinding());
        verify(i18nHelper, atLeast(1)).getTranslation(field.getName() + ".label");
    });
    assertNotNull(form.getLayoutTemplate());
    assertEquals(settings.getFormElements().size(), form.getLayoutTemplate().getRows().size());
    form.getLayoutTemplate().getRows().forEach(row -> {
        assertNotNull(row);
        assertEquals(1, row.getLayoutColumns().size());
        LayoutColumn column = row.getLayoutColumns().get(0);
        assertNotNull(column);
        assertEquals("12", column.getSpan());
        assertEquals(1, column.getLayoutComponents().size());
        LayoutComponent layoutComponent = column.getLayoutComponents().get(0);
        String formId = layoutComponent.getProperties().get(FormLayoutComponent.FORM_ID);
        assertNotNull(formId);
        assertEquals(form.getId(), formId);
        String fieldId = layoutComponent.getProperties().get(FormLayoutComponent.FIELD_ID);
        assertNotNull(fieldId);
        FieldDefinition field = form.getFieldById(fieldId);
        assertNotNull(field);
    });
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) LayoutColumn(org.uberfire.ext.layout.editor.api.editor.LayoutColumn) FieldElement(org.kie.workbench.common.forms.adf.service.definitions.elements.FieldElement) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) FormDefinitionSettings(org.kie.workbench.common.forms.adf.service.definitions.FormDefinitionSettings) FieldType(org.kie.workbench.common.forms.model.FieldType)

Aggregations

FormDefinitionSettings (org.kie.workbench.common.forms.adf.service.definitions.FormDefinitionSettings)1 FieldElement (org.kie.workbench.common.forms.adf.service.definitions.elements.FieldElement)1 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)1 FieldType (org.kie.workbench.common.forms.model.FieldType)1 FormLayoutComponent (org.kie.workbench.common.forms.model.FormLayoutComponent)1 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)1 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)1