use of org.kie.workbench.common.forms.editor.model.FormModelerContent in project kie-wb-common by kiegroup.
the class FormEditorServiceImplTest method testRename.
private void testRename(boolean saveBeforeRenaming) {
FormModelerContent content = mock(FormModelerContent.class);
doReturn(path).when(formEditorService).save(any(Path.class), any(FormModelerContent.class), any(Metadata.class), anyString());
doReturn(content).when(formEditorService).constructContent(any(Path.class), any(Overview.class));
when(content.getDefinition()).thenReturn(mock(FormDefinition.class));
Metadata metadata = mock(Metadata.class);
FormModelerContent resultContent = formEditorService.rename(path, NEW_FORM_NAME, COMMIT_COMMENT, saveBeforeRenaming, content, metadata);
assertSame(content, resultContent);
VerificationMode constructContentCalls = saveBeforeRenaming ? never() : times(1);
verify(formEditorService, constructContentCalls).constructContent(eq(path), any(Overview.class));
verify(formEditorService).save(eq(path), eq(content), eq(metadata), eq(COMMIT_COMMENT));
verify(renameService).rename(eq(path), eq(NEW_FORM_NAME), eq(COMMIT_COMMENT));
}
use of org.kie.workbench.common.forms.editor.model.FormModelerContent in project kie-wb-common by kiegroup.
the class FormEditorHelperTest method testGetContent.
@Test
public void testGetContent() {
FormModelerContent resContent = formEditorHelper.getContent();
assertEquals(resContent, content);
}
use of org.kie.workbench.common.forms.editor.model.FormModelerContent in project kie-wb-common by kiegroup.
the class FormEditorPresenterAbstractTest method loadContent.
protected void loadContent() {
when(formDefinitionResourceType.getSuffix()).thenReturn("form.frm");
when(formDefinitionResourceType.accept(path)).thenReturn(true);
when(editorFieldLayoutComponents.get()).thenAnswer(invocationOnMock -> mock(EditorFieldLayoutComponent.class));
when(formEditorService.loadContent(any())).then(invocation -> serviceLoad());
editorServiceCallerMock = new CallerMock<>(formEditorService);
editorHelper = spy(new TestFormEditorHelper(fieldManager, editorFieldLayoutComponents));
when(layoutEditorMock.getLayout()).thenReturn(new LayoutTemplate());
when(menuBuilderMock.addSave(any(MenuItem.class))).thenReturn(menuBuilderMock);
when(menuBuilderMock.addCopy(any(ObservablePath.class), any(DefaultFileNameValidator.class))).thenReturn(menuBuilderMock);
when(menuBuilderMock.addRename(any(ObservablePath.class), any(DefaultFileNameValidator.class))).thenReturn(menuBuilderMock);
when(menuBuilderMock.addRename(any(Command.class))).thenReturn(menuBuilderMock);
when(menuBuilderMock.addDelete(any(ObservablePath.class))).thenReturn(menuBuilderMock);
when(menuBuilderMock.addNewTopLevelMenu(any(MenuItem.class))).thenReturn(menuBuilderMock);
when(menuBuilderMock.build()).thenReturn(mock(Menus.class));
when(versionRecordManager.getCurrentPath()).thenReturn(path);
when(translationService.format(anyString(), anyString())).thenReturn("");
showAssetUsagesDisplayer = spy(new ShowAssetUsagesDisplayer(assetUsagesDisplayerView, translationService, new CallerMock<>(assetsUsagService)));
when(assetUsagesDisplayerView.getDefaultMessageContainer()).thenReturn(mock(HTMLElement.class));
when(assetsUsagService.getAssetUsages(anyString(), any(), any())).thenReturn(assetUsages);
deletePopUpPresenter = spy(new DeletePopUpPresenter(deletePopUpView, toggleCommentPresenter));
presenter = new FormEditorPresenter(view, modelChangesDisplayer, formDefinitionResourceType, editorServiceCallerMock, translationService, editorFieldLayoutComponents, showAssetUsagesDisplayer) {
{
kieView = mock(KieEditorWrapperView.class);
versionRecordManager = FormEditorPresenterAbstractTest.this.versionRecordManager;
editorHelper = FormEditorPresenterAbstractTest.this.editorHelper;
busyIndicatorView = mock(BusyIndicatorView.class);
overviewWidget = mock(OverviewWidgetPresenter.class);
layoutEditor = layoutEditorMock;
layoutDragComponentPalette = layoutDragComponentPaletteMock;
layoutFocusEvent = layoutFocusEventMock;
htmlLayoutDragComponent = FormEditorPresenterAbstractTest.this.htmlLayoutDragComponent;
notification = notificationEvent;
fileMenuBuilder = menuBuilderMock;
workbenchContext = FormEditorPresenterAbstractTest.this.workbenchContext;
projectController = FormEditorPresenterAbstractTest.this.projectController;
deletePopUpPresenter = FormEditorPresenterAbstractTest.this.deletePopUpPresenter;
renamePopUpPresenter = FormEditorPresenterAbstractTest.this.renamePopUpPresenter;
alertsButtonMenuItemBuilder = FormEditorPresenterAbstractTest.this.alertsButtonMenuItemBuilder;
formEditorContext = mock(FormEditorContext.class);
}
@Override
public void doLoadContent(FormModelerContent content) {
super.doLoadContent(content);
employeeFields.addAll(editorHelper.getAvailableFields().values());
}
@Override
protected void addSourcePage() {
}
};
presenter.onStartup(path, mock(PlaceRequest.class));
assertTrue("There should exist base field draggables", editorHelper.getBaseFieldsDraggables().size() > 0);
}
use of org.kie.workbench.common.forms.editor.model.FormModelerContent in project kie-wb-common by kiegroup.
the class FormEditorServiceImpl method rename.
@Override
public FormModelerContent rename(Path path, String newFileName, String commitMessage, boolean saveBeforeRenaming, FormModelerContent content, Metadata metadata) {
FormModelerContent contentToSave = content;
if (!saveBeforeRenaming) {
contentToSave = constructContent(path, content.getOverview());
}
contentToSave.getDefinition().setName(newFileName);
save(path, contentToSave, metadata, commitMessage);
renameService.rename(path, newFileName, commitMessage);
return contentToSave;
}
use of org.kie.workbench.common.forms.editor.model.FormModelerContent in project kie-wb-common by kiegroup.
the class FormEditorServiceImpl method constructContent.
@Override
protected FormModelerContent constructContent(Path path, Overview overview) {
try {
org.uberfire.java.nio.file.Path kiePath = Paths.convert(path);
FormDefinition form = findForm(kiePath);
FormModelerContent formModelConent = new FormModelerContent();
formModelConent.setDefinition(form);
formModelConent.setPath(path);
formModelConent.setOverview(overview);
FormEditorRenderingContext context = createRenderingContext(form, path);
formModelConent.setRenderingContext(context);
if (Optional.ofNullable(form.getModel()).isPresent()) {
FormModel formModel = form.getModel();
Optional<FormModelHandler> modelHandlerOptional = getHandlerForForm(form, path);
if (modelHandlerOptional.isPresent()) {
FormModelHandler formModelHandler = modelHandlerOptional.get();
FormModelSynchronizationResult synchronizationResult = formModelHandler.synchronizeFormModel();
formModel.getProperties().forEach(property -> {
Optional<FieldDefinition> fieldOptional = Optional.ofNullable(form.getFieldByBinding(property.getName()));
if (!fieldOptional.isPresent()) {
synchronizationResult.resolveConflict(property.getName());
}
});
formModelConent.setSynchronizationResult(synchronizationResult);
}
}
resourceOpenedEvent.fire(new ResourceOpenedEvent(path, sessionInfo));
return formModelConent;
} catch (Exception e) {
log.warn("Error loading form " + path.toURI(), e);
}
return null;
}
Aggregations