Search in sources :

Example 41 with FormDefinition

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

the class NestedFormsBPMNVFSFormDefinitionGeneratorServiceTest method findVFSForms.

private List<FormDefinition> findVFSForms(InvocationOnMock invocationOnMock) {
    String className = invocationOnMock.getArguments()[0].toString();
    if (Expense.class.getName().equals(className)) {
        FormModel formModel = new DataObjectFormModel(className, className);
        // Creating empty form
        FormDefinition emptyForm = new FormDefinition(formModel);
        emptyForm.setName(EMPTY_FORM_ID);
        emptyForm.setId(EMPTY_FORM_ID);
        // Creating a form with a field
        FormDefinition fullForm = new FormDefinition(formModel);
        fullForm.setName(EXPENSE_FORM_ID);
        fullForm.setId(EXPENSE_FORM_ID);
        DatePickerFieldDefinition field = new DatePickerFieldDefinition();
        field.setId(DATE_VARIABLE);
        field.setName(DATE_VARIABLE);
        field.setLabel(DATE_VARIABLE);
        field.setBinding(DATE_VARIABLE);
        fullForm.getFields().add(field);
        return Arrays.asList(emptyForm, fullForm);
    }
    return null;
}
Also used : Expense(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.model.Expense) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel) FormModel(org.kie.workbench.common.forms.model.FormModel) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) Matchers.anyString(org.mockito.Matchers.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel)

Example 42 with FormDefinition

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

the class NestedFormsBPMNVFSFormDefinitionGeneratorServiceTest method testCreateNewProcessFormNestedFormsWithModelFormsOnVFS.

@Test
public void testCreateNewProcessFormNestedFormsWithModelFormsOnVFS() {
    when(ioService.exists(any())).thenReturn(false);
    when(formFinderService.findFormsForType(any(), any())).thenAnswer(this::findVFSForms);
    FormGenerationResult result = launchNestedFormsTest();
    FormDefinition rootForm = result.getRootForm();
    assertNotNull(rootForm);
    FieldDefinition expenseField = rootForm.getFieldByBinding(EXPENSE_VARIABLE);
    assertNotNull(expenseField);
    assertTrue(expenseField instanceof SubFormFieldDefinition);
    SubFormFieldDefinition subFormFieldDefinition = (SubFormFieldDefinition) expenseField;
    // The nested form should be the form with a field not the empty one
    assertEquals(EXPENSE_FORM_ID, subFormFieldDefinition.getNestedForm());
    assertEquals(EXPENSE_FORM_ID, subFormFieldDefinition.getStandaloneClassName());
    // since the nested forms exist on VFS there shouldn't be any nested forms on the result
    assertTrue(result.getNestedForms().isEmpty());
    // since the nested forms exist on VFS it shouldn't be any write operation on the VFS
    verify(ioService, never()).write(any(), anyString(), any());
}
Also used : SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Test(org.junit.Test)

Example 43 with FormDefinition

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

the class BPMNFormGenerationTest method testComplexFields.

protected void testComplexFields(boolean fromClassLoader) {
    if (fromClassLoader) {
        try {
            when(classLoader.loadClass(Person.class.getName())).then(new Answer<Class<?>>() {

                @Override
                public Class<?> answer(InvocationOnMock invocationOnMock) throws Throwable {
                    return Person.class;
                }
            });
        } catch (ClassNotFoundException e) {
            fail("We shouldn't be here: " + e.getMessage());
        }
    }
    List<ModelProperty> properties = new ArrayList<>();
    properties.add(new ModelPropertyImpl("person", new TypeInfoImpl(TypeKind.OBJECT, Person.class.getName(), false)));
    model = getModel(getModelId(), properties);
    Collection<FormDefinition> forms = getModelForms(model, classLoader);
    Map<String, FormDefinition> allForms = new HashMap<>();
    forms.forEach(form -> allForms.put(form.getId(), form));
    try {
        verify(classLoader, times(3)).loadClass(anyString());
    } catch (ClassNotFoundException e) {
        fail(e.getMessage());
    }
    assertNotNull("There should some forms", forms);
    assertEquals("There should 4 forms", 4, forms.size());
    FormDefinition form = allForms.get(getModelId() + BPMNVariableUtils.TASK_FORM_SUFFIX);
    checkBPMForm(form, allForms);
    form = findFormForModel(Person.class.getName(), allForms);
    checkPersonForm(form, allForms);
    form = findFormForModel(PersonalData.class.getName(), allForms);
    checkPersonalDataForm(form, allForms);
    form = findFormForModel(LogEntry.class.getName(), allForms);
    checkLogEntryForm(form);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Person(org.kie.workbench.common.forms.jbpm.server.service.impl.model.Person)

Example 44 with FormDefinition

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

the class FormEditorPresenterAbstractTest method setUp.

@Before
public void setUp() throws Exception {
    fieldManager = new TestFieldManager();
    model = new PortableJavaModel("com.test.Employee");
    model.addProperty("name", String.class.getName());
    model.addProperty("lastName", String.class.getName());
    model.addProperty("birthday", Date.class.getName());
    model.addProperty("married", Boolean.class.getName());
    form = new FormDefinition(model);
    form.setName("EmployeeTestForm");
    form.setId("_random_id");
    // model.getProperties().stream().map(fieldManager::getDefinitionByModelProperty).forEach(fieldDefinition -> form.getFields().add(fieldDefinition));
    modelProperties = new ArrayList<>(model.getProperties());
    employeeFields = new ArrayList<>(form.getFields());
    when(workbenchContext.getActiveOrganizationalUnit()).thenReturn(Optional.empty());
    when(workbenchContext.getActiveWorkspaceProject()).thenReturn(Optional.empty());
    when(workbenchContext.getActiveModule()).thenReturn(Optional.empty());
    when(workbenchContext.getActiveRepositoryRoot()).thenReturn(Optional.empty());
    when(workbenchContext.getActivePackage()).thenReturn(Optional.empty());
    when(alertsButtonMenuItemBuilder.build()).thenReturn(alertsButtonMenuItem);
}
Also used : PortableJavaModel(org.kie.workbench.common.forms.model.impl.PortableJavaModel) TestFieldManager(org.kie.workbench.common.forms.fields.test.TestFieldManager) Mockito.anyString(org.mockito.Mockito.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Date(java.util.Date) Before(org.junit.Before)

Example 45 with FormDefinition

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

the class FormEditorPresenterAbstractTest method addAllFields.

protected void addAllFields() {
    FormDefinition form = editorHelper.getFormDefinition();
    editorHelper.getAvailableFields().values().forEach(field -> form.getFields().add(field));
}
Also used : FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

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