Commit 7c0d82c4 authored by Adrien's avatar Adrien Committed by GitHub

feat(explorer tests) improve bdm test robustness (#1451)

parent 26628986
/**
* 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;
import java.util.function.Supplier;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
public class ConditionBuilder {
private Supplier<Boolean> test;
private Supplier<String> failureMessageSupplier;
public ConditionBuilder withTest(Supplier<Boolean> test) {
this.test = test;
return this;
}
public ConditionBuilder withFailureMessage(Supplier<String> failureMessageSupplier) {
this.failureMessageSupplier = failureMessageSupplier;
return this;
}
public ICondition create() {
return new ICondition() {
@Override
public boolean test() throws Exception {
return test.get();
}
@Override
public void init(SWTBot bot) {
}
@Override
public String getFailureMessage() {
return failureMessageSupplier.get();
}
};
}
}
......@@ -14,12 +14,12 @@
*/
package org.bonitasoft.studio.swtbot.framework.projectExplorer;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.swtbot.framework.BotBase;
import org.bonitasoft.studio.swtbot.framework.ConditionBuilder;
import org.bonitasoft.studio.swtbot.framework.bdm.DefineBdmWizardBot;
import org.bonitasoft.studio.swtbot.framework.connector.ConnectorDefinitionWizardBot;
import org.bonitasoft.studio.swtbot.framework.connector.ConnectorImplementationWizardBot;
......@@ -27,7 +27,6 @@ import org.bonitasoft.studio.swtbot.framework.diagram.BotProcessDiagramPerspecti
import org.bonitasoft.studio.swtbot.framework.organization.BotManageOrganizationWizard;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
......@@ -162,71 +161,35 @@ public class ProjectExplorerBot extends BotBase {
}
public ICondition nodeAvailable(SWTBotTreeItem item, String node) {
return new ICondition() {
@Override
public boolean test() throws Exception {
try {
item.getNode(node);
return true;
} catch (WidgetNotFoundException e) {
return false;
}
}
@Override
public void init(SWTBot bot) {
}
@Override
public String getFailureMessage() {
return String.format("The node %s of '%s' isn't available", node, item);
}
};
return new ConditionBuilder()
.withTest(() -> {
try {
item.getNode(node);
return true;
} catch (WidgetNotFoundException e) {
return false;
}
})
.withFailureMessage(() -> String.format("The node %s of '%s' isn't available", node, item))
.create();
}
public ICondition contextMenuAvailable(SWTBotTreeItem item, String menu) {
return new ICondition() {
private List<String> menuItems;
@Override
public boolean test() throws Exception {
menuItems = item.contextMenu().menuItems();
return menuItems.contains(menu);
}
@Override
public void init(SWTBot bot) {
}
@Override
public String getFailureMessage() {
return String.format("The menu '%s' of '%s' isn't available (%s)", menu, item, menuItems);
}
};
return new ConditionBuilder()
.withTest(() -> item.contextMenu().menuItems().contains(menu))
.withFailureMessage(() -> String.format("The menu '%s' of '%s' isn't available (%s)", menu, item,
item.contextMenu().menuItems()))
.create();
}
public void waitUntilActiveEditorTitleIs(String title, Optional<String> extension) {
bot.waitUntil(new ICondition() {
String expectedTitle = extension.isPresent() ? title + extension.get() : title;
@Override
public boolean test() throws Exception {
return Objects.equals(bot.activeEditor().getTitle(), expectedTitle);
}
@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", expectedTitle, actualTitle);
}
});
String expectedTitle = extension.isPresent() ? title + extension.get() : title;
ICondition condition = new ConditionBuilder()
.withTest(() -> Objects.equals(bot.activeEditor().getTitle(), expectedTitle))
.withFailureMessage(() -> String.format("The active editor title should be %s instead of %s", expectedTitle,
bot.activeEditor().getTitle()))
.create();
bot.waitUntil(condition);
}
}
......@@ -20,11 +20,13 @@ import org.bonitasoft.engine.bdm.model.field.FieldType;
import org.bonitasoft.studio.businessobject.core.repository.BusinessObjectModelRepositoryStore;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.engine.BOSEngineManager;
import org.bonitasoft.studio.swtbot.framework.ConditionBuilder;
import org.bonitasoft.studio.swtbot.framework.bdm.DefineBdmWizardBot;
import org.bonitasoft.studio.swtbot.framework.projectExplorer.ProjectExplorerBot;
import org.bonitasoft.studio.swtbot.framework.rule.SWTGefBotRule;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
......@@ -57,8 +59,16 @@ public class ProjectExplorerBdmIT {
.cancel();
projectExplorerBot.bdm().deployBdm();
projectExplorerBot.bdm().deleteBdm();
assertThat(repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class).getChild("bom.xml"))
.isNull();
validateBdmIsDeleted();
}
private void validateBdmIsDeleted() {
ICondition bdmDeletedCondition = new ConditionBuilder()
.withTest(() -> repositoryAccessor.getRepositoryStore(BusinessObjectModelRepositoryStore.class)
.getChild("bom.xml") == null)
.withFailureMessage(() -> "Business data model has not been deleted.")
.create();
bot.waitUntil(bdmDeletedCondition);
}
private void createBdmIfRequired() {
......
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