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;
}
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());
}
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);
}
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);
}
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));
}
Aggregations