From 43a2f9bfd154a6b35e6fdd008bb763ce723275e0 Mon Sep 17 00:00:00 2001 From: Andrea Zoitl Date: Wed, 21 Aug 2024 13:57:55 +0200 Subject: [PATCH] Added SWTBotSubapp helper class #377 - Created helper class SWTBotSubapp - Relocated all methods related to subapplications from Abstract4diacUITests to SWTBotSubapp - Refactored the tests using these methods Addresses https://github.com/eclipse-4diac/4diac-ide/issues/377 --- .../ide/test/ui/Abstract4diacUITests.java | 24 ------- .../ide/test/ui/SWTBotContextMenuUITests.java | 10 ++- .../test/ui/SubappSystemExplorerTests.java | 7 +- .../ide/test/ui/SubapplicationTests.java | 21 +++--- .../ide/test/ui/helpers/SWTBotSubapp.java | 66 +++++++++++++++++++ 5 files changed, 91 insertions(+), 37 deletions(-) create mode 100644 tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotSubapp.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 b18da5385e..2febe9d1a2 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 @@ -32,7 +32,6 @@ 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.SubAppForFBNetworkEditPart; 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; @@ -131,14 +130,6 @@ protected static void dragAndDropEventsFB(final String fbName, final Point point eCycleNode.dragAndDrop(canvas, point); } - protected static void createSubappWithDragRectangle(final int fromXPosition, final int fromYPosition, - final int toXPosition, final int toYPosition) { - final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); - editor.drag(fromXPosition, fromYPosition, toXPosition, toYPosition); - bot.menu(UITestNamesHelper.SOURCE).menu(UITestNamesHelper.NEW_SUBAPPLICATION).click(); - - } - /** * Selects a FunctionBlock with the given Name in the editor. * @@ -198,21 +189,6 @@ protected static boolean isFbSelected(final List selectedEdit .anyMatch(fb -> fb.getModel().getName().equals(fbName)); } - /** - * Checks if Subapplication is selected by searching selectedEditParts list and - * returns the corresponding boolean value. - * - * @param selectedEditParts The List of selected EditParts. - * @param subAppName The Subapplication that is searched for. - * @return true if Subapplication is in the List, otherwise false. - */ - protected static boolean isSubappSelected(final List selectedEditParts, - final String subAppName) { - return selectedEditParts.stream().filter(p -> p.part() instanceof SubAppForFBNetworkEditPart) - .map(p -> (SubAppForFBNetworkEditPart) p.part()) - .anyMatch(fb -> subAppName.equals(fb.getModel().getName())); - } - /** * Checks if given FB instance name can be found on the editing area. * 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 ec008974f8..56928b1296 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.SWTBotSubapp; 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.SWTBot4diacFigureCanvas; @@ -47,7 +48,8 @@ public void createSubapplicationViaContextMenu() { editor.clickContextMenu(UITestNamesHelper.NEW_SUBAPPLICATION, 100, 100); final List selectedEditParts = editor.selectedEditParts(); assertEquals(1, selectedEditParts.size()); - assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); + final SWTBotSubapp subapp = new SWTBotSubapp(bot); + assertTrue(subapp.isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); // check App node and SubApp TreeItem in SystemExplorer tree final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot); assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP)); @@ -129,7 +131,8 @@ public void goToParentViaContextMenuEmptySubApp() { @Test public void goToParentViaContextMenuSubAppWithFB() { dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100)); - createSubappWithDragRectangle(50, 50, 400, 400); + final SWTBotSubapp subapp = new SWTBotSubapp(bot); + subapp.createSubappWithDragRectangle(50, 50, 400, 400); // check System Explorer tree if SubApp is present final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot); assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP)); @@ -151,7 +154,8 @@ public void goToParentViaContextMenuSubAppWithFB() { @Test public void goToChildViaContextMenuSubAppWithACompositeFB() { dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100)); - createSubappWithDragRectangle(50, 50, 300, 300); + final SWTBotSubapp subapp = new SWTBotSubapp(bot); + subapp.createSubappWithDragRectangle(50, 50, 300, 300); goToCompositeInstanceViewer(UITestNamesHelper.SUBAPP); final SWTBot4diacGefEditor editorSubApp = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); assertNotNull(editorSubApp); 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 cdda4c99c3..152c1cb2c0 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.SWTBotSubapp; 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.SWTBot4diacGefEditor; @@ -47,7 +48,8 @@ public void isSubappInSystemExplorerTree() { bot.menu(UITestNamesHelper.SOURCE).menu(UITestNamesHelper.NEW_SUBAPPLICATION).click(); final List selectedEditParts = editor.selectedEditParts(); assertEquals(1, selectedEditParts.size()); - assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); + final SWTBotSubapp subapp = new SWTBotSubapp(bot); + assertTrue(subapp.isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); // checks for SystemExplorer tree final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot); @@ -82,7 +84,8 @@ public void isFbAndSubappInSystemExplorerTree() { // checks for App node final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot); - assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); + final SWTBotSubapp subapp = new SWTBotSubapp(bot); + assertTrue(subapp.isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP)); assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.E_SWITCH_FB)); 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 fb5efa4276..5f86aee51f 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.SWTBotSubapp; 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; @@ -38,7 +39,7 @@ public class SubapplicationTests extends Abstract4diacUITests { * Checks if a subapplication can be created via menu by selecting the * Application editor breadcrumb. */ - @SuppressWarnings("static-method") + @SuppressWarnings({ "static-method", "static-access" }) @Test public void createEmptySubappViaMenu() { final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); @@ -46,7 +47,8 @@ public void createEmptySubappViaMenu() { editor.drag(50, 50, 500, 500); final List selectedEditParts = editor.selectedEditParts(); assertEquals(1, selectedEditParts.size()); - assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); + final SWTBotSubapp subapp = new SWTBotSubapp(bot); + assertTrue(subapp.isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); } /** @@ -57,15 +59,15 @@ public void createEmptySubappViaMenu() { * is drawn over the FBs. Then a subapplication is created via menu entry * "Source" -> "New subapplication" */ - @SuppressWarnings("static-method") + @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 SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); - // drag rectangle over to FB, therefore FB should be selected - editor.drag(50, 50, 400, 400); + // drag rectangle over the FBs, therefore FBs should be selected + editor.drag(80, 80, 400, 400); assertDoesNotThrow(() -> editor.waitForSelectedFBEditPart()); List selectedEditParts = editor.selectedEditParts(); assertFalse(selectedEditParts.isEmpty()); @@ -77,7 +79,8 @@ public void createSubappViaMenu() { // renew list of selectedEditParts and then check if SubApp was created selectedEditParts = editor.selectedEditParts(); assertEquals(1, selectedEditParts.size()); - assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); + final SWTBotSubapp subapp = new SWTBotSubapp(bot); + assertTrue(subapp.isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); } /** @@ -118,7 +121,8 @@ public void createSubappViaMenuWithConnectionBetweenFBs() { // renew list of selectedEditParts and then check if SubApp was created selectedEditParts = editor.selectedEditParts(); assertEquals(1, selectedEditParts.size()); - assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); + final SWTBotSubapp subapp = new SWTBotSubapp(bot); + assertTrue(subapp.isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); } /** @@ -156,7 +160,8 @@ public void createSubappViaMenuWithExistingConnectionOutsideSubapp() { // renew list of selectedEditParts and then check if SubApp was created selectedEditParts = editor.selectedEditParts(); assertEquals(1, selectedEditParts.size()); - assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); + final SWTBotSubapp subapp = new SWTBotSubapp(bot); + assertTrue(subapp.isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP)); assertTrue(connect.checkIfConnectionCanBeFound(PinNamesHelper.EO, PinNamesHelper.EO)); } diff --git a/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotSubapp.java b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotSubapp.java new file mode 100644 index 0000000000..687fa412e2 --- /dev/null +++ b/tests/org.eclipse.fordiac.ide.test.ui/src/org/eclipse/fordiac/ide/test/ui/helpers/SWTBotSubapp.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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 related to Subapplications from class + * Abstract4diacUITests here due to architecture redesign and + * created constructor and fields. + *******************************************************************************/ + +package org.eclipse.fordiac.ide.test.ui.helpers; + +import java.util.List; + +import org.eclipse.fordiac.ide.application.editparts.SubAppForFBNetworkEditPart; +import org.eclipse.fordiac.ide.test.ui.swtbot.SWT4diacGefBot; +import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor; +import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; + +public class SWTBotSubapp { + + private static SWT4diacGefBot bot; + + @SuppressWarnings("static-access") + public SWTBotSubapp(final SWT4diacGefBot bot) { + this.bot = bot; + } + + /** + * creates a Subapplication by first selecting all elements within the given + * rectangle and then creating the Subapplication. + * + * @param fromXPosition the x value of the starting point + * @param fromYPosition the y value of the starting point + * @param toXPosition the x value of the target point + * @param toYPosition the y value of the target point + */ + public static void createSubappWithDragRectangle(final int fromXPosition, final int fromYPosition, + final int toXPosition, final int toYPosition) { + final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME); + editor.drag(fromXPosition, fromYPosition, toXPosition, toYPosition); + bot.menu(UITestNamesHelper.SOURCE).menu(UITestNamesHelper.NEW_SUBAPPLICATION).click(); + + } + + /** + * Checks if Subapplication is selected by searching selectedEditParts list and + * returns the corresponding boolean value. + * + * @param selectedEditParts The List of selected EditParts. + * @param subAppName The Subapplication that is searched for. + * @return true if Subapplication is in the List, otherwise false. + */ + public static boolean isSubappSelected(final List selectedEditParts, final String subAppName) { + return selectedEditParts.stream().filter(p -> p.part() instanceof SubAppForFBNetworkEditPart) + .map(p -> (SubAppForFBNetworkEditPart) p.part()) + .anyMatch(fb -> subAppName.equals(fb.getModel().getName())); + } + +}