Skip to content

Commit

Permalink
Created class SWTBotSystemExplorer eclipse-4diac#377
Browse files Browse the repository at this point in the history
Due to the architecture restructuring, the new class
SWTBotSystemExplorer was created. Affected classes were changed to use
this change.

Addresses eclipse-4diac#377
  • Loading branch information
Andrearium committed Aug 16, 2024
1 parent 3977109 commit 4edb2cd
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor;
Expand Down Expand Up @@ -116,7 +117,8 @@ protected static void createProject() {
* @param point The Position of the FB on the canvas.
*/
protected static void dragAndDropEventsFB(final String fbName, final Point point) {
final SWTBotTreeItem typeLibraryNode = expandTypeLibraryTreeItemInSystemExplorer();
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();
Expand All @@ -135,42 +137,6 @@ protected static void dragAndDropEventsFB(final String fbName, final Point point
eCycleNode.dragAndDrop(canvas, point);
}

/**
* Checks if given element is visible in the Application of the System in the
* SystemExplorer Tree.
*
* @param element The name of the element (function block or SubApp) searched
* for in the Application of the System in the SystemExplorer
* tree.
*/
protected static boolean isElementInApplicationOfSystemInSystemExplorer(final String element) {
final SWTBotTreeItem appNode = expandApplicationTreeItemInSystemExplorer();
bot.waitUntil(treeItemHasNode(appNode, element));
final SWTBotTreeItem elementNode = appNode.getNode(element);
assertNotNull(elementNode);
return elementNode.isVisible();
}

/**
* Checks if given Function Block is visible in the SubApp node of the
* Application the System in the SystemExplorer Tree.
*
* @param fbName The name of the function block searched for in the SubApp node
* of the Application in the System in the SystemExplorer tree.
*/
protected static boolean isFBInSubAppOfSystemInSystemExplorer(final String fbName) {
final SWTBotTreeItem subAppNode = expandSubAppTreeItemInSystemExplorer();
final SWTBotTreeItem fbNode = subAppNode.getNode(fbName);
assertNotNull(fbNode);
return fbNode.isVisible();
}

protected static boolean isSubAppNodeInSystemExplorerEmpty() {
final SWTBotTreeItem subAppNode = expandSubAppTreeItemInSystemExplorer();
final List<String> subAppChildren = subAppNode.getNodes();
return subAppChildren.isEmpty();
}

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);
Expand Down Expand Up @@ -648,7 +614,8 @@ protected static void deleteProject() {
@SuppressWarnings("static-method")
@AfterEach
protected void cleanEditorArea() {
final SWTBotTreeItem appNode = expandApplicationTreeItemInSystemExplorer();
final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot);
final SWTBotTreeItem appNode = sysEx.expandApplicationTreeItemInSystemExplorer();
appNode.contextMenu("Open").click();

final SWTBotGefEditor editor = bot.gefEditor(UITestNamesHelper.PROJECT_NAME);
Expand All @@ -672,84 +639,4 @@ protected static void afterClass() {
bot.resetWorkbench();
}

/**
* Expands the 4diac IDE Project node (SWTBotTreeItem) in the System Explorer
*
* @author Andrea Zoitl
* @return treeProjectItem the expanded Project node
*/
private static SWTBotTreeItem expandProjectTreeItemInSystemExplorer() {
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);
treeProjectItem.select();
treeProjectItem.expand();
return treeProjectItem;
}

/**
* Expands the System node (SWTBotTreeItem) in the System Explorer
*
* @author Andrea Zoitl
* @return systemNode the expanded System node
*/
private static SWTBotTreeItem expandSystemTreeItemInSystemExplorer() {
final SWTBotTreeItem treeProjectItem = expandProjectTreeItemInSystemExplorer();
bot.waitUntil(treeItemHasNode(treeProjectItem, UITestNamesHelper.PROJECT_NAME_TREE_ITEM));
final SWTBotTreeItem systemNode = treeProjectItem.getNode(UITestNamesHelper.PROJECT_NAME_TREE_ITEM);
systemNode.select();
systemNode.expand();
return systemNode;
}

/**
* Expands the Type Library node (SWTBotTreeItem) in the System Explorer
*
* @author Andrea Zoitl
* @return typeLibraryNode the expanded Type Library node
*/
private static SWTBotTreeItem expandTypeLibraryTreeItemInSystemExplorer() {
final SWTBotTreeItem treeProjectItem = expandProjectTreeItemInSystemExplorer();
bot.waitUntil(treeItemHasNode(treeProjectItem, UITestNamesHelper.TYPE_LIBRARY_NODE));
final SWTBotTreeItem typeLibraryNode = treeProjectItem.getNode(UITestNamesHelper.TYPE_LIBRARY_NODE);
typeLibraryNode.select();
typeLibraryNode.expand();
return typeLibraryNode;
}

/**
* Expands the Application node (SWTBotTreeItem) in the System Explorer
*
* @author Andrea Zoitl
* @return appNode the expanded Application node
*/
private static SWTBotTreeItem expandApplicationTreeItemInSystemExplorer() {
final SWTBotTreeItem systemNode = expandSystemTreeItemInSystemExplorer();
bot.waitUntil(treeItemHasNode(systemNode, UITestNamesHelper.PROJECT_NAME_APP));
final SWTBotTreeItem appNode = systemNode.getNode(UITestNamesHelper.PROJECT_NAME_APP);
assertNotNull(appNode);
appNode.select();
appNode.expand();
return appNode;
}

/**
* Expands the Subapplication node (SWTBotTreeItem) of the 1. level of an
* Application in the System Explorer
*
* @author Andrea Zoitl
* @return appNode the expanded Application node
*/
private static SWTBotTreeItem expandSubAppTreeItemInSystemExplorer() {
final SWTBotTreeItem appNode = expandApplicationTreeItemInSystemExplorer();
final SWTBotTreeItem subAppNode = appNode.getNode(UITestNamesHelper.SUBAPP);
assertNotNull(subAppNode);
subAppNode.select();
subAppNode.expand();
return subAppNode;
}
}
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.SWTBotSystemExplorer;
import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacFigureCanvas;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor;
Expand All @@ -39,18 +40,18 @@ public class SWTBotContextMenuUITests extends Abstract4diacUITests {
* is then created. It is checked if it is empty and displayed correctly in the
* SystemExplorer
*/
@SuppressWarnings("static-method")
@SuppressWarnings({ "static-method", "static-access" })
@Test
public void createSubapplicationViaContextMenu() {
final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME);

editor.clickContextMenu(UITestNamesHelper.NEW_SUBAPPLICATION, 100, 100);
final List<SWTBotGefEditPart> selectedEditParts = editor.selectedEditParts();
assertEquals(1, selectedEditParts.size());
assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP));
// check App node and SubApp TreeItem in SystemExplorer tree
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isSubAppNodeInSystemExplorerEmpty());
final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot);
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isSubAppNodeInSystemExplorerEmpty());
}

