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 2febe9d1a2..c57a2b71dc 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,7 +20,6 @@ package org.eclipse.fordiac.ide.test.ui; import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellCloses; -import static org.eclipse.swtbot.swt.finder.waits.Conditions.treeItemHasNode; import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -29,18 +28,12 @@ import java.util.List; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.fordiac.ide.application.editparts.FBEditPart; 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.EditPart; -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; @@ -55,8 +48,6 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; @@ -103,134 +94,6 @@ protected static void createProject() { bot.waitUntil(shellCloses(shell)); } - /** - * Drags and drops a FB onto the canvas with given name and position. - * - * @param fbName The name of the Function Block. - * @param point The Position of the FB on the canvas. - */ - protected static void dragAndDropEventsFB(final String fbName, final Point point) { - final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot); - final SWTBotTreeItem typeLibraryNode = sysEx.expandTypeLibraryTreeItemInSystemExplorer(); - bot.waitUntil(treeItemHasNode(typeLibraryNode, UITestNamesHelper.EVENTS_NODE)); - final SWTBotTreeItem eventsNode = typeLibraryNode.getNode(UITestNamesHelper.EVENTS_NODE); - eventsNode.select(); - eventsNode.expand(); - bot.waitUntil(treeItemHasNode(eventsNode, fbName)); - final SWTBotTreeItem eCycleNode = eventsNode.getNode(fbName); - eCycleNode.select(); - eCycleNode.click(); - - // select application editor - final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); - final SWTBot4diacGefViewer viewer = (SWTBot4diacGefViewer) editor.getSWTBotGefViewer(); - final SWTBotGefFigureCanvas canvas = viewer.getCanvas(); - - assertNotNull(canvas); - eCycleNode.dragAndDrop(canvas, point); - } - - /** - * Selects a FunctionBlock with the given Name in the editor. - * - * The function block is searched for with the given name in the editor. - * However, as this only selects the name, the parent is retrieved and selected. - * Only then is the searched function block selected as a whole. - * - * @param editor - * @param name - */ - protected static SWTBot4diacGefEditor selectFBWithFBNameInEditor(final SWTBot4diacGefEditor editor, - final String name) { - assertNotNull(editor); - assertNotNull(editor.getEditPart(name)); - editor.click(name); - final SWTBotGefEditPart parent = editor.getEditPart(name).parent(); - assertNotNull(parent); - editor.click(parent); - return editor; - } - - /** - * Deletes a FB from the editing area. - * - * @param editor The SWTBot4diacGefEditor from which a FB with given - * instance name should be deleted. - * @param FbInstanceName The instance name of the FB - */ - protected static void deleteFB(final SWTBot4diacGefEditor editor, final String FbInstanceName) { - editor.setFocus(); - final SWTBotGefEditPart fb = editor.getEditPart(FbInstanceName).parent(); - fb.select().click(); - bot.menu(UITestNamesHelper.EDIT).menu(UITestNamesHelper.DELETE).click(); - } - - protected static Rectangle getAbsolutePosition(final SWTBotGefEditor editor, final String fb) { - final SWTBotGefEditPart parent = editor.getEditPart(fb).parent(); - assertNotNull(parent); - final IFigure figurePos = ((GraphicalEditPart) parent.part()).getFigure(); - assertNotNull(figurePos); - final Rectangle fbBounds = figurePos.getBounds().getCopy(); - assertNotNull(fbBounds); - figurePos.translateToAbsolute(fbBounds); - return fbBounds; - } - - /** - * Checks if FB is selected by searching selectedEditParts list and returns the - * corresponding boolean value. - * - * @param selectedEditParts The List of selected EditParts. - * @param fbName The FB that is searched for. - * @return true if fbName is in the List, otherwise false. - */ - protected static boolean isFbSelected(final List selectedEditParts, final String fbName) { - return selectedEditParts.stream().filter(p -> p.part() instanceof FBEditPart).map(p -> (FBEditPart) p.part()) - .anyMatch(fb -> fb.getModel().getName().equals(fbName)); - } - - /** - * Checks if given FB instance name can be found on the editing area. - * - * @param editor The SWTBot4diacGefEditor in which the FB instance name is - * searched - * @param fbName The String of the FB instance name searched for - * @return true if FB is onto editing area, false if not - */ - protected static boolean isFBNamePresendOnEditingArea(final SWTBot4diacGefEditor editor, final String fbName) { - final List editParts = editor.editParts(new BaseMatcher() { - @Override - public boolean matches(final Object item) { - return item instanceof FBEditPart; - } - - @Override - public void describeTo(final Description description) { - // method must be implemented but empty since not needed - } - }); - assertFalse(editParts.isEmpty()); - return editParts.stream().filter(p -> p.part() instanceof FBEditPart).map(p -> (FBEditPart) p.part()) - .anyMatch(fb -> fb.getModel().getName().equals(fbName)); - } - - /** - * Returns the bounds of the searched function block - * - * @param editor - * @param fBname - * @return The rectangle with the bounds of the function block searched for - */ - protected static Rectangle getBoundsOfFB(final SWTBot4diacGefEditor editor, final String fBname) { - editor.getEditPart(fBname); - editor.click(fBname); - final SWTBotGefEditPart parent = editor.getEditPart(fBname).parent(); - final IFigure figure = ((GraphicalEditPart) parent.part()).getFigure(); - final Rectangle fbBounds = figure.getBounds().getCopy(); - figure.translateToAbsolute(fbBounds); - return fbBounds; - } - /** * Select a given FB on the editing area and double click it to access the * CompositeInstanceViewer. After that the SWTBotGefEditor will be returned. diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Basic1FBNetworkEditingTests.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Basic1FBNetworkEditingTests.java index 8d22a2927d..a9ce399017 100644 --- a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Basic1FBNetworkEditingTests.java +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Basic1FBNetworkEditingTests.java @@ -26,11 +26,11 @@ import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.fordiac.ide.application.editparts.FBEditPart; import org.eclipse.fordiac.ide.application.editparts.InstanceNameEditPart; import org.eclipse.fordiac.ide.application.figures.InstanceNameFigure; import org.eclipse.fordiac.ide.test.ui.helpers.PinNamesHelper; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotConnection; +import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotFB; import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefViewer; @@ -105,10 +105,11 @@ public void dragAndDrop1FB() { * Checks if the FB is dragged onto the canvas is also visible in the hierarchy * tree. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void isAddedFbInProjectAppNode() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(300, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(300, 100)); final SWTBotView systemExplorerView = bot.viewById(UITestNamesHelper.SYSTEM_EXPLORER_ID); assertNotNull(systemExplorerView); systemExplorerView.show(); @@ -136,10 +137,11 @@ public void isAddedFbInProjectAppNode() { /** * Checks if the FB is no longer on the canvas after deletion. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void deleteExistingFB() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(300, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(300, 100)); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); assertNotNull(editor.getEditPart(UITestNamesHelper.E_CYCLE_FB)); @@ -159,10 +161,11 @@ public void deleteExistingFB() { * selected as expected. Then a rectangle is drawn over the FB to check whether * the FB is selected. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void selectFbViaMouseLeftClickRectangleOverFB() { - dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(200, 200)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(200, 200)); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); // drag rectangle next to FB, therefore FB should not be selected @@ -170,18 +173,12 @@ public void selectFbViaMouseLeftClickRectangleOverFB() { assertThrows(TimeoutException.class, () -> editor.waitForSelectedFBEditPart()); List selectedEditParts = editor.selectedEditParts(); assertTrue(selectedEditParts.isEmpty()); - assertFalse( - selectedEditParts.stream().filter(p -> p.part() instanceof FBEditPart).map(p -> (FBEditPart) p.part()) - .anyMatch(fb -> UITestNamesHelper.E_D_FF_FB.equals(fb.getModel().getName()))); - - // drag rectangle over to FB, therefore FB should be selected + assertFalse(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_D_FF_FB)); editor.drag(50, 50, 350, 350); assertDoesNotThrow(() -> editor.waitForSelectedFBEditPart()); selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertTrue( - selectedEditParts.stream().filter(p -> p.part() instanceof FBEditPart).map(p -> (FBEditPart) p.part()) - .anyMatch(fb -> UITestNamesHelper.E_D_FF_FB.equals(fb.getModel().getName()))); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_D_FF_FB)); } /** @@ -192,10 +189,11 @@ public void selectFbViaMouseLeftClickRectangleOverFB() { * selected as expected. Then several attempts are made to click on the FB * (meaning within the FB bounds) to select the FB as expected. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void selectFbViaMouseLeftClickOnFB() { - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(150, 250)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(150, 250)); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); // check bounds of FB @@ -212,7 +210,7 @@ public void selectFbViaMouseLeftClickOnFB() { assertThrows(TimeoutException.class, () -> editor.waitForSelectedFBEditPart()); List selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertFalse(isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); + assertFalse(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); // click next to the FB point = new Point(265, 350); @@ -220,7 +218,7 @@ public void selectFbViaMouseLeftClickOnFB() { assertThrows(TimeoutException.class, () -> editor.waitForSelectedFBEditPart()); selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertFalse(isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); + assertFalse(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); // click exactly at the insertion point point = new Point(150, 250); @@ -229,7 +227,7 @@ public void selectFbViaMouseLeftClickOnFB() { assertDoesNotThrow(() -> editor.waitForSelectedFBEditPart()); selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); // click within the FB bounds but not on a pin or instance name point = new Point(170, 300); @@ -238,7 +236,7 @@ public void selectFbViaMouseLeftClickOnFB() { assertDoesNotThrow(() -> editor.waitForSelectedFBEditPart()); selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); // click within the FB bounds but not on a pin or instance name point = new Point(200, 340); @@ -247,7 +245,7 @@ public void selectFbViaMouseLeftClickOnFB() { assertDoesNotThrow(() -> editor.waitForSelectedFBEditPart()); selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); } /** @@ -259,11 +257,12 @@ public void selectFbViaMouseLeftClickOnFB() { * To achieve this it is necessary to create a draw2d.geometry Point with the * same coordinates of the swt.graphics Point. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void moveFB() { final Point pos1 = new Point(200, 200); - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, pos1); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, pos1); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); assertNotNull(editor.getEditPart(UITestNamesHelper.E_CYCLE_FB)); @@ -302,10 +301,11 @@ public void moveFB() { * The method sets the default value of data input pin of type time of FB * E_CYCLE to a new value. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void editDTofECycle() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 200)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 200)); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); editor.getEditPart(PinNamesHelper.DEF_VAL); @@ -323,10 +323,11 @@ public void editDTofECycle() { * The method checks if the default value of data input pin of type time of FB * E_CYCLE is displayed correctly. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void directEditorDefaultValueTest() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 100)); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); editor.getEditPart(PinNamesHelper.DEF_VAL); @@ -343,10 +344,11 @@ public void directEditorDefaultValueTest() { * The method checks if the new entered value of data input pin of type time of * FB E_CYCLE is displayed correctly. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void directEditorNewValueTest() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 100)); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); editor.getEditPart(PinNamesHelper.DEF_VAL); @@ -363,10 +365,11 @@ public void directEditorNewValueTest() { /** * Checks if it is possible to edit the automatically generated name of the FB */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void editFBName() { - dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(100, 100)); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); @@ -413,7 +416,8 @@ public void editFBName() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void validConnectionBetweenEventInputPinAndEventOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 200)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 200)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.START, PinNamesHelper.EO); assertDoesNotThrow(viewer::waitForConnection); @@ -431,7 +435,8 @@ public void validConnectionBetweenEventInputPinAndEventOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void validConnectionBetweenEventOutputPinAndEventInputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.EO1, PinNamesHelper.START); assertDoesNotThrow(viewer::waitForConnection); @@ -449,7 +454,8 @@ public void validConnectionBetweenEventOutputPinAndEventInputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void validConnectionBetweenUintDataInputPinAndUintDataOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(150, 150)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(150, 150)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.PV, PinNamesHelper.CV); assertDoesNotThrow(viewer::waitForConnection); @@ -467,7 +473,8 @@ public void validConnectionBetweenUintDataInputPinAndUintDataOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void validConnectionBetweenBoolInputPinAndBoolOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(150, 150)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(150, 150)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.D, PinNamesHelper.Q); assertDoesNotThrow(viewer::waitForConnection); @@ -481,7 +488,8 @@ public void validConnectionBetweenBoolInputPinAndBoolOutputPin() { public void connectionCanBeFoundAfterMovingFB() { // in progress final Point pos1 = new Point(100, 150); - dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, pos1); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, pos1); final SWTBotConnection connect = new SWTBotConnection(bot); connect.createConnection(PinNamesHelper.INIT, PinNamesHelper.CLKO); connect.createConnection(PinNamesHelper.N, PinNamesHelper.CV); @@ -543,7 +551,8 @@ public void connectionCanBeFoundAfterMovingFB() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventInputPinAndEventInputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.START, PinNamesHelper.STOP); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -562,7 +571,8 @@ public void invalidConnectionBetweenEventInputPinAndEventInputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventInputPinAndUintInputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(150, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(150, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.START, PinNamesHelper.N); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -581,7 +591,8 @@ public void invalidConnectionBetweenEventInputPinAndUintInputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventInputPinAndTimeInputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(150, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(150, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.START, PinNamesHelper.DT); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -600,7 +611,8 @@ public void invalidConnectionBetweenEventInputPinAndTimeInputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventInputPinAndBoolInputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(150, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(150, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.CLK, PinNamesHelper.D); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -619,7 +631,8 @@ public void invalidConnectionBetweenEventInputPinAndBoolInputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventInputPinAndUintOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(100, 150)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(100, 150)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.CD, PinNamesHelper.CV); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -638,7 +651,8 @@ public void invalidConnectionBetweenEventInputPinAndUintOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventInputPinAndTimeOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.INIT, PinNamesHelper.DTO); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -657,7 +671,8 @@ public void invalidConnectionBetweenEventInputPinAndTimeOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventInputPinAndBoolOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(100, 150)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(100, 150)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.CD, PinNamesHelper.QU); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -676,7 +691,8 @@ public void invalidConnectionBetweenEventInputPinAndBoolOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenTimeInputPinAndTimeOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.DT, PinNamesHelper.DTO); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -695,7 +711,8 @@ public void invalidConnectionBetweenTimeInputPinAndTimeOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenTimeInputPinAndUintInputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.DT, PinNamesHelper.N); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -714,7 +731,8 @@ public void invalidConnectionBetweenTimeInputPinAndUintInputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenUintInputPinAndBoolOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.PV, PinNamesHelper.QU); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -733,7 +751,8 @@ public void invalidConnectionBetweenUintInputPinAndBoolOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventOutputPinAndUintInputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.EO0, PinNamesHelper.N); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -752,7 +771,8 @@ public void invalidConnectionBetweenEventOutputPinAndUintInputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventOutputPinAndTimeInputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.EO1, PinNamesHelper.DT); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -771,7 +791,8 @@ public void invalidConnectionBetweenEventOutputPinAndTimeInputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventOutputPinAndBoolInputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.EO, PinNamesHelper.D); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -790,7 +811,8 @@ public void invalidConnectionBetweenEventOutputPinAndBoolInputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventOutputPinAndEventOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.EO0, PinNamesHelper.EO2); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -809,7 +831,8 @@ public void invalidConnectionBetweenEventOutputPinAndEventOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventOutputPinAndUintOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.CLKO, PinNamesHelper.CV); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -828,7 +851,8 @@ public void invalidConnectionBetweenEventOutputPinAndUintOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventOutputPinAndTimeOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_TABLE_CTRL_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.CLKO, PinNamesHelper.DTO); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -847,7 +871,8 @@ public void invalidConnectionBetweenEventOutputPinAndTimeOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenEventOutputPinAndBoolOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_D_FF_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.EO, PinNamesHelper.Q); assertThrows(TimeoutException.class, viewer::waitForConnection); @@ -866,7 +891,8 @@ public void invalidConnectionBetweenEventOutputPinAndBoolOutputPin() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void invalidConnectionBetweenBoolOutputPinAndBoolOutputPin() { - dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(100, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); final SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.QU, PinNamesHelper.QD); assertThrows(TimeoutException.class, viewer::waitForConnection); diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Basic2FBNetworkEditingTests.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Basic2FBNetworkEditingTests.java index 26351adeb3..18506ff1ad 100644 --- a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Basic2FBNetworkEditingTests.java +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/Basic2FBNetworkEditingTests.java @@ -12,7 +12,6 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.test.ui; -import static org.eclipse.swtbot.swt.finder.waits.Conditions.treeItemHasNode; import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -27,20 +26,13 @@ import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.fordiac.ide.test.ui.helpers.PinNamesHelper; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotConnection; +import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotFB; import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor; -import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefViewer; import org.eclipse.gef.ConnectionEditPart; 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; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor; -import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefFigureCanvas; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; import org.eclipse.swtbot.swt.finder.widgets.TimeoutException; import org.junit.jupiter.api.Test; @@ -55,56 +47,24 @@ public class Basic2FBNetworkEditingTests extends Abstract4diacUITests { * Then a second FB (E_SWITCH) is dragged onto the canvas and the check is the * same as above. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void dragAndDrop2FB() { // select FB E_CYCLE - final SWTBotView systemExplorerView = bot.viewById(UITestNamesHelper.SYSTEM_EXPLORER_ID); - systemExplorerView.show(); - final Composite systemExplorerComposite = (Composite) systemExplorerView.getWidget(); - final Tree swtTree = bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), systemExplorerComposite); - final SWTBotTree tree = new SWTBotTree(swtTree); - assertNotNull(tree); - final SWTBotTreeItem treeProjectItem = tree.getTreeItem(UITestNamesHelper.PROJECT_NAME); - assertNotNull(treeProjectItem); - treeProjectItem.select(); - treeProjectItem.expand(); - final SWTBotTreeItem typeLibraryNode = treeProjectItem.getNode(UITestNamesHelper.TYPE_LIBRARY_NODE); - assertNotNull(typeLibraryNode); - typeLibraryNode.select(); - typeLibraryNode.expand(); - final SWTBotTreeItem eventsNode = typeLibraryNode.getNode(UITestNamesHelper.EVENTS_NODE); - assertNotNull(eventsNode); - eventsNode.select(); - eventsNode.expand(); - bot.waitUntil(treeItemHasNode(eventsNode, UITestNamesHelper.E_CYCLE_TREE_ITEM)); - final SWTBotTreeItem eCycleNode = eventsNode.getNode(UITestNamesHelper.E_CYCLE_TREE_ITEM); - assertNotNull(eCycleNode); - eCycleNode.select(); - eCycleNode.click(); - // select application editor - final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); - assertNotNull(editor); - final SWTBot4diacGefViewer viewer = (SWTBot4diacGefViewer) editor.getSWTBotGefViewer(); - assertNotNull(viewer); - final SWTBotGefFigureCanvas canvas = viewer.getCanvas(); - assertNotNull(canvas); + final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); + final SWTBotFB fbBot = new SWTBotFB(bot); final Point point1 = new Point(100, 100); - eCycleNode.dragAndDrop(canvas, point1); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, point1); assertNotNull(editor.getEditPart(UITestNamesHelper.E_CYCLE_FB)); - final Rectangle absPos1 = getAbsolutePosition(editor, UITestNamesHelper.E_CYCLE_FB); + final Rectangle absPos1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB); assertEquals(point1.x, absPos1.x); assertEquals(point1.y, absPos1.y); // select FB E_SWITCH - final SWTBotTreeItem eSwitchNode = eventsNode.getNode(UITestNamesHelper.E_SWITCH_TREE_ITEM); - assertNotNull(eSwitchNode); - eSwitchNode.select(); - eSwitchNode.click(); final Point point2 = new Point(300, 150); - eSwitchNode.dragAndDrop(canvas, point2); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, point2); assertNotNull(editor.getEditPart(UITestNamesHelper.E_SWITCH_FB)); - final Rectangle absPos2 = getAbsolutePosition(editor, UITestNamesHelper.E_SWITCH_FB); + final Rectangle absPos2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_SWITCH_FB); assertEquals(point2.x, absPos2.x); assertEquals(point2.y, absPos2.y); } @@ -114,11 +74,12 @@ public void dragAndDrop2FB() { * deleted and it is checked if the FB is no longer on the canvas after * deletion. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void delete1FB() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(300, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(300, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); assertNotNull(editor.getEditPart(UITestNamesHelper.E_CYCLE_FB)); @@ -142,11 +103,12 @@ public void delete1FB() { * selected as expected. Then a rectangle is drawn over the FBs to check whether * the FBs are selected. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void select2FBsViaMouseLeftClickOnFB() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(300, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, new Point(300, 100)); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); // drag rectangle next to FBs, therefore FBs should not be selected @@ -154,16 +116,16 @@ public void select2FBsViaMouseLeftClickOnFB() { assertThrows(TimeoutException.class, editor::waitForSelectedFBEditPart); List selectedEditParts = editor.selectedEditParts(); assertTrue(selectedEditParts.isEmpty()); - assertFalse(isFbSelected(selectedEditParts, UITestNamesHelper.E_N_TABLE_FB)); - assertFalse(isFbSelected(selectedEditParts, UITestNamesHelper.E_CTUD_FB)); + assertFalse(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_N_TABLE_FB)); + assertFalse(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_CTUD_FB)); // drag rectangle over FBs, therefore FBs should be selected editor.drag(50, 50, 500, 300); assertDoesNotThrow(editor::waitForSelectedFBEditPart); selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_N_TABLE_FB)); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_CTUD_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_N_TABLE_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_CTUD_FB)); } /** @@ -176,13 +138,14 @@ public void select2FBsViaMouseLeftClickOnFB() { * which is not expected. To achieve this it is necessary to create a * draw2d.geometry Point with the same coordinates of the swt.graphics Point. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void move1FB() { final Point pos1 = new Point(100, 100); - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, pos1); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, pos1); final Point pos2 = new Point(350, 100); - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, pos2); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, pos2); // select E_CYCLE and check position of E_CYCLE final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); @@ -191,17 +154,17 @@ public void move1FB() { editor.click(UITestNamesHelper.E_CYCLE_FB); final SWTBotGefEditPart fb1 = editor.getEditPart(UITestNamesHelper.E_CYCLE_FB).parent(); assertNotNull(fb1); - final Rectangle fb1Bounds1 = getAbsolutePosition(editor, UITestNamesHelper.E_CYCLE_FB); + final Rectangle fb1Bounds1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB); assertTrue(fb1Bounds1.contains(pos1.x, pos1.y)); // check position of E_N_TABLE - final Rectangle fb2Bounds1 = getAbsolutePosition(editor, UITestNamesHelper.E_N_TABLE_FB); + final Rectangle fb2Bounds1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_N_TABLE_FB); assertTrue(fb2Bounds1.contains(pos2.x, pos2.y)); // move E_CYCLE and check new position final Point pos3 = new Point(125, 185); editor.drag(fb1, pos3.x, pos3.y); - final Rectangle fb1Bounds2 = getAbsolutePosition(editor, UITestNamesHelper.E_CYCLE_FB); + final Rectangle fb1Bounds2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB); assertTrue(fb1Bounds2.contains(pos3.x, pos3.y)); // check if E_N_TABLE is still on same position @@ -217,37 +180,38 @@ public void move1FB() { * this position is also checked. To achieve this it is necessary to create a * draw2d.geometry Point with the same coordinates of the swt.graphics Point. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void moveBothFBOneAfterAnother() { final Point pos1 = new Point(200, 200); - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, pos1); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, pos1); final Point pos2 = new Point(400, 200); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, pos2); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, pos2); // select and move E_CYCLE - final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); + final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); assertNotNull(editor.getEditPart(UITestNamesHelper.E_CYCLE_FB)); editor.click(UITestNamesHelper.E_CYCLE_FB); final SWTBotGefEditPart fb1 = editor.getEditPart(UITestNamesHelper.E_CYCLE_FB).parent(); assertNotNull(fb1); - final Rectangle fb1Bounds1 = getAbsolutePosition(editor, UITestNamesHelper.E_CYCLE_FB); + final Rectangle fb1Bounds1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB); assertTrue(fb1Bounds1.contains(pos1.x, pos1.y)); final Point pos3 = new Point(85, 85); editor.drag(fb1, pos3.x, pos3.y); - final Rectangle fb1Bounds2 = getAbsolutePosition(editor, UITestNamesHelper.E_CYCLE_FB); + final Rectangle fb1Bounds2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB); assertTrue(fb1Bounds2.contains(pos3.x, pos3.y)); // select and move E_SWITCH editor.click(UITestNamesHelper.E_SWITCH_FB); final SWTBotGefEditPart fb2 = editor.getEditPart(UITestNamesHelper.E_SWITCH_FB).parent(); assertNotNull(fb2); - final Rectangle fb2Bounds1 = getAbsolutePosition(editor, UITestNamesHelper.E_SWITCH_FB); + final Rectangle fb2Bounds1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_SWITCH_FB); assertTrue(fb2Bounds1.contains(pos2.x, pos2.y)); final Point pos4 = new Point(285, 85); editor.drag(fb2, pos4.x, pos4.y); - final Rectangle fb2Bounds2 = getAbsolutePosition(editor, UITestNamesHelper.E_SWITCH_FB); + final Rectangle fb2Bounds2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_SWITCH_FB); assertTrue(fb2Bounds2.contains(pos4.x, pos4.y)); } @@ -259,18 +223,19 @@ public void moveBothFBOneAfterAnother() { * selected as expected. Then a rectangle is drawn over the FBs to check whether * the FBs are selected. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void moveBothFBTogether() { final Point absPos1Fb1 = new Point(100, 100); - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, absPos1Fb1); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, absPos1Fb1); final Point absPos1Fb2 = new Point(100, 220); - dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, absPos1Fb2); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, absPos1Fb2); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); - final Rectangle fb1Bounds1 = getAbsolutePosition(editor, UITestNamesHelper.E_CYCLE_FB); + final Rectangle fb1Bounds1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB); assertTrue(fb1Bounds1.contains(absPos1Fb1.x, absPos1Fb1.y)); - final Rectangle fb2Bounds1 = getAbsolutePosition(editor, UITestNamesHelper.E_SR_FB); + final Rectangle fb2Bounds1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_SR_FB); assertTrue(fb2Bounds1.contains(absPos1Fb2.x, absPos1Fb2.y)); // drag rectangle over FBs, therefore FBs should be selected @@ -278,8 +243,8 @@ public void moveBothFBTogether() { assertDoesNotThrow(editor::waitForSelectedFBEditPart); List selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_CYCLE_FB)); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_CYCLE_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); // move selection by clicking on point within selection (120, 120) and drag to // new Point (285, 85) @@ -290,8 +255,8 @@ public void moveBothFBTogether() { assertDoesNotThrow(editor::waitForSelectedFBEditPart); selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_CYCLE_FB)); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_CYCLE_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); // Calculation of translation final int translationX = pointTo.x - pointFrom.x; @@ -300,7 +265,7 @@ public void moveBothFBTogether() { // Calculation of new Position of E_CYCLEs final int absPos2Fb1X = absPos1Fb1.x + translationX; final int absPos2Fb1Y = absPos1Fb1.y + translationY; - final Rectangle fb1Bounds2 = getAbsolutePosition(editor, UITestNamesHelper.E_CYCLE_FB); + final Rectangle fb1Bounds2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB); assertEquals(absPos2Fb1X, fb1Bounds2.x); assertEquals(absPos2Fb1Y, fb1Bounds2.y); assertTrue(fb1Bounds2.contains(absPos2Fb1X, absPos2Fb1Y)); @@ -308,7 +273,7 @@ public void moveBothFBTogether() { // Calculation of new Position of E_SR final int absPos2Fb2X = absPos1Fb2.x + translationX; final int absPos2Fb2Y = absPos1Fb2.y + translationY; - final Rectangle fb2Bounds2 = getAbsolutePosition(editor, UITestNamesHelper.E_SR_FB); + final Rectangle fb2Bounds2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_SR_FB); assertEquals(absPos2Fb2X, fb2Bounds2.x); assertEquals(absPos2Fb2Y, fb2Bounds2.y); assertTrue(fb2Bounds2.contains(absPos2Fb2X, absPos2Fb2Y)); @@ -329,8 +294,9 @@ public void moveBothFBTogether() { @Test public void checkIfConnectionRemainsAfterMoving1FB() { final Point pos1 = new Point(100, 50); - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, pos1); - dragAndDropEventsFB(UITestNamesHelper.E_DEMUX_TREE_ITEM, new Point(300, 50)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, pos1); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_DEMUX_TREE_ITEM, new Point(300, 50)); final SWTBotConnection connect = new SWTBotConnection(bot); connect.createConnection(PinNamesHelper.EO, PinNamesHelper.EI); final ConnectionEditPart connection = connect.findConnection(PinNamesHelper.EO, PinNamesHelper.EI); @@ -343,7 +309,7 @@ public void checkIfConnectionRemainsAfterMoving1FB() { editor.click(UITestNamesHelper.E_CYCLE_FB); final SWTBotGefEditPart fb1 = editor.getEditPart(UITestNamesHelper.E_CYCLE_FB).parent(); assertNotNull(fb1); - final Rectangle fb1Bounds1 = getAbsolutePosition(editor, UITestNamesHelper.E_CYCLE_FB); + final Rectangle fb1Bounds1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB); assertTrue(fb1Bounds1.contains(pos1.x, pos1.y)); // get connection start and end point @@ -358,7 +324,7 @@ public void checkIfConnectionRemainsAfterMoving1FB() { // move E_CYCLE editor.drag(fb1, pos2.x, pos2.y); - final Rectangle fb1Bounds2 = getAbsolutePosition(editor, UITestNamesHelper.E_CYCLE_FB); + final Rectangle fb1Bounds2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CYCLE_FB); assertTrue(fb1Bounds2.contains(pos2.x, pos2.y)); assertNotNull(connection); final org.eclipse.draw2d.geometry.Point newStartPointConnection = polyLineConnection.getPoints() @@ -388,9 +354,10 @@ public void checkIfConnectionRemainsAfterMoving1FB() { @Test public void checkIfConnectionRemainsAfterMovingBothFBsOneAfterAnother() { final Point pos1 = new Point(375, 75); - dragAndDropEventsFB(UITestNamesHelper.E_SELECT_TREE_ITEM, pos1); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SELECT_TREE_ITEM, pos1); final Point pos2 = new Point(175, 125); - dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, pos2); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CTUD_TREE_ITEM, pos2); final SWTBotConnection connect = new SWTBotConnection(bot); connect.createConnection(PinNamesHelper.QU, PinNamesHelper.G); final ConnectionEditPart connection = connect.findConnection(PinNamesHelper.QU, PinNamesHelper.G); @@ -404,7 +371,7 @@ public void checkIfConnectionRemainsAfterMovingBothFBsOneAfterAnother() { editor.click(UITestNamesHelper.E_SELECT_FB); final SWTBotGefEditPart fb1 = editor.getEditPart(UITestNamesHelper.E_SELECT_FB).parent(); assertNotNull(fb1); - final Rectangle fb1Bounds1 = getAbsolutePosition(editor, UITestNamesHelper.E_SELECT_FB); + final Rectangle fb1Bounds1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_SELECT_FB); assertTrue(fb1Bounds1.contains(pos1.x, pos1.y)); // get connection start and end point @@ -423,7 +390,7 @@ public void checkIfConnectionRemainsAfterMovingBothFBsOneAfterAnother() { // move E_SELECT editor.drag(fb1, pos3.x, pos3.y); - final Rectangle fb1Bounds2 = getAbsolutePosition(editor, UITestNamesHelper.E_SELECT_FB); + final Rectangle fb1Bounds2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_SELECT_FB); assertTrue(fb1Bounds2.contains(pos3.x, pos3.y)); assertNotNull(connection); org.eclipse.draw2d.geometry.Point newStartPointConnection = polyLineConnection.getPoints().getFirstPoint(); @@ -437,11 +404,11 @@ public void checkIfConnectionRemainsAfterMovingBothFBsOneAfterAnother() { editor.click(UITestNamesHelper.E_CTUD_FB); final SWTBotGefEditPart fb2 = editor.getEditPart(UITestNamesHelper.E_CTUD_FB).parent(); assertNotNull(fb2); - final Rectangle fb2Bounds1 = getAbsolutePosition(editor, UITestNamesHelper.E_CTUD_FB); + final Rectangle fb2Bounds1 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CTUD_FB); assertTrue(fb2Bounds1.contains(pos2.x, pos2.y)); // move E_CTUD editor.drag(fb2, pos4.x, pos4.y); - final Rectangle fb2Bounds2 = getAbsolutePosition(editor, UITestNamesHelper.E_CTUD_FB); + final Rectangle fb2Bounds2 = fbBot.getBoundsOfFB(editor, UITestNamesHelper.E_CTUD_FB); assertTrue(fb2Bounds2.contains(pos4.x, pos4.y)); assertNotNull(connection); newStartPointConnection = polyLineConnection.getPoints().getFirstPoint(); @@ -466,9 +433,10 @@ public void checkIfConnectionRemainsAfterMovingBothFBsOneAfterAnother() { @Test public void checkIfConnectionRemainsAfterMovingBothFBsTogether() { final Point pos1 = new Point(200, 100); - dragAndDropEventsFB(UITestNamesHelper.E_DEMUX_TREE_ITEM, pos1); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_DEMUX_TREE_ITEM, pos1); final Point pos2 = new Point(100, 275); - dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, pos2); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, pos2); final SWTBotConnection connect = new SWTBotConnection(bot); connect.createConnection(PinNamesHelper.EO1, PinNamesHelper.R); ConnectionEditPart connection = connect.findConnection(PinNamesHelper.EO1, PinNamesHelper.R); @@ -485,8 +453,8 @@ public void checkIfConnectionRemainsAfterMovingBothFBsTogether() { assertDoesNotThrow(editor::waitForSelectedFBEditPart); List selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_DEMUX_FB)); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_DEMUX_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); // move selection by clicking on one FB but not on instance name or a pin final Point pointFrom = new Point(125, 300); @@ -496,8 +464,8 @@ public void checkIfConnectionRemainsAfterMovingBothFBsTogether() { assertDoesNotThrow(editor::waitForSelectedFBEditPart); selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_DEMUX_FB)); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_DEMUX_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); // calculation of translation final int translationX = pointTo.x - pointFrom.x; diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/BasicMultipleFBNetworkEditingTests.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/BasicMultipleFBNetworkEditingTests.java index 62b3ffe31b..a1b4a5a009 100644 --- a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/BasicMultipleFBNetworkEditingTests.java +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/BasicMultipleFBNetworkEditingTests.java @@ -16,6 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotFB; import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor; import org.eclipse.swt.graphics.Point; @@ -50,28 +51,29 @@ public class BasicMultipleFBNetworkEditingTests extends Abstract4diacUITests { * First multiple E_CYCLE and E_SR are dragged in mixed order onto the editing * area. After that it is checked if the names were assigned correctly. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void checkIfNewFbGetsNextFreeRunningNumber() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(500, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 250)); - dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 250)); - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(500, 250)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(500, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 250)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 250)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(500, 250)); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); - assertTrue(isFBNamePresendOnEditingArea(editor, E_CYCLE)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_CYCLE_1)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_CYCLE_2)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_CYCLE_3)); - assertFalse(isFBNamePresendOnEditingArea(editor, E_CYCLE_0)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_CYCLE)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_CYCLE_1)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_CYCLE_2)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_CYCLE_3)); + assertFalse(fbBot.isFBNamePresendOnEditingArea(editor, E_CYCLE_0)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SR)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SR_1)); - assertFalse(isFBNamePresendOnEditingArea(editor, E_SR_2)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SR)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SR_1)); + assertFalse(fbBot.isFBNamePresendOnEditingArea(editor, E_SR_2)); } @@ -85,42 +87,43 @@ public void checkIfNewFbGetsNextFreeRunningNumber() { * 2 FBs are deleted and 4 FBs are added and it is checked whether the name * allocation is correct here as well. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void checkIfNewFbGetsSmallestNextFreeRunningNumber() { - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(50, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(250, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(450, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(50, 250)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(50, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(250, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(450, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(50, 250)); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH_1)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH_2)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH_3)); - assertFalse(isFBNamePresendOnEditingArea(editor, E_SWITCH_0)); - assertFalse(isFBNamePresendOnEditingArea(editor, E_SWITCH_4)); - - deleteFB(editor, E_SWITCH_2); - assertFalse(isFBNamePresendOnEditingArea(editor, E_SWITCH_2)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(450, 250)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH_2)); - - deleteFB(editor, E_SWITCH); - deleteFB(editor, E_SWITCH_1); - assertFalse(isFBNamePresendOnEditingArea(editor, E_SWITCH)); - assertFalse(isFBNamePresendOnEditingArea(editor, E_SWITCH_1)); - - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(450, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(250, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(250, 250)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(50, 100)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH_1)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH_4)); - assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH_5)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_1)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_2)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_3)); + assertFalse(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_0)); + assertFalse(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_4)); + + fbBot.deleteFB(editor, E_SWITCH_2); + assertFalse(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_2)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(450, 250)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_2)); + + fbBot.deleteFB(editor, E_SWITCH); + fbBot.deleteFB(editor, E_SWITCH_1); + assertFalse(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH)); + assertFalse(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_1)); + + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(450, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(250, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(250, 250)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(50, 100)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_1)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_4)); + assertTrue(fbBot.isFBNamePresendOnEditingArea(editor, E_SWITCH_5)); } /** diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/CompositeInstanceViewerTests.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/CompositeInstanceViewerTests.java index 85adad410a..38ddabc34a 100644 --- a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/CompositeInstanceViewerTests.java +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/CompositeInstanceViewerTests.java @@ -28,6 +28,7 @@ import org.eclipse.fordiac.ide.model.ui.editors.AbstractBreadCrumbEditor; import org.eclipse.fordiac.ide.test.ui.helpers.PinNamesHelper; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotConnection; +import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotFB; import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefViewer; import org.eclipse.gef.ConnectionEditPart; @@ -50,10 +51,11 @@ public class CompositeInstanceViewerTests extends Abstract4diacUITests { * clicks on it. It is expected that a new breadcrumb tab with the name of the * FB appears and the editor is an instance of CompositeInstanceViewer. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void compositeInstanceViewerAppearsAfterDoubleClickOnFB() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 100)); final SWTBotGefEditor editor = goToCompositeInstanceViewer(UITestNamesHelper.E_N_TABLE_FB); UIThreadRunnable.syncExec(() -> { @@ -79,10 +81,11 @@ public void compositeInstanceViewerAppearsAfterDoubleClickOnFB() { * create a new draw2d.geometry Point, because draw2d.geometry Points are not * compatible with the former. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void compositeInstanceViewerMoveFB() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 200)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 200)); goToCompositeInstanceViewer(UITestNamesHelper.E_N_TABLE_FB); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); @@ -124,10 +127,11 @@ public void compositeInstanceViewerMoveFB() { /** * Checks if it is possible to delete FB in CompositeInstanceViewer */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void compositeInstanceViewerDeleteFB() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 200)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 200)); goToCompositeInstanceViewer(UITestNamesHelper.E_N_TABLE_FB); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); @@ -153,12 +157,13 @@ public void compositeInstanceViewerDeleteFB() { /** * Checks if it is possible to add another FB in CompositeInstanceViewer */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void compositeInstanceViewerAddAnotherFB() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 200)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 200)); goToCompositeInstanceViewer(UITestNamesHelper.E_CYCLE_FB); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editor); assertNotNull(editor.getEditPart(UITestNamesHelper.E_DELAY_FB)); @@ -184,7 +189,8 @@ public void compositeInstanceViewerEditingOfFB() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void compositeInstanceViewerConnectionCanBeAdded() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 200)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 200)); goToCompositeInstanceViewer(UITestNamesHelper.E_N_TABLE_FB); final SWTBotConnection connect = new SWTBotConnection(bot); SWTBot4diacGefViewer viewer = connect.createConnection(PinNamesHelper.EO, PinNamesHelper.EI); @@ -204,7 +210,8 @@ public void compositeInstanceViewerConnectionCanBeAdded() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void compositeInstanceViewerDeleteConnection() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); goToCompositeInstanceViewer(UITestNamesHelper.E_N_TABLE_FB); final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SWTBotContextMenuUITests.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SWTBotContextMenuUITests.java index 56928b1296..6537987bd4 100644 --- a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SWTBotContextMenuUITests.java +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SWTBotContextMenuUITests.java @@ -21,6 +21,7 @@ import java.util.List; import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotFB; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotSubapp; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotSystemExplorer; import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper; @@ -130,7 +131,8 @@ public void goToParentViaContextMenuEmptySubApp() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void goToParentViaContextMenuSubAppWithFB() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); final SWTBotSubapp subapp = new SWTBotSubapp(bot); subapp.createSubappWithDragRectangle(50, 50, 400, 400); // check System Explorer tree if SubApp is present @@ -153,7 +155,8 @@ public void goToParentViaContextMenuSubAppWithFB() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void goToChildViaContextMenuSubAppWithACompositeFB() { - dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); final SWTBotSubapp subapp = new SWTBotSubapp(bot); subapp.createSubappWithDragRectangle(50, 50, 300, 300); goToCompositeInstanceViewer(UITestNamesHelper.SUBAPP); @@ -162,8 +165,8 @@ public void goToChildViaContextMenuSubAppWithACompositeFB() { bot.toolbarButton(UITestNamesHelper.TOOLBAR_BUTTON_ZOOM_FIT_PAGE).click(); // check bounds of FB - final Rectangle fbBounds = getBoundsOfFB(editorSubApp, UITestNamesHelper.E_N_TABLE_FB); - selectFBWithFBNameInEditor(editorSubApp, UITestNamesHelper.E_N_TABLE_FB); + final Rectangle fbBounds = fbBot.getBoundsOfFB(editorSubApp, UITestNamesHelper.E_N_TABLE_FB); + fbBot.selectFBWithFBNameInEditor(editorSubApp, UITestNamesHelper.E_N_TABLE_FB); editorSubApp.clickContextMenu(UITestNamesHelper.GO_TO_CHILD, fbBounds.x, fbBounds.y); final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot); assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP)); diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SubappSystemExplorerTests.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SubappSystemExplorerTests.java index 152c1cb2c0..5de6fdfa39 100644 --- a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SubappSystemExplorerTests.java +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SubappSystemExplorerTests.java @@ -18,6 +18,7 @@ import java.util.List; +import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotFB; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotSubapp; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotSystemExplorer; import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper; @@ -40,10 +41,11 @@ public class SubappSystemExplorerTests extends Abstract4diacUITests { @SuppressWarnings({ "static-method", "static-access" }) @Test public void isSubappInSystemExplorerTree() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); - selectFBWithFBNameInEditor(editor, UITestNamesHelper.E_CYCLE_FB); + fbBot.selectFBWithFBNameInEditor(editor, UITestNamesHelper.E_CYCLE_FB); bot.menu(UITestNamesHelper.SOURCE).menu(UITestNamesHelper.NEW_SUBAPPLICATION).click(); final List selectedEditParts = editor.selectedEditParts(); @@ -72,11 +74,12 @@ public void isSubappInSystemExplorerTree() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void isFbAndSubappInSystemExplorerTree() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(300, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(300, 100)); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); - selectFBWithFBNameInEditor(editor, UITestNamesHelper.E_CYCLE_FB); + fbBot.selectFBWithFBNameInEditor(editor, UITestNamesHelper.E_CYCLE_FB); bot.menu(UITestNamesHelper.SOURCE).menu(UITestNamesHelper.NEW_SUBAPPLICATION).click(); final List selectedEditParts = editor.selectedEditParts(); diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SubapplicationTests.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SubapplicationTests.java index 5f86aee51f..2780540f55 100644 --- a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SubapplicationTests.java +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/SubapplicationTests.java @@ -23,6 +23,7 @@ import org.eclipse.fordiac.ide.model.ui.editors.HandlerHelper; import org.eclipse.fordiac.ide.test.ui.helpers.PinNamesHelper; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotConnection; +import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotFB; import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotSubapp; import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper; import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor; @@ -62,8 +63,9 @@ public void createEmptySubappViaMenu() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void createSubappViaMenu() { - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 100)); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); // drag rectangle over the FBs, therefore FBs should be selected @@ -72,8 +74,8 @@ public void createSubappViaMenu() { List selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); assertEquals(2, selectedEditParts.size()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); bot.menu(UITestNamesHelper.SOURCE).menu(UITestNamesHelper.NEW_SUBAPPLICATION).click(); // renew list of selectedEditParts and then check if SubApp was created @@ -94,8 +96,9 @@ public void createSubappViaMenu() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void createSubappViaMenuWithConnectionBetweenFBs() { - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); assertNotNull(connect.createConnection(PinNamesHelper.EO0, PinNamesHelper.S)); assertNotNull(connect.createConnection(PinNamesHelper.EO1, PinNamesHelper.R)); @@ -111,8 +114,8 @@ public void createSubappViaMenuWithConnectionBetweenFBs() { // expected 5 selected EditParts (2 GefEditPart for the FBs and // 3 GefConnectionEditPars for the connections assertEquals(5, selectedEditParts.size()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); assertTrue(connect.checkIfConnectionCanBeFound(PinNamesHelper.EO0, PinNamesHelper.S)); assertTrue(connect.checkIfConnectionCanBeFound(PinNamesHelper.EO1, PinNamesHelper.R)); assertTrue(connect.checkIfConnectionCanBeFound(PinNamesHelper.Q, PinNamesHelper.G)); @@ -137,9 +140,10 @@ public void createSubappViaMenuWithConnectionBetweenFBs() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void createSubappViaMenuWithExistingConnectionOutsideSubapp() { - dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(300, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(500, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(300, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(500, 100)); final SWTBotConnection connect = new SWTBotConnection(bot); assertNotNull(connect.createConnection(PinNamesHelper.EO, PinNamesHelper.EI)); @@ -151,9 +155,9 @@ public void createSubappViaMenuWithExistingConnectionOutsideSubapp() { List selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); assertEquals(2, selectedEditParts.size()); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); - assertTrue(isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); - assertFalse(isFbSelected(selectedEditParts, UITestNamesHelper.E_CYCLE_TREE_ITEM)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SWITCH_FB)); + assertTrue(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_SR_FB)); + assertFalse(fbBot.isFbSelected(selectedEditParts, UITestNamesHelper.E_CYCLE_TREE_ITEM)); assertTrue(connect.checkIfConnectionCanBeFound(PinNamesHelper.EO, PinNamesHelper.EI)); bot.menu(UITestNamesHelper.SOURCE).menu(UITestNamesHelper.NEW_SUBAPPLICATION).click(); @@ -175,8 +179,9 @@ public void createSubappViaMenuWithExistingConnectionOutsideSubapp() { @SuppressWarnings({ "static-method", "static-access" }) @Test public void createSubappViaMenuThenCreatingConnection() { - dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); - dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 100)); + final SWTBotFB fbBot = new SWTBotFB(bot); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100)); + fbBot.dragAndDropEventsFB(UITestNamesHelper.E_SR_TREE_ITEM, new Point(300, 100)); final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); editor.drag(50, 50, 400, 400); diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotFB.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotFB.java new file mode 100644 index 0000000000..cb6457d56a --- /dev/null +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotFB.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2023, 2024 Andrea Zoitl + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Andrea Zoitl - initial API and implementation and/or initial documentation + * - moved methods that are related to Function Blocks from class + * Abstract4diacUITests here due to architecture redesign and + * created constructor and fields. + *******************************************************************************/ + +package org.eclipse.fordiac.ide.test.ui.helpers; + +import static org.eclipse.swtbot.swt.finder.waits.Conditions.treeItemHasNode; +import static org.junit.jupiter.api.Assertions.assertFalse; +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.application.editparts.FBEditPart; +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.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; +import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor; +import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefFigureCanvas; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; + +public class SWTBotFB { + + private static SWT4diacGefBot bot; + + @SuppressWarnings("static-access") + public SWTBotFB(final SWT4diacGefBot bot) { + this.bot = bot; + } + + /** + * Drags and drops a FB onto the canvas with given name and position. + * + * @param fbName The name of the Function Block. + * @param point The Position of the FB on the canvas. + */ + @SuppressWarnings("static-access") + public static void dragAndDropEventsFB(final String fbName, final Point point) { + final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot); + final SWTBotTreeItem typeLibraryNode = sysEx.expandTypeLibraryTreeItemInSystemExplorer(); + bot.waitUntil(treeItemHasNode(typeLibraryNode, UITestNamesHelper.EVENTS_NODE)); + final SWTBotTreeItem eventsNode = typeLibraryNode.getNode(UITestNamesHelper.EVENTS_NODE); + eventsNode.select(); + eventsNode.expand(); + bot.waitUntil(treeItemHasNode(eventsNode, fbName)); + final SWTBotTreeItem eCycleNode = eventsNode.getNode(fbName); + eCycleNode.select(); + eCycleNode.click(); + + // select application editor + final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME); + final SWTBot4diacGefViewer viewer = (SWTBot4diacGefViewer) editor.getSWTBotGefViewer(); + final SWTBotGefFigureCanvas canvas = viewer.getCanvas(); + + assertNotNull(canvas); + eCycleNode.dragAndDrop(canvas, point); + } + + /** + * Selects a FunctionBlock with the given Name in the editor. + * + * The function block is searched for with the given name in the editor. + * However, as this only selects the name, the parent is retrieved and selected. + * Only then is the searched function block selected as a whole. + * + * @param editor + * @param name + */ + public static SWTBot4diacGefEditor selectFBWithFBNameInEditor(final SWTBot4diacGefEditor editor, + final String name) { + assertNotNull(editor); + assertNotNull(editor.getEditPart(name)); + editor.click(name); + final SWTBotGefEditPart parent = editor.getEditPart(name).parent(); + assertNotNull(parent); + editor.click(parent); + return editor; + } + + /** + * Deletes a FB from the editing area. + * + * @param editor The SWTBot4diacGefEditor from which a FB with given + * instance name should be deleted. + * @param FbInstanceName The instance name of the FB + */ + public static void deleteFB(final SWTBot4diacGefEditor editor, final String FbInstanceName) { + editor.setFocus(); + final SWTBotGefEditPart fb = editor.getEditPart(FbInstanceName).parent(); + fb.select().click(); + bot.menu(UITestNamesHelper.EDIT).menu(UITestNamesHelper.DELETE).click(); + } + + /** + * Checks if FB is selected by searching selectedEditParts list and returns the + * corresponding boolean value. + * + * @param selectedEditParts The List of selected EditParts. + * @param fbName The FB that is searched for. + * @return true if fbName is in the List, otherwise false. + */ + public static boolean isFbSelected(final List selectedEditParts, final String fbName) { + return selectedEditParts.stream().filter(p -> p.part() instanceof FBEditPart).map(p -> (FBEditPart) p.part()) + .anyMatch(fb -> fb.getModel().getName().equals(fbName)); + } + + /** + * Checks if given FB instance name can be found on the editing area. + * + * @param editor The SWTBot4diacGefEditor in which the FB instance name is + * searched + * @param fbName The String of the FB instance name searched for + * @return true if FB is onto editing area, false if not + */ + public static boolean isFBNamePresendOnEditingArea(final SWTBot4diacGefEditor editor, final String fbName) { + final List editParts = editor.editParts(new BaseMatcher() { + @Override + public boolean matches(final Object item) { + return item instanceof FBEditPart; + } + + @Override + public void describeTo(final Description description) { + // method must be implemented but empty since not needed + } + }); + assertFalse(editParts.isEmpty()); + return editParts.stream().filter(p -> p.part() instanceof FBEditPart).map(p -> (FBEditPart) p.part()) + .anyMatch(fb -> fb.getModel().getName().equals(fbName)); + } + +// // TODO duplicate method - check also getBoundsOfFB!!! +// protected static Rectangle getAbsolutePosition(final SWTBotGefEditor editor, final String fb) { +// final SWTBotGefEditPart parent = editor.getEditPart(fb).parent(); +// assertNotNull(parent); +// final IFigure figurePos = ((GraphicalEditPart) parent.part()).getFigure(); +// assertNotNull(figurePos); +// final Rectangle fbBounds = figurePos.getBounds().getCopy(); +// assertNotNull(fbBounds); +// figurePos.translateToAbsolute(fbBounds); +// return fbBounds; +// } + + /** + * Returns the bounds of the searched function block + * + * @param editor + * @param fBname + * @return The rectangle with the bounds of the function block searched for + */ + // TODO duplicate method - check also getAbsolutePosition!!! + public static Rectangle getBoundsOfFB(final SWTBotGefEditor editor, final String fBname) { + editor.getEditPart(fBname); + editor.click(fBname); + final SWTBotGefEditPart parent = editor.getEditPart(fBname).parent(); + assertNotNull(parent); + final IFigure figure = ((GraphicalEditPart) parent.part()).getFigure(); + assertNotNull(figure); + final Rectangle fbBounds = figure.getBounds().getCopy(); + assertNotNull(fbBounds); + figure.translateToAbsolute(fbBounds); + return fbBounds; + } + +}