Skip to content

Commit

Permalink
Creation of supporting SWTBot class SWTBotECC eclipse-4diac#377
Browse files Browse the repository at this point in the history
- Creation of supporting SWTBot class SWTBotECC and related methods are
moved here from Abstract4diacUITests
- ECCEditorTests are adapted to this changes and are running again

Addresses eclipse-4diac#377
  • Loading branch information
Andrearium committed Sep 19, 2024
1 parent 42fed24 commit 4c0a1c4
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotPropertySheet;
import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotSystemExplorer;
import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWT4diacGefBot;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefViewer;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacNatTable;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
Expand Down Expand Up @@ -194,71 +187,6 @@ protected static void changeCellValueInNatTbale(final SWTBot4diacNatTable dataTy
assertEquals(dataTypeTableBot.getCellDataValueByPosition(row, col), newValue);
}

/**
* Change the algorithm or event value of an EC state action.
*
* @param editor The ECC editor.
* @param stateName The name of the EC state.
* @param value The value to assign (algorithm or event).
* @param index The index of the item box to modify.
*/
protected static void changeAlgorithmAndEventValue(final SWTBot4diacGefEditor editor, final String partLabel,
final String newValue, final int boxIndex) {
final SWTBotGefEditPart box = getChildrenPart(editor.getEditPart(partLabel), boxIndex);
box.doubleClick().select();
editor.bot().ccomboBox().setSelection(newValue);
box.doubleClick().select();
assertEquals(editor.bot().ccomboBox().selection(), newValue);
}

/**
* Retrieves the center point of a graphical part within the editor.
*
*
* @param editPart The graphical part for which to get the center point.
* @return A Point object representing the center coordinates of the part.
*/
protected static Point getPoint(final SWTBotGefEditPart editPart) {
final IFigure figure = ((GraphicalEditPart) editPart.part()).getFigure();
assertNotNull(figure);
final Rectangle statePartBounds = ((GraphicalEditPart) editPart.part()).getFigure().getBounds().getCopy();
assertNotNull(statePartBounds);
figure.translateToAbsolute(statePartBounds);
return new Point(statePartBounds.getCenter().x, statePartBounds.getCenter().y);

}

/**
* Retrieves a child part of a given parent part at a specified index.
*
* @param parentPart The parent part from which to retrieve the child.
* @param index The index of the child part to retrieve. Use 0 for the
* first child, -1 for the last child, or any other index.
* @return The SWTBotGefEditPart corresponding to the specified child.
*/
protected static SWTBotGefEditPart getChildrenPart(final SWTBotGefEditPart parentPart, final int index) {
final List<SWTBotGefEditPart> childParts = parentPart.children();
assertNotNull(childParts);
return switch (index) {
case 0 -> {
final SWTBotGefEditPart childPart = childParts.getFirst();
assertNotNull(childPart);
yield childPart;
}
case -1 -> {
final SWTBotGefEditPart childPart = childParts.getLast();
assertNotNull(childPart);
yield childPart;
}
default -> {
final SWTBotGefEditPart childPart = childParts.get(index);
assertNotNull(childPart);
yield childPart;
}
};

}