/**
Expand All @@ -60,7 +61,7 @@ public void createSubapplicationViaContextMenu() {
* is then created. It is checked if it is empty and displayed correctly in the
* SystemExplorer
*/
@SuppressWarnings("static-method")
@SuppressWarnings({ "static-method", "static-access" })
@Disabled("until bug in test is found")
@Test
public void createFBViaContextMenu() {
Expand All @@ -80,7 +81,8 @@ public void createFBViaContextMenu() {
editor.directEditType(UITestNamesHelper.E_CYCLE_FB);
bot.sleep(3000);

assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot);
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
}

/**
Expand All @@ -92,24 +94,26 @@ public void createFBViaContextMenu() {
* SystemExplorer tree. Then the subapplication is exited via ContextMenu entry
* "Go To Parent" and SystemExplorer Tree is checked again.
*/
@SuppressWarnings("static-method")
@SuppressWarnings({ "static-method", "static-access" })
@Test
public void goToParentViaContextMenuEmptySubApp() {
final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME);
editor.clickContextMenu(UITestNamesHelper.NEW_SUBAPPLICATION, 100, 100);
// check System Explorer tree if SubApp is present
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isSubAppNodeInSystemExplorerEmpty());

final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot);
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isSubAppNodeInSystemExplorerEmpty());
goToCompositeInstanceViewer(UITestNamesHelper.SUBAPP);
final SWTBot4diacGefEditor editorSubApp = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME);
assertNotNull(editorSubApp);
// check System Explorer tree again after entering subapplication
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isSubAppNodeInSystemExplorerEmpty());
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isSubAppNodeInSystemExplorerEmpty());
editorSubApp.clickContextMenu(UITestNamesHelper.GO_TO_PARENT, 100, 100);
// check System Explorer tree after returning
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isSubAppNodeInSystemExplorerEmpty());
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isSubAppNodeInSystemExplorerEmpty());
}

