use of org.uberfire.ext.layout.editor.api.editor.LayoutRow in project kie-wb-common by kiegroup.
the class AllFieldTypesFormGenerationTest method testMigration.
@Test
public void testMigration() {
generator.execute(context);
Assertions.assertThat(context.getSummaries()).isNotEmpty().hasSize(1);
Assertions.assertThat(context.getExtraSummaries()).isEmpty();
// 1 legacyforms + 1 migrated forms
verify(migrationServicesCDIWrapper, times(2)).write(any(Path.class), anyString(), anyString());
FormMigrationSummary summary = context.getSummaries().iterator().next();
Form originalForm = summary.getOriginalForm().get();
FormDefinition newForm = summary.getNewForm().get();
assertNotNull(newForm);
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(fieldMappings.size());
LayoutTemplate newLayout = newForm.getLayoutTemplate();
assertNotNull(newLayout);
Assertions.assertThat(newLayout.getRows()).isNotEmpty().hasSize(// fields + 2 decorators in original form
fieldMappings.size() + 2);
List<LayoutRow> rows = newLayout.getRows();
checkDecoratorRow(rows.get(0));
checkDecoratorRow(rows.get(1));
IntStream indexStream = IntStream.range(0, fieldMappings.size());
indexStream.forEach(index -> {
FieldDefinition newField = newForm.getFields().get(index);
assertNotNull(newField);
Field originalField = originalForm.getField(newField.getName());
assertNotNull(originalField);
checkFieldDefinition(newField, newField.getName(), newField.getLabel(), newField.getBinding(), fieldMappings.get(newField.getName()), newForm, originalField);
LayoutRow row = rows.get(index + 2);
LayoutComponent component = checkRow(row);
checkLayoutFormField(component, newField, newForm);
});
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutRow in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorForBPMNWithComplexVariableTest method verifyBPMNForm.
private void verifyBPMNForm(FormMigrationSummary summary, Class<? extends JBPMFormModel> modelType) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).hasSize(5);
Field originalInvoiceUser = originalForm.getField(INVOICE_USER);
Field originalLines = originalForm.getField(INVOICE_LINES);
Field originalTotal = originalForm.getField(INVOICE_TOTAL);
DataHolder originalDataHolder = originalForm.getHolders().iterator().next();
String expectedExtraForm = summary.getBaseFormName() + "-" + originalDataHolder.getUniqeId();
checkMovedField(originalInvoiceUser, expectedExtraForm);
checkMovedField(originalLines, expectedExtraForm);
checkMovedField(originalTotal, expectedExtraForm);
Field invoiceField = originalForm.getField("invoice");
Assertions.assertThat(invoiceField).isNotNull().hasFieldOrPropertyWithValue("bag", INVOICE_MODEL).hasFieldOrPropertyWithValue("sourceLink", summary.getBaseFormName() + "-" + invoiceField.getFieldName()).hasFieldOrPropertyWithValue("inputBinding", originalDataHolder.getInputId()).hasFieldOrPropertyWithValue("outputBinding", originalDataHolder.getOuputId()).extracting("defaultSubform").isNotNull();
assertNotNull(invoiceField);
assertEquals(FieldTypeBuilder.SUBFORM, invoiceField.getFieldType().getCode());
FormDefinition newFormDefinition = summary.getNewForm().get();
Assertions.assertThat(newFormDefinition.getModel()).isNotNull().isInstanceOf(modelType);
Assertions.assertThat(newFormDefinition.getModel().getProperties()).hasSize(1).extracting("typeInfo.className").contains(INVOICE_MODEL);
Assertions.assertThat(newFormDefinition.getFields()).isNotNull().hasSize(1);
FieldDefinition newInvoiceField = newFormDefinition.getFieldByName("invoice");
Assertions.assertThat(newInvoiceField).isNotNull().isInstanceOf(SubFormFieldDefinition.class).hasFieldOrPropertyWithValue("standaloneClassName", INVOICE_MODEL);
LayoutTemplate newFormLayout = newFormDefinition.getLayoutTemplate();
assertNotNull(newFormLayout);
Assertions.assertThat(newFormLayout.getRows()).isNotEmpty().hasSize(1);
LayoutRow newLayoutRow = newFormLayout.getRows().get(0);
assertNotNull(newLayoutRow);
Assertions.assertThat(newLayoutRow.getLayoutColumns()).isNotEmpty().hasSize(1);
LayoutColumn newLayoutColumn = newLayoutRow.getLayoutColumns().get(0);
assertNotNull(newLayoutColumn);
assertEquals("12", newLayoutColumn.getSpan());
Assertions.assertThat(newLayoutColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(newLayoutColumn.getLayoutComponents().get(0), newInvoiceField, newFormDefinition);
FormMigrationSummary extraSummary = context.getExtraSummaries().stream().filter(extra -> extra.getBaseFormName().equals(expectedExtraForm)).findAny().orElse(null);
FormDefinition newExtraFormDefinition = extraSummary.getNewForm().get();
checkInvoiceFormDefinition(newExtraFormDefinition, originalForm);
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutRow in project kie-wb-common by kiegroup.
the class FormDefinitionGeneratorWithUnsupportedFieldsTest method testMigration.
@Test
public void testMigration() {
generator.execute(context);
Assertions.assertThat(context.getSummaries()).isNotEmpty().hasSize(1);
Assertions.assertThat(context.getExtraSummaries()).isEmpty();
// 1 legacyforms + 1 migrated forms
verify(migrationServicesCDIWrapper, times(2)).write(any(Path.class), anyString(), anyString());
FormMigrationSummary summary = context.getSummaries().iterator().next();
Form originalForm = summary.getOriginalForm().get();
FormDefinition newForm = summary.getNewForm().get();
assertNotNull(newForm);
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(1);
LayoutTemplate newLayout = newForm.getLayoutTemplate();
assertNotNull(newLayout);
Assertions.assertThat(newLayout.getRows()).isNotEmpty().hasSize(2);
// Checking first field (login), althought the original field type isn't supported it can be migrated to a textbox
Field originalLogin = originalForm.getField(USER_LOGIN);
FieldDefinition newLogin = newForm.getFieldByName(USER_LOGIN);
assertNotNull(newLogin);
checkFieldDefinition(newLogin, USER_LOGIN, "login", "login", TextBoxFieldDefinition.class, newForm, originalLogin);
LayoutRow loginRow = newLayout.getRows().get(0);
assertNotNull(loginRow);
Assertions.assertThat(loginRow.getLayoutColumns()).isNotEmpty().hasSize(1);
LayoutColumn loginColumn = loginRow.getLayoutColumns().get(0);
assertNotNull(loginColumn);
assertEquals("12", loginColumn.getSpan());
Assertions.assertThat(loginColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(loginColumn.getLayoutComponents().get(0), newLogin, newForm);
// Checking second field (password), the original field type isn't supported and it cannot be migrated to any
// other form control. There shouldn't be any FieldDefinition for it but it should be an HTML component on
// the layout warning about the error
assertNull(newForm.getFieldByName(USER_PASSWORD));
LayoutRow passwordRow = newLayout.getRows().get(1);
assertNotNull(passwordRow);
Assertions.assertThat(passwordRow.getLayoutColumns()).isNotEmpty().hasSize(1);
LayoutColumn passwordColumn = passwordRow.getLayoutColumns().get(0);
assertNotNull(passwordColumn);
assertEquals("12", passwordColumn.getSpan());
Assertions.assertThat(passwordColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
LayoutComponent passwordComponent = passwordColumn.getLayoutComponents().get(0);
Assertions.assertThat(passwordComponent).isNotNull().hasFieldOrPropertyWithValue("dragTypeName", FormsMigrationConstants.HTML_COMPONENT);
Field originalPassword = originalForm.getField(USER_PASSWORD);
Formatter formatter = new Formatter();
formatter.format(FormsMigrationConstants.UNSUPORTED_FIELD_HTML_TEMPLATE, originalPassword.getFieldName(), originalPassword.getFieldType().getCode());
final String expectedHtmlMessage = formatter.toString();
Assertions.assertThat(passwordComponent.getProperties()).hasEntrySatisfying(FormsMigrationConstants.HTML_CODE_PARAMETER, new Condition<>(htmlMessage -> htmlMessage.equals(expectedHtmlMessage), "Invalid error HTML message"));
formatter.close();
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutRow 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.uberfire.ext.layout.editor.api.editor.LayoutRow 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);
});
}
Aggregations