use of org.kie.workbench.common.forms.model.impl.TypeInfoImpl in project kie-wb-common by kiegroup.
the class FieldManagerTest method testGettingAllProvidersDefinitions.
@Test
public void testGettingAllProvidersDefinitions() {
for (BasicTypeFieldProvider provider : fieldManager.getAllBasicTypeProviders()) {
for (String className : provider.getSupportedTypes()) {
try {
Class clazz = Class.forName(className);
TypeInfo typeInfo = new TypeInfoImpl(clazz.isEnum() ? TypeKind.ENUM : TypeKind.BASE, clazz.getName(), false);
FieldDefinition fieldDefinition = fieldManager.getFieldFromProvider(provider.getFieldTypeName(), typeInfo);
Assertions.assertThat(fieldDefinition).isNotNull();
} catch (ClassNotFoundException e) {
// swallow error caused by looking up simple types
}
}
}
}
use of org.kie.workbench.common.forms.model.impl.TypeInfoImpl in project kie-wb-common by kiegroup.
the class FormModelSynchronizationUtilImplTest method testTypeConflictProperties.
@Test
public void testTypeConflictProperties() {
Map<String, TypeConflictImpl> conflicts = formModelSynchronizationResult.getConflicts();
ModelProperty name = formModel.getProperty("name");
assertNotNull(name);
conflicts.put("name", new TypeConflictImpl("name", name.getTypeInfo(), new TypeInfoImpl(Boolean.class.getName())));
ModelProperty surname = formModel.getProperty("surname");
assertNotNull(surname);
conflicts.put("surname", new TypeConflictImpl("surname", name.getTypeInfo(), new TypeInfoImpl(Long.class.getName())));
ModelProperty birthday = formModel.getProperty("birthday");
assertNotNull(birthday);
conflicts.put("birthday", new TypeConflictImpl("birthday", name.getTypeInfo(), new TypeInfoImpl(String.class.getName())));
synchronizationUtil.init(form, formModelSynchronizationResult);
int originalFormFields = form.getFields().size();
synchronizationUtil.resolveConflicts();
assertEquals(originalFormFields, form.getFields().size());
checkConflictedFieldDefinition(conflicts.get("name"), CheckBoxFieldDefinition.class);
checkConflictedFieldDefinition(conflicts.get("surname"), IntegerBoxFieldDefinition.class);
checkConflictedFieldDefinition(conflicts.get("birthday"), TextBoxFieldDefinition.class);
}
use of org.kie.workbench.common.forms.model.impl.TypeInfoImpl in project kie-wb-common by kiegroup.
the class FormGenerationWithSynchronizationTest method testRemoveModelProperties.
@Test
public void testRemoveModelProperties() {
List<ModelProperty> modelProperties = new ArrayList<>();
modelProperties.add(new ModelPropertyImpl(NAME_PROPERTY, new TypeInfoImpl(String.class.getName())));
modelProperties.add(new ModelPropertyImpl(LASTNAME_PROPERTY, new TypeInfoImpl(String.class.getName())));
newFormModel = new TaskFormModel(PROCESS_ID, TASK_NAME, modelProperties);
FormGenerationResult generationResult = service.generateForms(newFormModel, source);
assertNotNull(generationResult);
assertNotNull(generationResult.getRootForm());
FormDefinition formDefinition = generationResult.getRootForm();
assertEquals(newFormModel, formDefinition.getModel());
assertEquals(ORIGINAL_FORM_FIELDS, Integer.valueOf(formDefinition.getFields().size()));
FieldDefinition field = formDefinition.getFieldByBinding(NAME_PROPERTY);
assertNotNull(field);
assertEquals(field.getStandaloneClassName(), String.class.getName());
field = formDefinition.getFieldByBinding(LASTNAME_PROPERTY);
assertNotNull(field);
assertEquals(field.getStandaloneClassName(), String.class.getName());
assertNull(formDefinition.getFieldByBinding(AGE_PROPERTY));
assertNull(formDefinition.getFieldByBinding(MARRIED_PROPERTY));
assertNull(formDefinition.getFieldByBinding(ADDRESS_PROPERTY));
assertNotNull(formDefinition.getFieldByName(AGE_PROPERTY));
assertNotNull(formDefinition.getFieldByName(MARRIED_PROPERTY));
assertNotNull(formDefinition.getFieldByName(ADDRESS_PROPERTY));
}
use of org.kie.workbench.common.forms.model.impl.TypeInfoImpl 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.impl.TypeInfoImpl in project kie-wb-common by kiegroup.
the class FormEditorHelperTest method initFields.
private void initFields() {
TextBoxFieldDefinition name = new TextBoxFieldDefinition();
name.setId("name");
name.setName("name");
name.setLabel("Name");
name.setPlaceHolder("Name");
name.setBinding("name");
name.setStandaloneClassName(String.class.getName());
nameField = name;
TextBoxFieldDefinition lastName = new TextBoxFieldDefinition();
lastName.setId("lastName");
lastName.setName("lastName");
lastName.setLabel("Last Name");
lastName.setPlaceHolder("Last Name");
lastName.setBinding("lastName");
lastName.setStandaloneClassName(String.class.getName());
lastNameField = lastName;
DatePickerFieldDefinition birthday = new DatePickerFieldDefinition();
birthday.setId("birthday");
birthday.setName("birthday");
birthday.setLabel("Birthday");
birthday.setBinding("birthday");
birthday.setStandaloneClassName(Date.class.getName());
CheckBoxFieldDefinition married = new CheckBoxFieldDefinition();
married.setId("married");
married.setName("married");
married.setLabel("Married");
married.setBinding("married");
married.setStandaloneClassName(Boolean.class.getName());
marriedField = married;
IntegerBoxFieldDefinition age = new IntegerBoxFieldDefinition();
age.setId("age");
age.setName("age");
age.setLabel("Age");
age.setBinding("age");
ageField = age;
DecimalBoxFieldDefinition weight = new DecimalBoxFieldDefinition();
weight.setId("weight");
weight.setName("weight");
weight.setLabel("Weight");
weight.setBinding("weight");
weightField = weight;
employeeFields = new ArrayList<>();
employeeFields.add(name);
employeeFields.add(lastName);
employeeFields.add(birthday);
employeeFields.add(married);
employeeFields.add(age);
employeeFields.add(weight);
modelProperties = new ArrayList<>();
employeeFields.forEach(fieldDefinition -> modelProperties.add(new ModelPropertyImpl(fieldDefinition.getBinding(), new TypeInfoImpl(fieldDefinition.getStandaloneClassName()))));
}
Aggregations