use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.
the class NewFieldPopupTest method multipleFieldChangeTest.
@Test
public void multipleFieldChangeTest() {
DataModelerContext context = DataModelerEditorsTestHelper.createTestContext();
NewFieldPopup newFieldPopup = new NewFieldPopup(view);
newFieldPopup.init(context);
when(view.getSelectedType()).thenReturn("boolean");
newFieldPopup.onTypeChange();
// the ability of creating multiple fields should be disabled for java primitives
verify(view, times(1)).enableIsMultiple(false);
verify(view, times(1)).setIsMultiple(false);
// and should be enabled as soon as a non java primitive is selected
when(view.getSelectedType()).thenReturn("java.lang.Integer");
newFieldPopup.onTypeChange();
verify(view, times(1)).enableIsMultiple(true);
}
use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.
the class NewFieldPopupTest method initAndShowPopupTest.
@Test
public void initAndShowPopupTest() {
DataModelerContext context = DataModelerEditorsTestHelper.createTestContext();
List<Pair<String, String>> expectedTypeOptions = DataModelerUtils.buildFieldTypeOptions(context.getBaseTypes(), context.getDataModel().getDataObjects(), context.getDataModel().getJavaEnums(), context.getDataModel().getExternalClasses(), context.getDataModel().getDependencyJavaEnums(), false);
NewFieldPopup newFieldPopup = new NewFieldPopup(view);
newFieldPopup.init(context);
newFieldPopup.show();
// the field type options should have been properly initialized with the types existing in the context.
verify(view, times(1)).init(newFieldPopup);
verify(view, times(1)).initTypeList(expectedTypeOptions, true);
verify(view, times(1)).show();
}
use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.
the class PackageSelectorTest method createContext.
private DataModelerContext createContext() {
DataModelerContext context = DataModelerEditorsTestHelper.createTestContext();
context.appendPackage("package2");
context.appendPackage("package1");
context.appendPackage("package3");
return context;
}
use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.
the class DataModelerEditorsTestHelper method createTestContext.
public static DataModelerContext createTestContext() {
DataModelerContext context = new DataModelerContext("123456789");
context.init(PropertyTypeFactoryImpl.getInstance().getBasePropertyTypes());
List<AnnotationDefinition> commonAnnotations = CommonAnnotations.getCommonAnnotations();
Map<String, AnnotationDefinition> annotationDefinitions = new HashMap<String, AnnotationDefinition>();
for (AnnotationDefinition annotationDefinition : commonAnnotations) {
annotationDefinitions.put(annotationDefinition.getClassName(), annotationDefinition);
}
context.setAnnotationDefinitions(annotationDefinitions);
EditorModelContent content = new EditorModelContent();
content.setDataModel(createTestModel());
content.setCurrentModule(new KieModule());
context.setEditorModelContent(content);
return context;
}
use of org.kie.workbench.common.screens.datamodeller.client.DataModelerContext in project kie-wb-common by kiegroup.
the class DataObjectBrowserTest method addValidPropertyTest.
private void addValidPropertyTest(boolean createAndContinue) {
DataObjectBrowser objectBrowser = createBrowser();
DataModelerContext context = createContext();
objectBrowser.setContext(context);
// the dataObject has fields: field1, field2 and field3
DataObject dataObject = context.getDataObject();
// open the new property dialog.
objectBrowser.onNewProperty();
// check the new field popup is shown
verify(newFieldPopupView, times(1)).show();
// emulate the user data entering in the new field popup
when(newFieldPopupView.getFieldName()).thenReturn("field4");
when(newFieldPopupView.getSelectedType()).thenReturn("java.lang.String");
when(newFieldPopupView.getIsMultiple()).thenReturn(false);
// emulate that the provided field name is correct
Map<String, Boolean> validationResult = new HashMap<String, Boolean>();
validationResult.put("field4", true);
when(validationService.evaluateJavaIdentifiers(new String[] { "field4" })).thenReturn(validationResult);
// emulate the user pressing the create button in the new field popup
newFieldPopup.onCreate();
// the new field popup should have been closed and the new property shoud have been added o the data object.
ObjectProperty expectedProperty = new ObjectPropertyImpl("field4", "java.lang.String", false);
if (createAndContinue) {
verify(newFieldPopupView, times(1)).clear();
} else {
verify(newFieldPopupView, times(1)).hide();
}
verify(view, times(1)).setTableHeight(DataObjectBrowser.DataObjectBrowserHelper.calculateTableHeight(3));
verify(view, times(1)).setTableHeight(DataObjectBrowser.DataObjectBrowserHelper.calculateTableHeight(4));
assertEquals(4, dataObject.getProperties().size());
assertEquals(expectedProperty, dataObject.getProperties().get(3));
}
Aggregations