/**
* Returns from CompositeinstanceViewer back to Editing Area
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.eclipse.fordiac.ide.test.ui.Abstract4diacUITests;
import org.eclipse.fordiac.ide.test.ui.helpers.UITestPinHelper;
import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotECC;
import org.eclipse.fordiac.ide.test.ui.helpers.SWTBotFBType;
import org.eclipse.fordiac.ide.test.ui.helpers.UITestNamesHelper;
import org.eclipse.fordiac.ide.test.ui.helpers.UITestPinHelper;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefViewer;
import org.eclipse.swt.graphics.Point;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void changeECStateNameWithTab() {
public void createECAction() {
final SWTBotGefEditPart statePart = editor.getEditPart(UITestNamesHelper.TESTSTATE);
assertNotNull(statePart);
final Point testStatePoint = getPoint(statePart);
final Point testStatePoint = new SWTBotECC(bot).getPoint(statePart);
editor.clickContextMenu(UITestNamesHelper.ADD_ACTION, testStatePoint.x, testStatePoint.y);
assertNotNull(editor.getEditPart(UITestNamesHelper.TESTSTATE).children());
}
Expand All @@ -124,7 +125,8 @@ public void createECAction() {
@Test
@Order(4)
public void createAlgorithm() {
changeAlgorithmAndEventValue(editor, UITestNamesHelper.TESTSTATE, UITestNamesHelper.DEINITIALIZE, 0);
new SWTBotECC(bot).changeAlgorithmAndEventValue(editor, UITestNamesHelper.TESTSTATE,
UITestNamesHelper.DEINITIALIZE, 0);
}

/**
Expand All @@ -135,7 +137,7 @@ public void createAlgorithm() {
@Test
@Order(5)
public void createOutputEvent() {
changeAlgorithmAndEventValue(editor, UITestNamesHelper.DEINIT, UITestNamesHelper.CNF, -1);
new SWTBotECC(bot).changeAlgorithmAndEventValue(editor, UITestNamesHelper.DEINIT, UITestNamesHelper.CNF, -1);
}

/**
Expand All @@ -147,11 +149,12 @@ public void createOutputEvent() {
@Order(6)
public void createTransition() {
final SWTBotGefEditPart statePart = editor.getEditPart(UITestNamesHelper.START);
final Point start = getPoint(statePart);
final SWTBotECC eccBot = new SWTBotECC(bot);
final Point start = eccBot.getPoint(statePart);
assertNotNull(start);

final SWTBotGefEditPart endPart = editor.getEditPart(UITestNamesHelper.TESTSTATE);
final Point end = getPoint(endPart);
final Point end = eccBot.getPoint(endPart);
assertNotNull(end);

final SWTBot4diacGefViewer viewer = editor.getSWTBotGefViewer();
Expand All @@ -166,7 +169,8 @@ public void createTransition() {
@Test
@Order(7)
public void changeAlgorithm() {
changeAlgorithmAndEventValue(editor, UITestNamesHelper.TESTSTATE, UITestNamesHelper.INITIALIZE, 0);
new SWTBotECC(bot).changeAlgorithmAndEventValue(editor, UITestNamesHelper.TESTSTATE,
UITestNamesHelper.INITIALIZE, 0);
}

/**
Expand All @@ -177,7 +181,8 @@ public void changeAlgorithm() {
@Test
@Order(8)
public void changeConditionEvent() {
changeAlgorithmAndEventValue(editor, UITestNamesHelper.INIT_SMALL, UITestNamesHelper.CNF, -1);
new SWTBotECC(bot).changeAlgorithmAndEventValue(editor, UITestNamesHelper.INIT_SMALL, UITestNamesHelper.CNF,
-1);
}

/**
Expand All @@ -189,21 +194,21 @@ public void changeConditionEvent() {
@Order(9)
public void changeECTransitionConditionExpression() {
final SWTBotGefEditPart part = editor
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QI + "]");
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QI + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
editor.select(part);
final SWTBot propertiesBot = selectTabFromECCProperties(UITestNamesHelper.TRANSITION);
assertNotNull(propertiesBot);

propertiesBot.ccomboBoxWithLabel(UITestNamesHelper.CONDITION_LABEL).setSelection(UITestNamesHelper.REQ);

propertiesBot.styledTextWithLabel(UITestNamesHelper.CONDITION_LABEL)
.setText(UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO);
.setText(UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO); //$NON-NLS-1$
assertEquals(propertiesBot.styledTextWithLabel(UITestNamesHelper.CONDITION_LABEL).getText(),
UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO);
UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO); //$NON-NLS-1$
assertNull(editor
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QI + "]"));
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QI + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNotNull(editor
.getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]"));
.getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

}

Expand All @@ -216,7 +221,7 @@ public void changeECTransitionConditionExpression() {
@Order(10)
public void changeECTransitionComment() {
final SWTBotGefEditPart part = editor
.getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]");
.getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
editor.select(part);
final SWTBot propertiesBot = selectTabFromECCProperties(UITestNamesHelper.TRANSITION);
assertNotNull(propertiesBot);
Expand All @@ -234,8 +239,9 @@ public void changeECTransitionComment() {
@Test
@Order(11)
public void deleteECAction() {
final SWTBotGefEditPart actionPart = getChildrenPart(editor.getEditPart(UITestNamesHelper.TESTSTATE), 0);
final Point actionPoint = getPoint(actionPart);
final SWTBotECC eccBot = new SWTBotECC(bot);
final SWTBotGefEditPart actionPart = eccBot.getChildrenPart(editor.getEditPart(UITestNamesHelper.TESTSTATE), 0);
final Point actionPoint = eccBot.getPoint(actionPart);
actionPart.click();
editor.clickContextMenu(UITestNamesHelper.DELETE, actionPoint.x, actionPoint.y);

Expand Down Expand Up @@ -280,25 +286,25 @@ public void tryToSetInvalidName() {
public void tryToInvalidECTransitionConditionExpression() {
// Select the EC transition part
final SWTBotGefEditPart part = editor
.getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]");
.getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
editor.select(part);

// Access the Transition tab and set an invalid condition
final SWTBot propertiesBot = selectTabFromECCProperties(UITestNamesHelper.TRANSITION);
assertNotNull(propertiesBot);
propertiesBot.ccomboBoxWithLabel(UITestNamesHelper.CONDITION_LABEL).setSelection(UITestNamesHelper.INIT);
propertiesBot.styledTextWithLabel(UITestNamesHelper.CONDITION_LABEL)
.setText(UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB);
.setText(UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB); //$NON-NLS-1$

// Validate the new condition expression
assertEquals(propertiesBot.styledTextWithLabel(UITestNamesHelper.CONDITION_LABEL).getText(),
UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB);
UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB); //$NON-NLS-1$

// Verify that the transition part is correctly updated
assertNull(editor
.getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]"));
.getEditPart(UITestNamesHelper.REQ + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.QO + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNotNull(editor
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]"));
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

/**
Expand Down Expand Up @@ -378,18 +384,18 @@ public void changeEventWithTable() {
public void deleteTransition() {
// Select the transition part and focus on it
final SWTBotGefEditPart part = editor
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]");
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
editor.select(part);
assertNotNull(part);

// Get the location of the transition part and delete it via context menu
final Point partPoint = getPoint(part);
final Point partPoint = new SWTBotECC(bot).getPoint(part);
editor.select(part);
editor.clickContextMenu(UITestNamesHelper.DELETE, partPoint.x, partPoint.y);

// Verify that the transition part is successfully deleted
assertNull(editor
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]"));
.getEditPart(UITestNamesHelper.INIT + "[" + UITestNamesHelper.TRUE + " = " + UITestPinHelper.AB + "]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.eclipse.fordiac.ide.test.ui.helpers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWT4diacGefBot;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;

public class SWTBotECC {

private final SWT4diacGefBot bot;

@SuppressWarnings("static-access")
public SWTBotECC(final SWT4diacGefBot bot) {
this.bot = bot;
}

/**
* Change the algorithm or event value of an EC state action.
*
* @param editor The ECC editor.
* @param stateName The name of the EC state.
* @param value The value to assign (algorithm or event).
* @param index The index of the item box to modify.
*/
public void changeAlgorithmAndEventValue(final SWTBot4diacGefEditor editor, final String partLabel,
final String newValue, final int boxIndex) {
final SWTBotGefEditPart box = getChildrenPart(editor.getEditPart(partLabel), boxIndex);
box.doubleClick().select();
editor.bot().ccomboBox().setSelection(newValue);
box.doubleClick().select();
assertEquals(editor.bot().ccomboBox().selection(), newValue);
}

