Commit 66a89577 authored by Adrien's avatar Adrien Committed by GitHub

feat(project explorer) test application actions (#1416)

parent 3d37440c
......@@ -481,20 +481,7 @@
commandId="org.bonitasoft.studio.renameCommand"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="activeMenuSelection">
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.application.renamablePropertyTester.isRenamable">
</test>
</iterate>
</and>
</with>
checkEnabled="true">
</visibleWhen>
</command>
<separator
......@@ -517,20 +504,7 @@
label="%deploy"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="activeMenuSelection">
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.application.deployablePropertyTester.isDeployable">
</test>
</iterate>
</and>
</with>
checkEnabled="true">
</visibleWhen>
</command>
</menuContribution>
......@@ -1391,20 +1365,6 @@
properties="isBonitaProject"
type="org.eclipse.core.resources.IResource">
</propertyTester>
<propertyTester
class="org.bonitasoft.studio.application.property.tester.DeployableResourcePropertyTester"
id="org.bonitasoft.studio.application.deployablePropertyTester"
namespace="org.bonitasoft.studio.application.deployablePropertyTester"
properties="isDeployable"
type="org.eclipse.core.runtime.IAdaptable">
</propertyTester>
<propertyTester
class="org.bonitasoft.studio.application.property.tester.RenamableResourcePropertyTester"
id="org.bonitasoft.studio.application.renamablePropertyTester"
namespace="org.bonitasoft.studio.application.renamablePropertyTester"
properties="isRenamable"
type="org.eclipse.core.runtime.IAdaptable">
</propertyTester>
<propertyTester
class="org.bonitasoft.studio.application.property.tester.GroovySrcPropertyTester"
id="org.bonitasoft.studio.groovy.ui.GroovySrcPropertyTester"
......
......@@ -14,27 +14,54 @@
*/
package org.bonitasoft.studio.application.handler;
import java.util.Optional;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.bonitasoft.studio.common.repository.model.IDeployable;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.IStructuredSelection;
public class DeployHandler extends AbstractHandler {
private FileStoreFinder fileStoreFinder;
public DeployHandler() {
fileStoreFinder = new FileStoreFinder();
}
private FileStoreFinder selectionFinder = new FileStoreFinder();
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
fileStoreFinder
selectionFinder
.findElementToDeploy(RepositoryManager.getInstance().getCurrentRepository())
.ifPresent(IDeployable::deploy);
return null;
}
@Override
public boolean isEnabled() {
Optional<IStructuredSelection> selection = selectionFinder.getCurrentStructuredSelection();
if (selection.isPresent()
&& selection.get().toList().size() == 1
&& selection.get().getFirstElement() instanceof IAdaptable) {
IResource resource = ((IAdaptable) selection.get().getFirstElement()).getAdapter(IResource.class);
if (resource != null) {
Repository currentRepository = RepositoryManager.getInstance().getCurrentRepository();
boolean resourceMatch = selectionFinder.findElementToDeploy(resource.getName(), currentRepository)
.isPresent();
if (!resourceMatch) {
IProject project = resource.getProject();
if (project != null) {
resourceMatch = selectionFinder.findElementToDeploy(project.getName(), currentRepository)
.isPresent();
}
}
return resourceMatch;
}
}
return false;
}
}
......@@ -14,23 +14,42 @@
*/
package org.bonitasoft.studio.application.handler;
import java.util.Objects;
import java.util.Optional;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.IStructuredSelection;
public class RenameHandler extends AbstractHandler {
private FileStoreFinder elementToRenameFinder = new FileStoreFinder();
private FileStoreFinder selectionFinder = new FileStoreFinder();
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Repository repo = RepositoryManager.getInstance().getCurrentRepository();
elementToRenameFinder.findElementToRename(repo)
selectionFinder.findElementToRename(repo)
.ifPresent(elementToRename -> elementToRename.retrieveNewName().ifPresent(elementToRename::rename));
return null;
}
@Override
public boolean isEnabled() {
Repository currentRepository = RepositoryManager.getInstance().getCurrentRepository();
Optional<IStructuredSelection> selection = selectionFinder.getCurrentStructuredSelection();
if (selection.isPresent() && selection.get().toList().size() == 1) {
if (selection.get().getFirstElement() instanceof IProject) {
IProject project = (IProject) selection.get().getFirstElement();
return Objects.equals(project, currentRepository.getProject());
}
return selectionFinder.findElementToRename(RepositoryManager.getInstance().getCurrentRepository()).isPresent();
}
return false;
}
}
/**
* Copyright (C) 2018 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.application.property.tester;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
public class DeployableResourcePropertyTester extends PropertyTester {
private FileStoreFinder fileStoreFinder;
public DeployableResourcePropertyTester() {
fileStoreFinder = new FileStoreFinder();
}
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
Repository currentRepository = RepositoryManager.getInstance().getCurrentRepository();
IResource resource = ((IAdaptable) receiver).getAdapter(IResource.class);
if (resource != null) {
boolean resourceMatch = fileStoreFinder.findElementToDeploy(resource.getName(), currentRepository).isPresent();
if (!resourceMatch) {
IProject project = resource.getProject();
if (project != null) {
resourceMatch = fileStoreFinder.findElementToDeploy(project.getName(), currentRepository).isPresent();
}
}
return resourceMatch;
}
return false;
}
}
......@@ -96,7 +96,7 @@ public class FileStoreFinder {
});
}
protected Optional<IStructuredSelection> getCurrentStructuredSelection() {
public Optional<IStructuredSelection> getCurrentStructuredSelection() {
return getExplorerViewPart()
.map(vp -> vp.getViewSite().getSelectionProvider().getSelection())
.filter(IStructuredSelection.class::isInstance)
......
......@@ -12,36 +12,37 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.application.property.tester;
package org.bonitasoft.studio.la.application.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.la.application.repository.ApplicationFileStore;
import org.bonitasoft.studio.la.application.repository.ApplicationRepositoryStore;
public class RenamableResourcePropertyTester extends PropertyTester {
public class ImportApplicationAction {
private FileStoreFinder fileStoreFinder;
public RenamableResourcePropertyTester() {
fileStoreFinder = new FileStoreFinder();
}
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
Repository currentRepository = RepositoryManager.getInstance().getCurrentRepository();
IResource resource = ((IAdaptable) receiver).getAdapter(IResource.class);
if (Objects.equals(resource, currentRepository.getProject())) {
return true;
public Optional<ApplicationFileStore> importApplication(RepositoryAccessor repositoryAccessor, File file) {
ApplicationRepositoryStore repositoryStore = repositoryAccessor.getRepositoryStore(ApplicationRepositoryStore.class);
if (repositoryStore.getChildren().stream()
.anyMatch(applicationFileStore -> Objects.equals(applicationFileStore.getName(), file.getName()))) {
if (FileActionDialog.overwriteQuestion(file.getName())) {
repositoryStore.getChild(file.getName()).delete();
} else {
return Optional.empty();
}
}
if (resource != null) {
return fileStoreFinder.findElementToRename(resource, currentRepository).isPresent();
try (FileInputStream fis = new FileInputStream(file)) {
ApplicationFileStore applicationFileStore = repositoryStore.importInputStream(file.getName(), fis);
return Optional.ofNullable(applicationFileStore);
} catch (final IOException e) {
throw new RuntimeException("Failed to import the application descriptor", e);
}
return false;
}
}
......@@ -18,16 +18,12 @@ import static org.bonitasoft.studio.ui.wizard.WizardBuilder.newWizard;
import static org.bonitasoft.studio.ui.wizard.WizardPageBuilder.newPage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.la.application.core.ImportApplicationAction;
import org.bonitasoft.studio.la.application.repository.ApplicationFileStore;
import org.bonitasoft.studio.la.application.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.application.ui.control.ImportApplicationPage;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.ui.wizard.WizardBuilder;
......@@ -62,23 +58,7 @@ public class ImportApplicationhandler extends AbstractHandler {
private Optional<ApplicationFileStore> finish(ImportApplicationPage importApplicationPage,
RepositoryAccessor repositoryAccessor) {
final File file = new File(importApplicationPage.getFilePath());
final ApplicationRepositoryStore repositoryStore = repositoryAccessor
.getRepositoryStore(ApplicationRepositoryStore.class);
if (repositoryStore.getChildren().stream()
.anyMatch(applicationFileStore -> Objects.equals(applicationFileStore.getName(), file.getName()))) {
if (FileActionDialog.overwriteQuestion(file.getName())) {
repositoryStore.getChild(file.getName()).delete();
} else {
return Optional.empty();
}
}
try (FileInputStream fis = new FileInputStream(file)) {
final ApplicationFileStore applicationFileStore = repositoryStore.importInputStream(file.getName(), fis);
return Optional.ofNullable(applicationFileStore);
} catch (final IOException e) {
throw new RuntimeException("Failed to import the application descriptor", e);
}
return new ImportApplicationAction().importApplication(repositoryAccessor, file);
}
@Override
......
......@@ -82,6 +82,7 @@ Export-Package: org.bonitasoft.studio.swtbot.framework,
org.bonitasoft.studio.swtbot.framework.organization,
org.bonitasoft.studio.swtbot.framework.projectExplorer,
org.bonitasoft.studio.swtbot.framework.projectExplorer.bdm,
org.bonitasoft.studio.swtbot.framework.projectExplorer.la,
org.bonitasoft.studio.swtbot.framework.projectExplorer.organization,
org.bonitasoft.studio.swtbot.framework.rule,
org.bonitasoft.studio.swtbot.framework.widget
......
......@@ -15,12 +15,14 @@
package org.bonitasoft.studio.swtbot.framework.projectExplorer;
import java.util.List;
import java.util.Objects;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.swtbot.framework.BotBase;
import org.bonitasoft.studio.swtbot.framework.bdm.DefineBdmWizardBot;
import org.bonitasoft.studio.swtbot.framework.organization.BotManageOrganizationWizard;
import org.bonitasoft.studio.swtbot.framework.projectExplorer.bdm.BDMProjectExplorerBot;
import org.bonitasoft.studio.swtbot.framework.projectExplorer.la.LivingApplicationProjectExplorerBot;
import org.bonitasoft.studio.swtbot.framework.projectExplorer.organization.OrganizationProjectExplorerBot;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.swt.finder.SWTBot;
......@@ -39,15 +41,25 @@ public class ProjectExplorerBot extends BotBase {
}
public BotManageOrganizationWizard newOrganization() {
getProjectTreeItem().contextMenu().menu("New").menu("Organization...").click();
SWTBotTreeItem projectTreeItem = getProjectTreeItem();
bot.waitUntil(contextMenuAvailable(projectTreeItem, "New"));
projectTreeItem.contextMenu().menu("New").menu("Organization...").click();
return new BotManageOrganizationWizard(bot);
}
public DefineBdmWizardBot newBdm() {
getProjectTreeItem().contextMenu().menu("New").menu("Business Data Model...").click();
SWTBotTreeItem projectTreeItem = getProjectTreeItem();
bot.waitUntil(contextMenuAvailable(projectTreeItem, "New"));
projectTreeItem.contextMenu().menu("New").menu("Business Data Model...").click();
return new DefineBdmWizardBot(bot, org.bonitasoft.studio.businessobject.i18n.Messages.manageBusinessDataModelTitle);
}
public void newLivingApplication() {
SWTBotTreeItem projectTreeItem = getProjectTreeItem();
bot.waitUntil(contextMenuAvailable(projectTreeItem, "New"));
projectTreeItem.contextMenu().menu("New").menu("Application descriptor").click();
}
public OrganizationProjectExplorerBot organization() {
return new OrganizationProjectExplorerBot(bot);
}
......@@ -56,6 +68,10 @@ public class ProjectExplorerBot extends BotBase {
return new BDMProjectExplorerBot(bot);
}
public LivingApplicationProjectExplorerBot livingApplication() {
return new LivingApplicationProjectExplorerBot(bot);
}
public SWTBotTreeItem getProjectTreeItem() {
return getProjectExplorerTree().getTreeItem(projectName);
}
......@@ -121,4 +137,24 @@ public class ProjectExplorerBot extends BotBase {
};
}
public void waitUntilActiveEditorTitleIs(String title) {
bot.waitUntil(new ICondition() {
@Override
public boolean test() throws Exception {
return Objects.equals(bot.activeEditor().getTitle(), title + ".xml");
}
@Override
public void init(SWTBot bot) {
}
@Override
public String getFailureMessage() {
String actualTitle = bot.activeEditor().getTitle();
return String.format("The active editor title should be %s instead of %s", title + ".xml", actualTitle);
}
});
}
}
/**
* Copyright (C) 2018 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.swtbot.framework.projectExplorer.la;
import org.bonitasoft.studio.swtbot.framework.BotDialog;
import org.bonitasoft.studio.swtbot.framework.projectExplorer.ProjectExplorerBot;
import org.bonitasoft.studio.ui.i18n.Messages;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
public class LivingApplicationProjectExplorerBot extends ProjectExplorerBot {
public LivingApplicationProjectExplorerBot(SWTGefBot bot) {
super(bot);
}
@Override
public void newLivingApplication() {
clickOnContextualMenu(getApplicationFolderTreeItem(), "New");
}
public void renameApplication(String oldName, String newName) {
clickOnContextualMenu(getApplicationTreeItem(oldName), "Rename...");
bot.waitUntil(Conditions.shellIsActive(Messages.rename));
SWTBotShell activeShell = bot.activeShell();
bot.text().setText(newName);
bot.button(IDialogConstants.OK_LABEL).click();
bot.waitUntil(Conditions.shellCloses(activeShell));
}
public void deleteApplication(String application) {
clickOnContextualMenu(getApplicationTreeItem(application), "Delete");
}
public BotDialog exportApplication() {
clickOnContextualMenu(getApplicationFolderTreeItem(), "Export...");
return new BotDialog(bot, org.bonitasoft.studio.la.i18n.Messages.exportApplicationDescriptor);
}
public void openApplication(String application) {
clickOnContextualMenu(getApplicationTreeItem(application), "Open");
}
public void deployApplication(String application) {
clickOnContextualMenu(getApplicationTreeItem(application), "Deploy");
bot.waitUntil(Conditions.shellIsActive(org.bonitasoft.studio.la.i18n.Messages.deployDoneTitle));
SWTBotShell activeShell = bot.activeShell();
bot.button(IDialogConstants.OK_LABEL).click();
bot.waitUntil(Conditions.shellCloses(activeShell));
}
public SWTBotTreeItem getApplicationTreeItem(String application) {
return getTreeItem(getApplicationFolderTreeItem(), addXmlExtension(application));
}
public SWTBotTreeItem getApplicationFolderTreeItem() {
return getTreeItem(getProjectTreeItem(), "Application descriptors");
}
private String addXmlExtension(String application) {
if (!application.endsWith(".xml")) {
application += ".xml";
}
return application;
}
}
......@@ -73,6 +73,7 @@ import org.bonitasoft.studio.tests.expressionEditor.TestPatternExpressionViewer;
import org.bonitasoft.studio.tests.iteration.MultiInstantiationIT;
import org.bonitasoft.studio.tests.processzoo.examples.TestWebPurchase;
import org.bonitasoft.studio.tests.projectExplorer.ProjectExplorerBdmIT;
import org.bonitasoft.studio.tests.projectExplorer.ProjectExplorerLivingApplicationIT;
import org.bonitasoft.studio.tests.projectExplorer.ProjectExplorerOrganizationIT;
import org.bonitasoft.studio.tests.properties.CallActivityMappingIT;
import org.bonitasoft.studio.tests.properties.TestConditionExpression;
......@@ -149,7 +150,8 @@ import org.junit.runners.Suite;
BPMNEventSubProcessExportImportTest.class,
OrganizationCreationTest.class,
ProjectExplorerOrganizationIT.class,
ProjectExplorerBdmIT.class
ProjectExplorerBdmIT.class,
ProjectExplorerLivingApplicationIT.class
})
public class SWTBotTestSuite {
......
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<applications xmlns="http://documentation.bonitasoft.com/application-xml-schema/1.0">
<application token="testExplorerApplication" version="1.0" profile="User" state="ACTIVATED" layout="custompage_defaultlayout" theme="custompage_bootstrapdefaulttheme">
<displayName>My App</displayName>
<applicationPages/>
<applicationMenus/>
</application>
</applications>
/**
* Copyright (C) 2018 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.