/**
Expand All @@ -121,28 +125,29 @@ public void goToParentViaContextMenuEmptySubApp() {
* are present in the SystemExplorer tree. Then the SubApp is exited via
* ContextMenu entry "Go To Parent" and SystemExplorer Tree is checked again.
*/
@SuppressWarnings("static-method")
@SuppressWarnings({ "static-method", "static-access" })
@Test
public void goToParentViaContextMenuSubAppWithFB() {
dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100));
createSubappWithDragRectangle(50, 50, 400, 400);
// check System Explorer tree if SubApp is present
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot);
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
goToCompositeInstanceViewer(UITestNamesHelper.SUBAPP);
final SWTBot4diacGefEditor editorSubApp = (SWTBot4diacGefEditor) bot.gefEditor(UITestNamesHelper.PROJECT_NAME);
assertNotNull(editorSubApp);
bot.toolbarButton(UITestNamesHelper.TOOLBAR_BUTTON_ZOOM_FIT_PAGE).click();
// check System Explorer tree again after entering subapplication
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
editorSubApp.clickContextMenu(UITestNamesHelper.GO_TO_PARENT, 100, 100);
// check System Explorer tree after returning
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
}

@SuppressWarnings("static-method")
@SuppressWarnings({ "static-method", "static-access" })
@Test
public void goToChildViaContextMenuSubAppWithACompositeFB() {
dragAndDropEventsFB(UITestNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100));
Expand All @@ -156,8 +161,9 @@ public void goToChildViaContextMenuSubAppWithACompositeFB() {
final Rectangle fbBounds = getBoundsOfFB(editorSubApp, UITestNamesHelper.E_N_TABLE_FB);
selectFBWithFBNameInEditor(editorSubApp, UITestNamesHelper.E_N_TABLE_FB);
editorSubApp.clickContextMenu(UITestNamesHelper.GO_TO_CHILD, fbBounds.x, fbBounds.y);
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_N_TABLE_FB));
final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot);
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_N_TABLE_FB));
}

}
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.SWTBotSystemExplorer;
import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor;
import org.eclipse.swt.graphics.Point;
Expand All @@ -35,7 +36,7 @@ public class SubappSystemExplorerTests extends Abstract4diacUITests {
* the FB is also visible as child of the App node of the System in the
* SystemExplorer tree.
*/
@SuppressWarnings("static-method")
@SuppressWarnings({ "static-method", "static-access" })
@Test
public void isSubappInSystemExplorerTree() {
dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100));
Expand All @@ -49,8 +50,9 @@ public void isSubappInSystemExplorerTree() {
assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP));

// checks for SystemExplorer tree
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot);
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
}

/**
Expand All @@ -65,7 +67,7 @@ public void isSubappInSystemExplorerTree() {
* It is also checked whether E_SWITCH, which does not belong to the SubApp, is
* displayed as Application node.
*/
@SuppressWarnings("static-method")
@SuppressWarnings({ "static-method", "static-access" })
@Test
public void isFbAndSubappInSystemExplorerTree() {
dragAndDropEventsFB(UITestNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100));
Expand All @@ -79,14 +81,15 @@ public void isFbAndSubappInSystemExplorerTree() {
assertEquals(1, selectedEditParts.size());

// checks for App node
final SWTBotSystemExplorer sysEx = new SWTBotSystemExplorer(bot);
assertTrue(isSubappSelected(selectedEditParts, UITestNamesHelper.SUBAPP));
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.E_SWITCH_FB));
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.SUBAPP));
assertTrue(sysEx.isElementInApplicationOfSystemInSystemExplorer(UITestNamesHelper.E_SWITCH_FB));

// checks for SubApp node
assertTrue(isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
assertTrue(sysEx.isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_CYCLE_FB));
assertThrows(WidgetNotFoundException.class,
() -> isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_SWITCH_FB));
() -> sysEx.isFBInSubAppOfSystemInSystemExplorer(UITestNamesHelper.E_SWITCH_FB));
}

}
Loading

0 comments on commit 4edb2cd

Please sign in to comment.