Search in sources :

Example 6 with DataModelerContext

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);
}
Also used : DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) Test(org.junit.Test)

Example 7 with DataModelerContext

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();
}
Also used : DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) Pair(org.uberfire.commons.data.Pair) Test(org.junit.Test)

Example 8 with DataModelerContext

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;
}
Also used : DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)

Example 9 with DataModelerContext

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;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) HashMap(java.util.HashMap) EditorModelContent(org.kie.workbench.common.screens.datamodeller.model.EditorModelContent) DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 10 with DataModelerContext

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));
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) HashMap(java.util.HashMap) DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)

Aggregations

DataModelerContext (org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)15 Test (org.junit.Test)10 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)5 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)4 HashMap (java.util.HashMap)3 Pair (org.uberfire.commons.data.Pair)3 DataObjectFieldDeletedEvent (org.kie.workbench.common.screens.datamodeller.events.DataObjectFieldDeletedEvent)2 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)2 ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)2 DataModelerEvent (org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent)1 EditorModelContent (org.kie.workbench.common.screens.datamodeller.model.EditorModelContent)1 AnnotationDefinition (org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition)1 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1