Search in sources :

Example 66 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class JPADataObjectEditorTest method tableNameChangeTest.

@Test
public void tableNameChangeTest() {
    JPADataObjectEditor objectEditor = createObjectEditor();
    // load the editor
    objectEditor.onContextChange(context);
    DataObject dataObject = context.getDataObject();
    // emulates user interaction
    objectEditor.onTableNameChange("NewTableName");
    // the field should have been updated according to the values entered on the ui
    assertEquals("NewTableName", AnnotationValueHandler.getStringValue(dataObject, Table.class.getName(), "name"));
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 67 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class MainDataObjectFieldEditorTest method loadDataObjectFieldTest.

@Test
public void loadDataObjectFieldTest() {
    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);
    // the view should be populated with the values from the field.
    verify(view, times(1)).setName(field.getName());
    verify(view, times(1)).setLabel(AnnotationValueHandler.getStringValue(field, Label.class.getName(), "value"));
    verify(view, times(1)).setDescription(AnnotationValueHandler.getStringValue(field, Description.class.getName(), "value"));
    verify(view, times(1)).initTypeList(anyList(), eq(field.getClassName()), eq(false));
    assertFalse(fieldEditor.isReadonly());
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 68 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class DroolsDataObjectFieldEditorTest method loadDataObjectFieldTest.

@Test
public void loadDataObjectFieldTest() {
    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);
    // the view should be populated with the values from the field.
    verify(view, times(1)).setEquals(true);
    verify(view, times(1)).setPosition("0");
    assertFalse(fieldEditor.isReadonly());
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 69 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject 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 70 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject 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)

Aggregations

DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)95 Test (org.junit.Test)45 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)40 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)29 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)28 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)21 ArrayList (java.util.ArrayList)17 AnnotationValuesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation)17 ClassAnnotation (org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation)17 EnumsAnnotation (org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation)17 MarkerAnnotation (org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation)17 PrimitivesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation)17 TestAnnotation (org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation)17 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)16 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)15 MethodImpl (org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl)12 List (java.util.List)11 TypeImpl (org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)11 Method (org.kie.workbench.common.services.datamodeller.core.Method)10 Generated (javax.annotation.Generated)8