/**
* Retrieves a child part of a given parent part at a specified index.
*
* @param parentPart The parent part from which to retrieve the child.
* @param index The index of the child part to retrieve. Use 0 for the
* first child, -1 for the last child, or any other index.
* @return The SWTBotGefEditPart corresponding to the specified child.
*/
@SuppressWarnings("static-method")
public SWTBotGefEditPart getChildrenPart(final SWTBotGefEditPart parentPart, final int index) {
final List<SWTBotGefEditPart> childParts = parentPart.children();
assertNotNull(childParts);
return switch (index) {
case 0 -> {
final SWTBotGefEditPart childPart = childParts.getFirst();
assertNotNull(childPart);
yield childPart;
}
case -1 -> {
final SWTBotGefEditPart childPart = childParts.getLast();
assertNotNull(childPart);
yield childPart;
}
default -> {
final SWTBotGefEditPart childPart = childParts.get(index);
assertNotNull(childPart);
yield childPart;
}
};
}

/**
* Retrieves the center point of a graphical part within the editor.
*
*
* @param editPart The graphical part for which to get the center point.
* @return A Point object representing the center coordinates of the part.
*/
@SuppressWarnings("static-method")
public Point getPoint(final SWTBotGefEditPart editPart) {
final IFigure figure = ((GraphicalEditPart) editPart.part()).getFigure();
assertNotNull(figure);
final Rectangle statePartBounds = ((GraphicalEditPart) editPart.part()).getFigure().getBounds().getCopy();
assertNotNull(statePartBounds);
figure.translateToAbsolute(statePartBounds);
return new Point(statePartBounds.getCenter().x, statePartBounds.getCenter().y);
}

}

0 comments on commit 4c0a1c4

Please sign in to comment.