Skip to content

Commit

Permalink
Added SWTBotSubapp helper class eclipse-4diac#377
Browse files Browse the repository at this point in the history
- Created helper class SWTBotSubapp
- Relocated all methods related to subapplications from
Abstract4diacUITests to SWTBotSubapp
- Refactored the tests using these methods

Addresses eclipse-4diac#377
  • Loading branch information
Andrearium committed Aug 21, 2024
1 parent eeaf42a commit 43a2f9b
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -198,21 +189,6 @@ protected static boolean isFbSelected(final List<SWTBotGefEditPart> 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<SWTBotGefEditPart> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,7 +48,8 @@ public void createSubapplicationViaContextMenu() {
editor.clickContextMenu(UITestNamesHelper.NEW_SUBAPPLICATION, 100, 100);
final List<SWTBotGefEditPart> 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));
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,7 +48,8 @@ public void isSubappInSystemExplorerTree() {
bot.menu(UITestNamesHelper.SOURCE).menu(UITestNamesHelper.NEW_SUBAPPLICATION).click();
final List<SWTBotGefEditPart> 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);
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,15 +39,16 @@ 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);
bot.menu(UITestNamesHelper.SOURCE).menu(UITestNamesHelper.NEW_SUBAPPLICATION).click();
editor.drag(50, 50, 500, 500);
final List<SWTBotGefEditPart> selectedEditParts = editor.selectedEditParts();
assertEquals(1, selectedEditParts.size());
assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP));
final SWTBotSubapp subapp = new SWTBotSubapp(bot);
assertTrue(subapp.isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP));
}

/**
Expand All @@ -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<SWTBotGefEditPart> selectedEditParts = editor.selectedEditParts();
assertFalse(selectedEditParts.isEmpty());
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<SWTBotGefEditPart> 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()));
}

}

0 comments on commit 43a2f9b

Please sign in to comment.