Search in sources :

Example 46 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormEditorPresenterTest method testFieldProperties.

protected void testFieldProperties(String fieldId, boolean bound) {
    FormDefinition form = editorHelper.getFormDefinition();
    addField(editorHelper.getAvailableFields().values().stream().filter(fieldDefinition -> fieldDefinition.getBinding().equals(fieldId)).findFirst().get());
    checkExpectedFields(editorHelper.getAvailableFields().size(), 1, bound);
    FieldDefinition field = editorHelper.getFormDefinition().getFields().get(0);
    checkFieldType(field, TextBoxFieldDefinition.class);
    Collection<String> compatibleTypes = editorHelper.getCompatibleFieldTypes(field);
    assertNotNull("No compatibles types found!", compatibleTypes);
    assertTrue("There should exist more than one compatible types for TextBoxFieldDefinition!", compatibleTypes.size() > 1);
    assertTrue("Missing TextAreaFieldDefinition as a compatible type for TextBoxFieldDefinition", compatibleTypes.contains(TextAreaFieldDefinition.FIELD_TYPE.getTypeName()));
    field = editorHelper.switchToFieldType(field, TextAreaFieldDefinition.FIELD_TYPE.getTypeName());
    checkFieldType(field, TextAreaFieldDefinition.class);
    List<String> compatibleFields = editorHelper.getCompatibleModelFields(field);
    assertNotNull("No compatibles fields found!", compatibleFields);
    assertEquals("There should exist 1 compatible fields for " + field.getName() + "!", 1, compatibleFields.size());
    String expectedBindingExpression = "lastName";
    field = editorHelper.switchToField(field, expectedBindingExpression);
    assertEquals("Wrong binding expression after switch field!", field.getBinding(), expectedBindingExpression);
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) FormEditorSyncPaletteEvent(org.kie.workbench.common.forms.editor.client.editor.events.FormEditorSyncPaletteEvent) FormEditorConstants(org.kie.workbench.common.forms.editor.client.resources.i18n.FormEditorConstants) FileNameAndCommitMessage(org.uberfire.ext.editor.commons.client.file.FileNameAndCommitMessage) RunWith(org.junit.runner.RunWith) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) MenuItem(org.uberfire.workbench.model.menu.MenuItem) Matchers.eq(org.mockito.Matchers.eq) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) Matchers.anyInt(org.mockito.Matchers.anyInt) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) ComponentRemovedEvent(org.uberfire.ext.layout.editor.client.api.ComponentRemovedEvent) Mockito.anyString(org.mockito.Mockito.anyString) Mockito.doReturn(org.mockito.Mockito.doReturn) Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) FieldLayoutComponent(org.kie.workbench.common.forms.dynamic.client.rendering.FieldLayoutComponent) RenamePopUpPresenter(org.uberfire.ext.editor.commons.client.file.popups.RenamePopUpPresenter) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) CommandWithFileNameAndCommitMessage(org.uberfire.ext.editor.commons.client.file.CommandWithFileNameAndCommitMessage) Mockito.verify(org.mockito.Mockito.verify) VerificationMode(org.mockito.verification.VerificationMode) List(java.util.List) Mockito.never(org.mockito.Mockito.never) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) AssetUpdateValidator(org.kie.workbench.common.widgets.metadata.client.validation.AssetUpdateValidator) DefaultFileNameValidator(org.uberfire.ext.editor.commons.client.validation.DefaultFileNameValidator) Mockito.any(org.mockito.Mockito.any) Mockito.reset(org.mockito.Mockito.reset) Assert.assertEquals(org.junit.Assert.assertEquals) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) Mockito.mock(org.mockito.Mockito.mock) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) Mockito.anyString(org.mockito.Mockito.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 47 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FieldPropertiesRendererTest method loadContent.

protected void loadContent() {
    fieldManager = spy(new TestFieldManager());
    renderer = spy(new FieldPropertiesRenderer(view, dynamicFormModelGenerator, staticDataBindingEditor, dynamicDataBindingEditor, fieldManager));
    renderer.init();
    when(helper.getCurrentField()).thenReturn(lastNameField);
    when(helper.getCurrentRenderingContext()).thenReturn(context);
    FormDefinition form = new FormDefinition(null);
    when(context.getRootForm()).thenReturn(form);
    when(dynamicFormModelGenerator.getContextForModel(any())).thenReturn(context);
}
Also used : TestFieldManager(org.kie.workbench.common.forms.fields.test.TestFieldManager) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 48 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormGenerationIntegrationTest method inputTaskFormIsCorrectlyGenerated.

@Test
public void inputTaskFormIsCorrectlyGenerated() {
    when(module.getRootPath()).thenReturn(rootPathWithNestedForms);
    final FormGenerationResult formGenerationResult = generateForm("FormGenerationTest_TaskOnlyWithInputs-taskform.frm", taskFormModels.get(2));
    final List<String> expectedInputTaskFormFields = Arrays.asList("_boolean", CHECKBOX_FIELDTYPE, "_dataObject", SUBFORM_FIELDTYPE, "_document", DOCUMENT_FIELDTYPE, "_float", DECIMALBOX_FIELDTYPE, "_integer", INTEGERBOX_FIELDTYPE, "_object", TEXTAREA_FIELDTYPE, "_string", TEXTBOX_FIELDTYPE);
    final FormDefinition rootForm = formGenerationResult.getRootForm();
    testFormDefinition(rootForm, expectedInputTaskFormFields);
    testNestedFormsHaveCorrectId(rootForm, "_dataObject", DATAOBJECT_FORM_ID);
}
Also used : FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Test(org.junit.Test)

Example 49 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormGenerationIntegrationTest method twinTaskFormIsCorrectlyGenerated.

@Test
public void twinTaskFormIsCorrectlyGenerated() {
    when(module.getRootPath()).thenReturn(rootPathWithNestedForms);
    final FormGenerationResult formGenerationResult = generateForm("FormGenerationTest_TwinTasks-taskform.frm", taskFormModels.get(4));
    final List<String> expectedProcessFormFields = Arrays.asList("_boolean", CHECKBOX_FIELDTYPE, "_dataObject1", SUBFORM_FIELDTYPE, "_dataObject2", SUBFORM_FIELDTYPE, "_string", TEXTBOX_FIELDTYPE, "_boolean_", CHECKBOX_FIELDTYPE, "_string_", TEXTBOX_FIELDTYPE, "dataObject_", SUBFORM_FIELDTYPE, "integer_", INTEGERBOX_FIELDTYPE);
    final FormDefinition rootForm = formGenerationResult.getRootForm();
    testFormDefinition(rootForm, expectedProcessFormFields);
    testNestedFormsHaveCorrectId(rootForm, "_dataObject1", DATAOBJECT_FORM_ID);
    testNestedFormsHaveCorrectId(rootForm, "_dataObject2", DATAOBJECT_FORM_ID);
    testNestedFormsHaveCorrectId(rootForm, "dataObject_", DATAOBJECT_FORM_ID);
}
Also used : FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Test(org.junit.Test)

Example 50 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormGenerationIntegrationTest method testNestedFormsGeneration.

@Test
public void testNestedFormsGeneration() {
    when(module.getRootPath()).thenReturn(rootPathWithoutNestedForms);
    ModelDriver modelDriver = new JavaRoasterModelDriver(ioService, Paths.convert(rootPathWithoutNestedForms), moduleClassLoader, filterHolder);
    try {
        ModelDriverResult result = modelDriver.loadModel();
        dataModel = result.getDataModel();
    } catch (ModelDriverException e) {
        throw new ServiceException("It was not possible to load model for URI: " + rootPathWithoutNestedForms.toURI(), e);
    }
    when(dataModelerService.loadModel(module)).thenReturn(dataModel);
    when(commentedOptionFactory.makeCommentedOption(any())).thenReturn(commentedOption);
    final FormGenerationResult formGenerationResult = generateForm("FormGenerationTest_TwinTasks-taskform.frm", taskFormModels.get(4));
    final List<String> expectedDataObjectFormFields = Arrays.asList("nestedObjectForSubform", SUBFORM_FIELDTYPE, "nestedObjectListForMultipleSubform", MULTIPLESUBFORM_FIELDTYPE, "bigDecimalDecimalBox", DECIMALBOX_FIELDTYPE, "bigIntegerIntegerBox", INTEGERBOX_FIELDTYPE, "booleanCheckBox", CHECKBOX_FIELDTYPE, "byteIntegerBox", INTEGERBOX_FIELDTYPE, "charTextBox", TEXTBOX_FIELDTYPE, "dateDatePicker", DATEPICKER_FIELDTYPE, "doubleDecimalBox", DECIMALBOX_FIELDTYPE, "floatDecimalBox", DECIMALBOX_FIELDTYPE, "longIntegerBox", INTEGERBOX_FIELDTYPE, "stringListBox", TEXTBOX_FIELDTYPE, "intIntegerBox", INTEGERBOX_FIELDTYPE, "shortIntegerBox", INTEGERBOX_FIELDTYPE, "bigDecimalRadioGroup", DECIMALBOX_FIELDTYPE, "bigIntegerRadioGroup", INTEGERBOX_FIELDTYPE, "byteRadioGroup", INTEGERBOX_FIELDTYPE, "charRadioGroup", TEXTBOX_FIELDTYPE, "doubleSlider", DECIMALBOX_FIELDTYPE, "doubleRadioGroup", DECIMALBOX_FIELDTYPE, "floatRadioGroup", DECIMALBOX_FIELDTYPE, "intRadioGroup", INTEGERBOX_FIELDTYPE, "intSlider", INTEGERBOX_FIELDTYPE, "longRadioGroup", INTEGERBOX_FIELDTYPE, "stringPicture", TEXTBOX_FIELDTYPE, "stringRadioGroup", TEXTBOX_FIELDTYPE, "stringTextArea", TEXTBOX_FIELDTYPE, "stringTextBox", TEXTBOX_FIELDTYPE, "shortRadioGroup", INTEGERBOX_FIELDTYPE);
    final List<String> expectedNestedDataObjectFormFields = Arrays.asList("stringListBox", TEXBOX_FIELDTYPE, "doubleDecimalBox", DECIMALBOX_FIELDTYPE, "booleanCheckBox", CHECKBOX_FIELDTYPE, "dateDatePicker", DATEPICKER_FIELDTYPE, "charRadioGroup", TEXTBOX_FIELDTYPE, "doubleSlider", DECIMALBOX_FIELDTYPE, "intIntegerBox", INTEGERBOX_FIELDTYPE, "stringPicture", TEXBOX_FIELDTYPE, "stringTextArea", TEXTBOX_FIELDTYPE, "stringTextBox", TEXTBOX_FIELDTYPE);
    final FormDefinition rootForm = formGenerationResult.getRootForm();
    final List<FormDefinition> nestedForms = formGenerationResult.getNestedForms();
    final FormDefinition dataObjectForm = nestedForms.get(0);
    final FormDefinition nestedDataObjectForm = nestedForms.get(1);
    final String dataObjectFormID = dataObjectForm.getId();
    testNestedFormsHaveCorrectId(rootForm, "_dataObject1", dataObjectFormID);
    testNestedFormsHaveCorrectId(rootForm, "_dataObject2", dataObjectFormID);
    testNestedFormsHaveCorrectId(rootForm, "dataObject_", dataObjectFormID);
    final String nestedDataObjectFormID = nestedDataObjectForm.getId();
    testFormDefinition(dataObjectForm, expectedDataObjectFormFields);
    testNestedFormsHaveCorrectId(dataObjectForm, "nestedObjectForSubform", nestedDataObjectFormID);
    testFormDefinition(nestedDataObjectForm, expectedNestedDataObjectFormFields);
}
Also used : ServiceException(org.kie.workbench.common.screens.datamodeller.service.ServiceException) FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ModelDriver(org.kie.workbench.common.services.datamodeller.driver.ModelDriver) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) Test(org.junit.Test)

Aggregations

FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)89 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)30 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)16 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)14 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)14 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)13 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)12 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)12 AbstractFormGenerationTest (org.kie.workbench.common.forms.adf.engine.shared.test.AbstractFormGenerationTest)10 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)10 List (java.util.List)9 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)8 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)8 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)8 Person (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.model.Person)7 FormModel (org.kie.workbench.common.forms.model.FormModel)7 PortableJavaModel (org.kie.workbench.common.forms.model.impl.PortableJavaModel)7 Date (java.util.Date)6