Commit 57872dec authored by Adrien's avatar Adrien Committed by Romain Bioteau

feat(project explorer) test UID artifact creation (#1424)

parent ba5b7117
......@@ -8,5 +8,6 @@ bin.includes = META-INF/,\
messages*.properties,\
icons/,\
lib/ui-designer-backend-contract.jar,\
fragment.e4xmi
fragment.e4xmi,\
resources/CustomWidgetTemplate.json
source.. = src/
......@@ -22,6 +22,7 @@ import java.util.List;
import java.util.stream.Collectors;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.designer.UIDesignerPlugin;
import org.bonitasoft.studio.designer.core.PageDesignerURLFactory;
import org.bonitasoft.studio.designer.core.repository.WebWidgetFileStore;
import org.bonitasoft.studio.designer.core.repository.WebWidgetRepositoryStore;
......@@ -59,8 +60,13 @@ public class CreateCustomWidgetOperation extends CreateUIDArtifactOperation {
@Override
protected JSONObject createBody() throws InvocationTargetException {
try (InputStream inputStream = CreateCustomWidgetOperation.class
.getResourceAsStream("/CustomWidgetTemplate.json")) {
try (InputStream inputStream = UIDesignerPlugin.getDefault().getBundle()
.getResource("/resources/CustomWidgetTemplate.json")
.openStream()) {
if (inputStream == null) {
throw new IOException("Failed to retrieve CustomWidgetTemplate.json");
}
JSONObject body = new JSONObject(IoUtils.toString(inputStream));
body.put("name", getNewName());
return body;
......
......@@ -16,6 +16,7 @@ package org.bonitasoft.studio.preferences.browser;
import java.net.URL;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.preferences.dialog.BonitaPreferenceDialog;
import org.bonitasoft.studio.preferences.i18n.Messages;
......@@ -62,8 +63,9 @@ public class OpenBrowserOperation implements Runnable {
protected boolean browserIsSet() {
if (noExternalBrowserSet()) {
if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.noBrowserFoundTitle,
Messages.noBrowserFoundMsg)) {
if (!FileActionDialog.getDisablePopup()
&& MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.noBrowserFoundTitle,
Messages.noBrowserFoundMsg)) {
final BonitaPreferenceDialog dialog = new BonitaPreferenceDialog(Display.getDefault().getActiveShell());
dialog.create();
dialog.setSelectedPreferencePage(BonitaPreferenceDialog.WEB_BROWSER_PAGE_ID);
......
......@@ -44,6 +44,7 @@ import org.bonitasoft.studio.tests.connectors.TestTestConnectorOperation;
import org.bonitasoft.studio.tests.connectors.TestWebserviceVersionForBPMNImport;
import org.bonitasoft.studio.tests.data.DataRefactorIT;
import org.bonitasoft.studio.tests.deploy.TestDeployCommand;
import org.bonitasoft.studio.tests.designer.UIDArtifactCreationIT;
import org.bonitasoft.studio.tests.document.RefactorDocumentOperationTest;
import org.bonitasoft.studio.tests.document.TestDocumentRefactoring;
import org.bonitasoft.studio.tests.engine.TestJavaDoc;
......@@ -143,7 +144,8 @@ import org.junit.runners.Suite;
ExportBarIT.class,
UIDesignerWorkspaceIntegrationIT.class,
CloseAllEditors.class,
TestMessageRefactoring.class
TestMessageRefactoring.class,
UIDArtifactCreationIT.class
})
public class IntegrationTestSuite {
......
......@@ -86,7 +86,8 @@ Require-Bundle: org.eclipse.ui.workbench,
org.bonitasoft.studio.jpdl,
org.bonitasoft.studio.migration,
org.bonitasoft.studio.validation,
org.bonitasoft.studio.model.edit.custom
org.bonitasoft.studio.model.edit.custom,
org.bonitasoft.studio.ui
Export-Package: org.bonitasoft.studio.tests,
org.bonitasoft.studio.tests.actors,
org.bonitasoft.studio.tests.api,
......@@ -102,6 +103,7 @@ Export-Package: org.bonitasoft.studio.tests,
org.bonitasoft.studio.tests.data,
org.bonitasoft.studio.tests.dependencies.handler,
org.bonitasoft.studio.tests.deploy,
org.bonitasoft.studio.tests.designer,
org.bonitasoft.studio.tests.diagram,
org.bonitasoft.studio.tests.dialog,
org.bonitasoft.studio.tests.document,
......
/*******************************************************************************
* Copyright (C) 2018 BonitaSoft S.A.
* BonitaSoft is a trademark of BonitaSoft SA.
* This software file is BONITASOFT CONFIDENTIAL. Not For Distribution.
* For commercial licensing information, contact:
* BonitaSoft, 32 rue Gustave Eiffel – 38000 Grenoble
* or BonitaSoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107
*******************************************************************************/
package org.bonitasoft.studio.tests.designer;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.designer.core.PageDesignerURLFactory;
import org.bonitasoft.studio.designer.core.operation.CreateCustomWidgetOperation;
import org.bonitasoft.studio.designer.core.operation.CreateLayoutOperation;
import org.bonitasoft.studio.designer.core.operation.CreatePageOperation;
import org.bonitasoft.studio.designer.core.operation.CreateUIDArtifactOperation;
import org.bonitasoft.studio.designer.core.repository.WebPageFileStore;
import org.bonitasoft.studio.designer.core.repository.WebPageRepositoryStore;
import org.bonitasoft.studio.designer.core.repository.WebWidgetFileStore;
import org.bonitasoft.studio.designer.core.repository.WebWidgetRepositoryStore;
import org.bonitasoft.studio.ui.util.StringIncrementer;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.Before;
import org.junit.Test;
public class UIDArtifactCreationIT {
private RepositoryAccessor repositoryAccessor;
@Before
public void init() {
repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
}
@Test
public void should_create_application_page() throws Exception {
CreatePageOperation createPageOperation = new CreatePageOperation(PageDesignerURLFactory.INSTANCE,
repositoryAccessor);
String newName = getPageNewName("page", CreateUIDArtifactOperation.DEFAULT_PAGE_NAME);
createPageOperation.run(new NullProgressMonitor());
assertThat(repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class).getChild(newName)).isNotNull();
}
@Test
public void should_create_layout() throws Exception {
CreateLayoutOperation createLayoutOperation = new CreateLayoutOperation(PageDesignerURLFactory.INSTANCE,
repositoryAccessor);
String newName = getPageNewName("layout", CreateUIDArtifactOperation.DEFAULT_LAYOUT_NAME);
createLayoutOperation.run(new NullProgressMonitor());
assertThat(repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class).getChild(newName))
.isNotNull();
}
@Test
public void should_create_custom_widget() throws Exception {
CreateCustomWidgetOperation createCustomWidgetOperation = new CreateCustomWidgetOperation(
PageDesignerURLFactory.INSTANCE, repositoryAccessor);
String newName = getCustomWidgetNewName();
createCustomWidgetOperation.run(new NullProgressMonitor());
String newArtifactId = createCustomWidgetOperation.getNewArtifactId();
assertThat(newArtifactId.toLowerCase()).endsWith(newName.toLowerCase());
assertThat(repositoryAccessor.getRepositoryStore(WebWidgetRepositoryStore.class).getChild(newArtifactId))
.isNotNull();
}
private String getPageNewName(String artifactType, String defaultName) {
List<String> existingPages = repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class).getChildren()
.stream()
.filter(store -> Objects.equals(store.getType(), artifactType))
.map(WebPageFileStore::getDisplayName)
.collect(Collectors.toList());
return StringIncrementer.getIncrementedString(defaultName, existingPages);
}
private String getCustomWidgetNewName() {
List<String> existingWidgets = repositoryAccessor.getRepositoryStore(WebWidgetRepositoryStore.class).getChildren()
.stream()
.map(WebWidgetFileStore::getDisplayName)
.collect(Collectors.toList());
return StringIncrementer.getIncrementedString(CreateUIDArtifactOperation.DEFAULT_WIDGET_NAME, existingWidgets);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment