use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method verifyInvoiceForm.
protected void verifyInvoiceForm(FormMigrationSummary summary) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(3);
FormDefinition newForm = summary.getNewForm().get();
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(3);
Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", INVOICE_MODEL).isInstanceOf(DataObjectFormModel.class);
IntStream indexStream = IntStream.range(0, newForm.getFields().size());
LayoutTemplate formLayout = newForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(newForm.getFields().size());
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = newForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, INVOICE_USER, "user (invoice)", "user", SubFormFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, INVOICE_LINES, "lines (invoice)", "lines", MultipleSubFormFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 3:
checkFieldDefinition(fieldDefinition, INVOICE_LINES, "lines (invoice)", "lines", MultipleSubFormFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
}
LayoutRow fieldRow = formLayout.getRows().get(index);
assertNotNull(fieldRow);
Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(1);
LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(0);
assertNotNull(fieldColumn);
assertEquals("12", fieldColumn.getSpan());
Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
});
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method verifyUserForm.
protected void verifyUserForm(FormMigrationSummary summary) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(2);
FormDefinition newForm = summary.getNewForm().get();
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(2);
Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", USER_MODEL).isInstanceOf(DataObjectFormModel.class);
IntStream indexStream = IntStream.range(0, newForm.getFields().size());
LayoutTemplate formLayout = newForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(2);
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = newForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, USER_LOGIN, "login", "login", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, USER_PASSWORD, "password", "password", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
}
LayoutRow fieldRow = formLayout.getRows().get(index);
assertNotNull(fieldRow);
Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(1);
LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(0);
assertNotNull(fieldColumn);
assertEquals("12", fieldColumn.getSpan());
Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
});
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorImpl method createFormForModel.
public void createFormForModel(JBPMFormModel formModel, org.uberfire.java.nio.file.Path path) {
if (formModel == null) {
LOGGER.severe("Impossible to create form for empty model");
throw new IllegalArgumentException("Impossible to create form for empty model");
}
org.uberfire.java.nio.file.Path nioFormPath = path.getParent().resolve(formModel.getFormName() + ".frm");
FormDefinition form = bpmnFormGeneratorService.generateForms(formModel, Paths.convert(nioFormPath)).getRootForm();
if (!ioService.exists(nioFormPath)) {
ioService.createFile(nioFormPath);
}
ioService.write(nioFormPath, serializer.serialize(form));
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormEditorHelperTest method loadContent.
private void loadContent() {
testFieldManager = spy(new TestFieldManager());
when(editorFieldLayoutComponents.get()).thenAnswer(invocationOnMock -> {
final EditorFieldLayoutComponent mocked = mock(EditorFieldLayoutComponent.class);
return mocked;
});
when(formEditorService.loadContent(any())).then(invocation -> {
FormDefinition form = new FormDefinition();
form.setName("EmployeeTestForm");
form.setId("_random_id");
content = new FormModelerContent();
PortableJavaModel model = new PortableJavaModel("com.test.Employee");
model.getProperties().addAll(modelProperties);
form.setModel(model);
content.setDefinition(form);
content.setOverview(new Overview());
return content;
});
when(testFieldManager.getBaseFieldTypes()).thenAnswer(invocationOnMock -> {
List<String> baseFields = new ArrayList<>();
baseFields.add("TextBox");
baseFields.add("CheckBox");
return baseFields;
});
editorServiceCallerMock = new CallerMock<>(formEditorService);
formEditorHelper = new TestFormEditorHelper(testFieldManager, editorFieldLayoutComponents);
formEditorService.loadContent(null);
formEditorHelper.initHelper(content);
assertEquals(formEditorHelper.getEditorFieldTypes().size(), formEditorHelper.getBaseFieldsDraggables().size());
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormEditorHelperTest method testGetFormDefinition.
@Test
public void testGetFormDefinition() {
FormDefinition formDefinition = formEditorHelper.getFormDefinition();
assertEquals(formDefinition, content.getDefinition());
}
Aggregations