Search in sources :

Example 61 with DataObject

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

the class DataModelerScreenPresenter method getSaveCommand.

private ParameterizedCommand<String> getSaveCommand(final JavaTypeInfo newTypeInfo, final Path path) {
    return new ParameterizedCommand<String>() {

        @Override
        public void execute(final String commitMessage) {
            final DataObject modifiedDataObject = getModifiedDataObject();
            view.showSaving();
            if (newTypeInfo != null) {
                modelerService.call(getSaveSuccessCallback(path), new DataModelerErrorCallback(Constants.INSTANCE.modelEditor_saving_error())).saveSource(getSource(), path, modifiedDataObject, metadata, commitMessage, newTypeInfo.getPackageName(), newTypeInfo.getName());
            } else {
                modelerService.call(getSaveSuccessCallback(path), new DataModelerErrorCallback(Constants.INSTANCE.modelEditor_saving_error())).saveSource(getSource(), path, modifiedDataObject, metadata, commitMessage);
            }
        }
    };
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand)

Example 62 with DataObject

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

the class DataObjectBrowserTest method onDataObjectFieldDeleted.

@Test
public void onDataObjectFieldDeleted() {
    DataObjectBrowser dataObjectBrowser = spy(createBrowser());
    DataModelerContext context = createContext();
    context.setContextId("contextId");
    dataObjectBrowser.setContext(context);
    DataObject dataObject = mock(DataObject.class);
    dataObjectBrowser.setDataObject(dataObject);
    DataObjectFieldDeletedEvent event = new DataObjectFieldDeletedEvent();
    event.setContextId("contextId");
    Mockito.reset(dataObjectBrowser);
    dataObjectBrowser.onDataObjectFieldDeleted(event);
    verify(dataObjectBrowser, times(1)).setDataObject(dataObject);
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataObjectFieldDeletedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectFieldDeletedEvent) DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 63 with DataObject

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

Example 64 with DataObject

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

the class DataObjectBrowserTest method addInvalidPropertyTest.

@Test
public void addInvalidPropertyTest() {
    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 NOT correct
    Map<String, Boolean> validationResult = new HashMap<String, Boolean>();
    validationResult.put("field4", false);
    when(validationService.evaluateJavaIdentifiers(new String[] { "field4" })).thenReturn(validationResult);
    // emulate the user pressing the create button in the new field popup
    newFieldPopup.onCreate();
    // the error message should have been set
    verify(newFieldPopupView, times(1)).setErrorMessage(anyString());
    verify(view, times(1)).setTableHeight(DataObjectBrowser.DataObjectBrowserHelper.calculateTableHeight(3));
    // no property should have been added.
    assertEquals(3, dataObject.getProperties().size());
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) HashMap(java.util.HashMap) DataModelerContext(org.kie.workbench.common.screens.datamodeller.client.DataModelerContext) DomainEditorBaseTest(org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest) Test(org.junit.Test)

Example 65 with DataObject

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

the class JPADataObjectEditorTest method changeToPersistableTest.

private void changeToPersistableTest(PopupActions action) {
    JPADataObjectEditor objectEditor = createObjectEditor();
    // load the editor
    objectEditor.onContextChange(context);
    // by construction the currently loaded data object org.test.TestObject1 is not persistable.
    DataObject dataObject = context.getDataObject();
    // emulate user interaction setting TestObject1 as persistable
    objectEditor.onEntityFieldChange("true");
    // The confirmation popup should have been raised since the DataObject has no @Id
    verify(view, times(1)).showYesNoCancelPopup(anyString(), anyString(), any(Command.class), anyString(), eq(ButtonType.PRIMARY), any(Command.class), anyString(), eq(ButtonType.DANGER), any(Command.class), anyString(), eq(ButtonType.DEFAULT));
    if (action == PopupActions.YES) {
        // emulate the YES response form user input and the corresponding verifications.
        objectEditor.doEntityFieldChange(true, true);
        // the object should have been marked as @Entity
        assertNotNull(dataObject.getAnnotation(JPADomainAnnotations.JAVAX_PERSISTENCE_ENTITY_ANNOTATION));
        ObjectProperty idField = dataObject.getProperty("id");
        // the Identifier field should have been created.
        assertNotNull(idField);
        assertNotNull(idField.getAnnotation(JPADomainAnnotations.JAVAX_PERSISTENCE_ID_ANNOTATION));
        assertNotNull(idField.getAnnotation(JPADomainAnnotations.JAVAX_PERSISTENCE_SEQUENCE_GENERATOR_ANNOTATION));
        assertNotNull(idField.getAnnotation(JPADomainAnnotations.JAVAX_PERSISTENCE_GENERATED_VALUE_ANNOTATION));
    } else if (action == PopupActions.NO) {
        // emulate the NO response form user input and the corresponding verifications.
        objectEditor.doEntityFieldChange(true, false);
        // the object should have been marked as @Entity
        assertNotNull(dataObject.getAnnotation(JPADomainAnnotations.JAVAX_PERSISTENCE_ENTITY_ANNOTATION));
        // but the @Id field was not created
        assertNull(dataObject.getProperty("id"));
    } else if (action == PopupActions.CANCEL) {
        // emulate the CANCEL response form user input and the corresponding verifications.
        // no @Entity annotation or id field should have been created.
        assertNull(dataObject.getAnnotation(JPADomainAnnotations.JAVAX_PERSISTENCE_ENTITY_ANNOTATION));
        assertNull(dataObject.getProperty("id"));
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Command(org.uberfire.mvp.Command)

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