Search in sources :

Example 6 with DataModelerEvent

use of org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent in project kie-wb-common by kiegroup.

the class DataObjectBrowserTest method removePropertyTest.

@Test
public void removePropertyTest() {
    DataObjectBrowser objectBrowser = createBrowser();
    DataModelerContext context = createContext();
    // the dataObject has fields: field1, field2 and field3
    DataObject dataObject = context.getDataObject();
    ObjectProperty objectProperty = dataObject.getProperty("field3");
    int count = dataObject.getProperties().size();
    context.getEditorModelContent().setPath(dummyPath);
    objectBrowser.setContext(context);
    when(assetsUsageService.getAssetPartUsages(any(), any(), any(), any())).thenReturn(new ArrayList<>());
    // field3 is on position 2 by construction.
    objectBrowser.onDeleteProperty(objectProperty, 2);
    verify(showAssetUsagesDisplayer).showAssetPartUsages(anyString(), any(), any(), any(), any(), any(), any());
    // if field3 was removed, then field2 should have been selected.
    verify(view).setSelectedRow(dataObject.getProperty("field2"), true);
    // an even should have been fired with the notification of the just removed property.
    verify(dataModelerEvent, times(1)).fire(any(DataModelerEvent.class));
    verify(view, times(1)).setTableHeight(DataObjectBrowser.DataObjectBrowserHelper.calculateTableHeight(count));
    verify(view, times(2)).setTableHeight(DataObjectBrowser.DataObjectBrowserHelper.calculateTableHeight(count - 1));
    // the dataObject should now have one less property.
    assertEquals((count - 1), dataObject.getProperties().size());
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataModelerEvent(org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 7 with DataModelerEvent

use of org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent in project kie-wb-common by kiegroup.

the class MainDataObjectFieldEditorTest method valuesChangeTest.

@Test
public void valuesChangeTest() {
    MainDataObjectFieldEditor fieldEditor = createFieldEditor();
    DataObject dataObject = context.getDataObject();
    ObjectProperty field = dataObject.getProperty("field1");
    // emulates selection of field1 in current context.
    context.setObjectProperty(field);
    // The domain editors typically reacts upon DataModelerContext changes.
    // when the context changes the editor will typically be reloaded.
    fieldEditor.onContextChange(context);
    context.getEditorModelContent().setOriginalClassName(context.getDataObject().getClassName());
    context.getEditorModelContent().setPath(mock(Path.class));
    // emulate the user input
    when(view.getName()).thenReturn(NEW_FIELD_NAME);
    when(view.getDescription()).thenReturn(NEW_DESCRIPTION);
    when(view.getLabel()).thenReturn(NEW_LABEL);
    when(view.getType()).thenReturn(NEW_TYPE);
    Map<String, Boolean> validationResult = new HashMap<String, Boolean>();
    validationResult.put(NEW_FIELD_NAME, true);
    when(validationService.evaluateJavaIdentifiers(any(String[].class))).thenReturn(validationResult);
    // notify the presenter about the changes in the UI
    fieldEditor.onNameChange();
    fieldEditor.onLabelChange();
    fieldEditor.onDescriptionChange();
    fieldEditor.onTypeChange();
    verify(showAssetUsagesDisplayer).showAssetPartUsages(anyString(), any(), anyString(), anyString(), any(), any(), any());
    // After the changes has been processed by the presenter the field should have been populated with the new values.
    field = context.getObjectProperty();
    assertEquals(NEW_FIELD_NAME, field.getName());
    assertEquals(NEW_LABEL, AnnotationValueHandler.getStringValue(field, Label.class.getName()));
    assertEquals(NEW_DESCRIPTION, AnnotationValueHandler.getStringValue(field, Description.class.getName()));
    assertEquals(NEW_TYPE, field.getClassName());
    verify(dataModelerEvent, times(4)).fire(any(DataModelerEvent.class));
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Path(org.uberfire.backend.vfs.Path) DataModelerEvent(org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) HashMap(java.util.HashMap) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 8 with DataModelerEvent

use of org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent in project kie-wb-common by kiegroup.

the class DroolsDataObjectFieldEditorTest method valuesChangesTest.

@Test
public void valuesChangesTest() {
    DroolsDataObjectFieldEditor fieldEditor = createFieldEditor();
    DataObject dataObject = context.getDataObject();
    ObjectProperty field1 = dataObject.getProperty("field1");
    // emulates selection of field1 in current context.
    context.setObjectProperty(field1);
    ;
    // The domain editors typically reacts upon DataModelerContext changes.
    // when the context changes the editor will typically be reloaded.
    fieldEditor.onContextChange(context);
    // emulate the user input.
    when(view.getEquals()).thenReturn(false);
    when(view.getPosition()).thenReturn("1");
    // notify the presenter about the changes in the UI
    fieldEditor.onEqualsChange();
    fieldEditor.onPositionChange();
    assertNull(field1.getAnnotation(Key.class.getName()));
    assertEquals(1, AnnotationValueHandler.getValue(field1, Position.class.getName(), "value"));
    verify(dataModelerEvent, times(2)).fire(any(DataModelerEvent.class));
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataModelerEvent(org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 9 with DataModelerEvent

use of org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent in project kie-wb-common by kiegroup.

the class MainDataObjectEditorTest method valuesChangeTest.

@Test
public void valuesChangeTest() {
    MainDataObjectEditor objectEditor = createObjectEditor();
    // load the editor
    objectEditor.onContextChange(context);
    context.getEditorModelContent().setOriginalClassName(context.getDataObject().getClassName());
    context.getEditorModelContent().setPath(mock(Path.class));
    // emulate the user input
    when(view.getName()).thenReturn(NEW_NAME);
    when(view.getPackageName()).thenReturn(NEW_PACKAGE);
    when(view.getSuperClass()).thenReturn(NEW_SUPERCLASS);
    when(view.getDescription()).thenReturn(NEW_DESCRIPTION);
    when(view.getLabel()).thenReturn(NEW_LABEL);
    Map<String, Boolean> validationResult = new HashMap<String, Boolean>();
    validationResult.put(NEW_NAME, true);
    when(validationService.evaluateJavaIdentifiers(any(String[].class))).thenReturn(validationResult);
    // notify the presenter about the changes in the UI
    objectEditor.onNameChange();
    objectEditor.onPackageChange();
    objectEditor.onSuperClassChange();
    objectEditor.onLabelChange();
    objectEditor.onDescriptionChange();
    verify(showAssetUsagesDisplayer, times(2)).showAssetUsages(anyString(), any(), any(), any(), any(), any());
    // After the changes has been processed by the presenter the dataObject should have been populated with the new values.
    DataObject dataObject = context.getDataObject();
    assertEquals(NEW_NAME, dataObject.getName());
    assertEquals(NEW_PACKAGE, dataObject.getPackageName());
    assertEquals(NEW_SUPERCLASS, dataObject.getSuperClassName());
    assertEquals(NEW_LABEL, AnnotationValueHandler.getStringValue(dataObject, Label.class.getName()));
    assertEquals(NEW_DESCRIPTION, AnnotationValueHandler.getStringValue(dataObject, Description.class.getName()));
    verify(dataModelerEvent, times(5)).fire(any(DataModelerEvent.class));
}
Also used : Path(org.uberfire.backend.vfs.Path) DataModelerEvent(org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) HashMap(java.util.HashMap) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 10 with DataModelerEvent

use of org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent in project kie-wb-common by kiegroup.

the class AddMethodCommand method execute.

@Override
public void execute() {
    if (method != null) {
        dataObject.addMethod(method);
        DataModelerEvent event = new DataObjectChangeEvent().withChangeType(ChangeType.METHOD_ADD_CHANGE).withOldValue(null).withNewValue(method).withContextId(getContext().getContextId()).withSource(getSource()).withCurrentDataObject(getDataObject()).withCurrentMethod(method);
        notifyChange(event);
    }
}
Also used : DataModelerEvent(org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent) DataObjectChangeEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectChangeEvent)

Aggregations

DataModelerEvent (org.kie.workbench.common.screens.datamodeller.events.DataModelerEvent)10 Test (org.junit.Test)5 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)5 DataObjectChangeEvent (org.kie.workbench.common.screens.datamodeller.events.DataObjectChangeEvent)5 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)5 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)3 HashMap (java.util.HashMap)2 Path (org.uberfire.backend.vfs.Path)2 DataModelerContext (org.kie.workbench.common.screens.datamodeller.client.DataModelerContext)1 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)1 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)1