Commit b4231b57 authored by Aurelien Pupier's avatar Aurelien Pupier
Browse files

Use waitUntil conditions to avoid aleatory behavior

parent 4d2e3a67
/** /**
* Copyright (C) 2010 BonitaSoft S.A. * Copyright (C) 2010-2014 Bonitasoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version. * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
...@@ -23,7 +20,9 @@ import org.eclipse.jface.dialogs.IDialogConstants; ...@@ -23,7 +20,9 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.eclipse.gef.finder.SWTBotGefTestCase; import org.eclipse.swtbot.eclipse.gef.finder.SWTBotGefTestCase;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor; import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -37,7 +36,6 @@ public class TestBug1682 extends SWTBotGefTestCase { ...@@ -37,7 +36,6 @@ public class TestBug1682 extends SWTBotGefTestCase {
protected Rectangle bounds; protected Rectangle bounds;
private int nbParts; private int nbParts;
private int nbPartsAfterDelete;
@Test @Test
public void testBug1682() throws Exception { public void testBug1682() throws Exception {
...@@ -45,37 +43,51 @@ public class TestBug1682 extends SWTBotGefTestCase { ...@@ -45,37 +43,51 @@ public class TestBug1682 extends SWTBotGefTestCase {
public void run() { public void run() {
try { try {
FormDiagramEditor editor = TestCommands.openFormEditorWithBaseTestForForm(); final FormDiagramEditor editor = TestCommands.openFormEditorWithBaseTestForForm();
nbParts = editor.getDiagramEditPart().getChildren().size(); nbParts = editor.getDiagramEditPart().getChildren().size();
} catch (Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}); });
/*The editor for process*/ /*The editor for process*/
String title = bot.activeEditor().getTitle(); final String title = bot.activeEditor().getTitle();
SWTBotGefEditor gefEditor = bot.gefEditor(title); final SWTBotGefEditor gefEditor = bot.gefEditor(title);
/*get the form in the first process (pool)*/ /*get the form in the first process (pool)*/
gefEditor.mainEditPart().children().get(0).select(); gefEditor.mainEditPart().children().get(0).select();
gefEditor.clickContextMenu("Delete"); gefEditor.clickContextMenu("Delete");
bot.button(IDialogConstants.OK_LABEL).click(); bot.button(IDialogConstants.OK_LABEL).click();
bot.waitUntil(new ICondition() {
private int nbPartsAfterDelete;
public boolean test() throws Exception {
Display.getDefault().syncExec(new Runnable() { Display.getDefault().syncExec(new Runnable() {
public void run() { public void run() {
try { try {
FormDiagramEditor editor = (FormDiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); final FormDiagramEditor editor = (FormDiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
nbPartsAfterDelete = editor.getDiagramEditPart().getChildren().size(); nbPartsAfterDelete = editor.getDiagramEditPart().getChildren().size();
} catch (Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}); });
return nbParts - 1 == nbPartsAfterDelete;
}
gefEditor.save(); public void init(final SWTBot bot) {
assertEquals("Part not deleted", nbParts - 1, nbPartsAfterDelete); }
public String getFailureMessage() {
return "Part not deleted";
}
});
gefEditor.save();
} }
} }
Supports Markdown
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