use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormLayoutTemplateGeneratorTest method init.
@Before
public void init() {
templateGenerator = getTemplateGenerator();
form = new FormDefinition();
form.setName("Test");
form.setId("Test-ID");
TextBoxFieldDefinition name = new TextBoxFieldDefinition();
name.setId("name");
name.setName("employee_name");
name.setLabel("Name");
name.setPlaceHolder("Name");
name.setBinding("name");
name.setStandaloneClassName(String.class.getName());
TextBoxFieldDefinition lastName = new TextBoxFieldDefinition();
lastName.setId("lastName");
lastName.setName("employee_lastName");
lastName.setLabel("Last Name");
lastName.setPlaceHolder("Last Name");
lastName.setBinding("lastName");
lastName.setStandaloneClassName(String.class.getName());
DatePickerFieldDefinition birthday = new DatePickerFieldDefinition();
birthday.setId("birthday");
birthday.setName("employee_birthday");
birthday.setLabel("Birthday");
birthday.setBinding("birthday");
birthday.setStandaloneClassName(Date.class.getName());
CheckBoxFieldDefinition married = new CheckBoxFieldDefinition();
married.setId("married");
married.setName("employee_married");
married.setLabel("Married");
married.setBinding("married");
married.setStandaloneClassName(Boolean.class.getName());
form.getFields().add(name);
form.getFields().add(lastName);
form.getFields().add(birthday);
form.getFields().add(married);
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormDefinitionSerializerImplTest method initTest.
@Before
public void initTest() {
fieldManager = new TestFieldManager();
definitionSerializer = new FormDefinitionSerializerImpl(new FieldSerializer(), new FormModelSerializer(), new TestMetaDataEntryManager());
JavaFormModel model = new PortableJavaModel("org.test.MyParentModel");
formDefinition = new FormDefinition(model);
formDefinition.setId("testForm");
formDefinition.setName("testForm");
formDefinition.setLayoutTemplate(new LayoutTemplate());
for (BasicTypeFieldProvider provider : fieldManager.getAllBasicTypeProviders()) {
for (String type : provider.getSupportedTypes()) {
FieldDefinition field = provider.getFieldByType(new TypeInfoImpl(type));
assertNotNull(field);
String fieldDescription = provider.getFieldTypeName() + "_" + type;
field.setName(fieldDescription);
field.setLabel(fieldDescription);
field.setStandaloneClassName(type);
field.setBinding(fieldDescription);
model.getProperties().add(new ModelPropertyImpl(fieldDescription, new TypeInfoImpl(type)));
formDefinition.getFields().add(field);
}
}
SubFormFieldDefinition subForm = new SubFormFieldDefinition();
subForm.setLabel("SubForm");
subForm.setNestedForm("");
subForm.setBinding("model");
subForm.setStandaloneClassName("org.test.MyTestModel");
subForm.setBinding("SubForm");
formDefinition.getFields().add(subForm);
model.getProperties().add(new ModelPropertyImpl(subForm.getBinding(), new TypeInfoImpl(TypeKind.OBJECT, subForm.getStandaloneClassName(), false)));
MultipleSubFormFieldDefinition multipleSubForm = new MultipleSubFormFieldDefinition();
multipleSubForm.setLabel("MultipleSubForm");
multipleSubForm.setCreationForm("");
multipleSubForm.setEditionForm("");
multipleSubForm.setStandaloneClassName("org.test.MyTestModel");
multipleSubForm.setBinding("MultipleSubForm");
formDefinition.getFields().add(multipleSubForm);
model.getProperties().add(new ModelPropertyImpl(multipleSubForm.getBinding(), new TypeInfoImpl(TypeKind.OBJECT, multipleSubForm.getStandaloneClassName(), true)));
EnumListBoxFieldDefinition enumListBox = new EnumListBoxFieldDefinition();
enumListBox.setLabel("EnumListBox");
enumListBox.setBinding("EnumListBox");
enumListBox.setStandaloneClassName("org.test.MyTestModel");
formDefinition.getFields().add(enumListBox);
model.getProperties().add(new ModelPropertyImpl(enumListBox.getBinding(), new TypeInfoImpl(TypeKind.ENUM, enumListBox.getStandaloneClassName(), false)));
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormDefinitionSerializerImplTest method testFormDeSerialization.
@Test
public void testFormDeSerialization() {
String serializedForm = doSerializationTest();
FormDefinition deSerializedForm = definitionSerializer.deserialize(serializedForm);
assertNotNull(deSerializedForm);
assertEquals(formDefinition.getFields().size(), deSerializedForm.getFields().size());
for (FieldDefinition originalField : formDefinition.getFields()) {
FieldDefinition resultField = deSerializedForm.getFieldById(originalField.getId());
assertNotNull(resultField);
assertEquals(originalField.getClass(), resultField.getClass());
assertEquals(originalField.getName(), resultField.getName());
assertEquals(originalField.getLabel(), resultField.getLabel());
assertEquals(originalField.getStandaloneClassName(), resultField.getStandaloneClassName());
}
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormGeneratorTest method testGenerateFormForClassWithFilters.
@Test
public void testGenerateFormForClassWithFilters() {
FormDefinition form = generator.generateFormForClass(Person.class, getFilters());
checkFormGeneratedWithFilters(form);
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormGeneratorTest method testGenerateFormForClassName.
@Test
public void testGenerateFormForClassName() {
FormDefinition form = generator.generateFormForClassName(Person.class.getName());
testGeneratedForm(form, Person.class.getName());
}
Aggregations