From d01607adb3209411e91620386846f0471be871e1 Mon Sep 17 00:00:00 2001 From: Andrea Zoitl Date: Mon, 9 Sep 2024 16:04:21 +0200 Subject: [PATCH] Creation of supporting SWTBot class SWTBotECC #377 - Creation of supporting SWTBot class SWTBotECC and related methods are moved here from Abstract4diacUITests - ECCEditorTests are adapted to this changes and are running again Addresses https://github.com/eclipse-4diac/4diac-ide/issues/377 --- .../ide/test/ui/Abstract4diacUITests.java | 72 --------------- .../ide/test/ui/fbtype/ECCEditorTests.java | 54 ++++++----- .../ide/test/ui/helpers/SWTBotECC.java | 90 +++++++++++++++++++ 3 files changed, 120 insertions(+), 96 deletions(-) create mode 100644 tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotECC.java diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Abstract4diacUITests.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Abstract4diacUITests.java index 556a7a4baa..168b086629 100644 --- a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Abstract4diacUITests.java +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Abstract4diacUITests.java @@ -20,19 +20,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import java.util.List; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotPropertySheet; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotSystemExplorer; import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper; import org.eclipse.fordiac.ide.test.ui.swtbot.SWT4diacGefBot; -import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefViewer; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacNatTable; -import org.eclipse.gef.GraphicalEditPart; -import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Tree; import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory; @@ -194,71 +187,6 @@ protected static void changeCellValueInNatTbale(final SWTBot4diacNatTable dataTy assertEquals(dataTypeTableBot.getCellDataValueByPosition(row, col), newValue); } - /** - * Change the algorithm or event value of an EC state action. - * - * @param editor The ECC editor. - * @param stateName The name of the EC state. - * @param value The value to assign (algorithm or event). - * @param index The index of the item box to modify. - */ - protected static void changeAlgorithmAndEventValue(final SWTBot4diacGefEditor editor, final String partLabel, - final String newValue, final int boxIndex) { - final SWTBotGefEditPart box = getChildrenPart(editor.getEditPart(partLabel), boxIndex); - box.doubleClick().select(); - editor.bot().ccomboBox().setSelection(newValue); - box.doubleClick().select(); - assertEquals(editor.bot().ccomboBox().selection(), newValue); - } - - /** - * Retrieves the center point of a graphical part within the editor. - * - * - * @param editPart The graphical part for which to get the center point. - * @return A Point object representing the center coordinates of the part. - */ - protected static Point getPoint(final SWTBotGefEditPart editPart) { - final IFigure figure = ((GraphicalEditPart) editPart.part()).getFigure(); - assertNotNull(figure); - final Rectangle statePartBounds = ((GraphicalEditPart) editPart.part()).getFigure().getBounds().getCopy(); - assertNotNull(statePartBounds); - figure.translateToAbsolute(statePartBounds); - return new Point(statePartBounds.getCenter().x, statePartBounds.getCenter().y); - - } - - /** - * Retrieves a child part of a given parent part at a specified index. - * - * @param parentPart The parent part from which to retrieve the child. - * @param index The index of the child part to retrieve. Use 0 for the - * first child, -1 for the last child, or any other index. - * @return The SWTBotGefEditPart corresponding to the specified child. - */ - protected static SWTBotGefEditPart getChildrenPart(final SWTBotGefEditPart parentPart, final int index) { - final List childParts = parentPart.children(); - assertNotNull(childParts); - return switch (index) { - case 0 -> { - final SWTBotGefEditPart childPart = childParts.getFirst(); - assertNotNull(childPart); - yield childPart; - } - case -1 -> { - final SWTBotGefEditPart childPart = childParts.getLast(); - assertNotNull(childPart); - yield childPart; - } - default -> { - final SWTBotGefEditPart childPart = childParts.get(index); - assertNotNull(childPart); - yield childPart; - } - }; - - } - /** * Returns from CompositeinstanceViewer back to Editing Area */ diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/fbtype/ECCEditorTests.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/fbtype/ECCEditorTests.java index ced29c5a5f..9e6a21dd9f 100644 --- a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/fbtype/ECCEditorTests.java +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/fbtype/ECCEditorTests.java @@ -17,9 +17,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import org.eclipse.fordiac.ide.test.ui.Abstract4diacUITests; -import org.eclipse.fordiac.ide.test.ui.helpers.UITestPinHelper; +import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotECC; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotFBType; import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper; +import org.eclipse.fordiac.ide.test.ui.helpers.UITestPinHelper; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefViewer; import org.eclipse.swt.graphics.Point; @@ -111,7 +112,7 @@ public void changeECStateNameWithTab() { public void createECAction() { final SWTBotGefEditPart statePart = editor.getEditPart(UITestNamesHelper.TESTSTATE); assertNotNull(statePart); - final Point testStatePoint = getPoint(statePart); + final Point testStatePoint = new SWTBotECC(bot).getPoint(statePart); editor.clickContextMenu(UITestNamesHelper.ADD_ACTION, testStatePoint.x, testStatePoint.y); assertNotNull(editor.getEditPart(UITestNamesHelper.TESTSTATE).children()); } @@ -124,7 +125,8 @@ public void createECAction() { @Test @Order(4) public void createAlgorithm() { - changeAlgorithmAndEventValue(editor, UITestNamesHelper.TESTSTATE, UITestNamesHelper.DEINITIALIZE, 0); + new SWTBotECC(bot).changeAlgorithmAndEventValue(editor, UITestNamesHelper.TESTSTATE, + UITestNamesHelper.DEINITIALIZE, 0); } /** @@ -135,7 +137,7 @@ public void createAlgorithm() { @Test @Order(5) public void createOutputEvent() { - changeAlgorithmAndEventValue(editor, UITestNamesHelper.DEINIT, UITestNamesHelper.CNF, -1); + new SWTBotECC(bot).changeAlgorithmAndEventValue(editor, UITestNamesHelper.DEINIT, UITestNamesHelper.CNF, -1); } /** @@ -147,11 +149,12 @@ public void createOutputEvent() { @Order(6) public void createTransition() { final SWTBotGefEditPart statePart = editor.getEditPart(UITestNamesHelper.START); - final Point start = getPoint(statePart); + final SWTBotECC eccBot = new SWTBotECC(bot); + final Point start = eccBot.getPoint(statePart); assertNotNull(start); final SWTBotGefEditPart endPart = editor.getEditPart(UITestNamesHelper.TESTSTATE); - final Point end = getPoint(endPart); + final Point end = eccBot.getPoint(endPart); assertNotNull(end); final SWTBot4diacGefViewer viewer = editor.getSWTBotGefViewer(); @@ -166,7 +169,8 @@ public void createTransition() { @Test @Order(7) public void changeAlgorithm() { - changeAlgorithmAndEventValue(editor, UITestNamesHelper.TESTSTATE, UITestNamesHelper.INITIALIZE, 0); + new SWTBotECC(bot).changeAlgorithmAndEventValue(editor, UITestNamesHelper.TESTSTATE, + UITestNamesHelper.INITIALIZE, 0); } /** @@ -177,7 +181,8 @@ public void changeAlgorithm() { @Test @Order(8) public void changeConditionEvent() { - changeAlgorithmAndEventValue(editor, UITestNamesHelper.INIT_SMALL, UITestNamesHelper.CNF, -1); + new SWTBotECC(bot).changeAlgorithmAndEventValue(editor, UITestNamesHelper.INIT_SMALL, UITestNamesHelper.CNF, + -1); } /** @@ -189,7 +194,7 @@ public void changeConditionEvent() { @Order(9) public void changeECTransitionConditionExpression() { final SWTBotGefEditPart part = editor - .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QI + "]"); + .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QI + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ editor.select(part); final SWTBot propertiesBot = selectTabFromECCProperties(UITestNamesHelper.TRANSITION); assertNotNull(propertiesBot); @@ -197,13 +202,13 @@ public void changeECTransitionConditionExpression() { propertiesBot.ccomboBoxWithLabel(UITestNamesHelper.CONDITION_LABEL).setSelection(UITestNamesHelper.REQ); propertiesBot.styledTextWithLabel(UITestNamesHelper.CONDITION_LABEL) - .setText(UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO); + .setText(UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO); //$NON-NLS-1$ assertEquals(propertiesBot.styledTextWithLabel(UITestNamesHelper.CONDITION_LABEL).getText(), - UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO); + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO); //$NON-NLS-1$ assertNull(editor - .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QI + "]")); + .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QI + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertNotNull(editor - .getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]")); + .getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } @@ -216,7 +221,7 @@ public void changeECTransitionConditionExpression() { @Order(10) public void changeECTransitionComment() { final SWTBotGefEditPart part = editor - .getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]"); + .getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ editor.select(part); final SWTBot propertiesBot = selectTabFromECCProperties(UITestNamesHelper.TRANSITION); assertNotNull(propertiesBot); @@ -234,8 +239,9 @@ public void changeECTransitionComment() { @Test @Order(11) public void deleteECAction() { - final SWTBotGefEditPart actionPart = getChildrenPart(editor.getEditPart(UITestNamesHelper.TESTSTATE), 0); - final Point actionPoint = getPoint(actionPart); + final SWTBotECC eccBot = new SWTBotECC(bot); + final SWTBotGefEditPart actionPart = eccBot.getChildrenPart(editor.getEditPart(UITestNamesHelper.TESTSTATE), 0); + final Point actionPoint = eccBot.getPoint(actionPart); actionPart.click(); editor.clickContextMenu(UITestNamesHelper.DELETE, actionPoint.x, actionPoint.y); @@ -280,7 +286,7 @@ public void tryToSetInvalidName() { public void tryToInvalidECTransitionConditionExpression() { // Select the EC transition part final SWTBotGefEditPart part = editor - .getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]"); + .getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ editor.select(part); // Access the Transition tab and set an invalid condition @@ -288,17 +294,17 @@ public void tryToInvalidECTransitionConditionExpression() { assertNotNull(propertiesBot); propertiesBot.ccomboBoxWithLabel(UITestNamesHelper.CONDITION_LABEL).setSelection(UITestNamesHelper.INIT); propertiesBot.styledTextWithLabel(UITestNamesHelper.CONDITION_LABEL) - .setText(UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB); + .setText(UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB); //$NON-NLS-1$ // Validate the new condition expression assertEquals(propertiesBot.styledTextWithLabel(UITestNamesHelper.CONDITION_LABEL).getText(), - UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB); + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB); //$NON-NLS-1$ // Verify that the transition part is correctly updated assertNull(editor - .getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]")); + .getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertNotNull(editor - .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]")); + .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } /** @@ -378,18 +384,18 @@ public void changeEventWithTable() { public void deleteTransition() { // Select the transition part and focus on it final SWTBotGefEditPart part = editor - .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]"); + .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ editor.select(part); assertNotNull(part); // Get the location of the transition part and delete it via context menu - final Point partPoint = getPoint(part); + final Point partPoint = new SWTBotECC(bot).getPoint(part); editor.select(part); editor.clickContextMenu(UITestNamesHelper.DELETE, partPoint.x, partPoint.y); // Verify that the transition part is successfully deleted assertNull(editor - .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]")); + .getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } /** diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotECC.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotECC.java new file mode 100644 index 0000000000..5a27c9081d --- /dev/null +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotECC.java @@ -0,0 +1,90 @@ +package org.eclipse.fordiac.ide.test.ui.helpers; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.fordiac.ide.test.ui.swtbot.SWT4diacGefBot; +import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; + +public class SWTBotECC { + + private final SWT4diacGefBot bot; + + @SuppressWarnings("static-access") + public SWTBotECC(final SWT4diacGefBot bot) { + this.bot = bot; + } + + /** + * Change the algorithm or event value of an EC state action. + * + * @param editor The ECC editor. + * @param stateName The name of the EC state. + * @param value The value to assign (algorithm or event). + * @param index The index of the item box to modify. + */ + public void changeAlgorithmAndEventValue(final SWTBot4diacGefEditor editor, final String partLabel, + final String newValue, final int boxIndex) { + final SWTBotGefEditPart box = getChildrenPart(editor.getEditPart(partLabel), boxIndex); + box.doubleClick().select(); + editor.bot().ccomboBox().setSelection(newValue); + box.doubleClick().select(); + assertEquals(editor.bot().ccomboBox().selection(), newValue); + } + + /** + * Retrieves a child part of a given parent part at a specified index. + * + * @param parentPart The parent part from which to retrieve the child. + * @param index The index of the child part to retrieve. Use 0 for the + * first child, -1 for the last child, or any other index. + * @return The SWTBotGefEditPart corresponding to the specified child. + */ + @SuppressWarnings("static-method") + public SWTBotGefEditPart getChildrenPart(final SWTBotGefEditPart parentPart, final int index) { + final List childParts = parentPart.children(); + assertNotNull(childParts); + return switch (index) { + case 0 -> { + final SWTBotGefEditPart childPart = childParts.getFirst(); + assertNotNull(childPart); + yield childPart; + } + case -1 -> { + final SWTBotGefEditPart childPart = childParts.getLast(); + assertNotNull(childPart); + yield childPart; + } + default -> { + final SWTBotGefEditPart childPart = childParts.get(index); + assertNotNull(childPart); + yield childPart; + } + }; + } + + /** + * Retrieves the center point of a graphical part within the editor. + * + * + * @param editPart The graphical part for which to get the center point. + * @return A Point object representing the center coordinates of the part. + */ + @SuppressWarnings("static-method") + public Point getPoint(final SWTBotGefEditPart editPart) { + final IFigure figure = ((GraphicalEditPart) editPart.part()).getFigure(); + assertNotNull(figure); + final Rectangle statePartBounds = ((GraphicalEditPart) editPart.part()).getFigure().getBounds().getCopy(); + assertNotNull(statePartBounds); + figure.translateToAbsolute(statePartBounds); + return new Point(statePartBounds.getCenter().x, statePartBounds.getCenter().y); + } + +}