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);
}
}
};
}
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);
}
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));
}
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());
}
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"));
}
}
Aggregations