Skip to content

Commit

Permalink
Beginning of the restructuring of the SWTBot tests eclipse-4diac#377
Browse files Browse the repository at this point in the history
- Creation of package org.eclipse.fordiac.ide.test.ui.helpers
- Creation of final class StringNameHelpers
- Creation of final class PinNameHelpers
- Relocate static final Strings from Abstract4diacUITest class into new
classes
- Refactoring the tests to use the new classes

Addresses eclipse-4diac#377
  • Loading branch information
Andrearium committed Aug 12, 2024
1 parent c8c3cf0 commit 4053869
Show file tree
Hide file tree
Showing 13 changed files with 838 additions and 766 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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.StringNamesHelper;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefEditor;
import org.eclipse.swt.graphics.Point;
import org.junit.jupiter.api.Disabled;
Expand Down Expand Up @@ -52,14 +53,14 @@ public class BasicMultipleFBNetworkEditingTests extends Abstract4diacUITests {
@SuppressWarnings("static-method")
@Test
public void checkIfNewFbGetsNextFreeRunningNumber() {
dragAndDropEventsFB(E_CYCLE_TREE_ITEM, new Point(100, 100));
dragAndDropEventsFB(E_SR_TREE_ITEM, new Point(300, 100));
dragAndDropEventsFB(E_CYCLE_TREE_ITEM, new Point(500, 100));
dragAndDropEventsFB(E_CYCLE_TREE_ITEM, new Point(100, 250));
dragAndDropEventsFB(E_SR_TREE_ITEM, new Point(300, 250));
dragAndDropEventsFB(E_CYCLE_TREE_ITEM, new Point(500, 250));

final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(PROJECT_NAME);
dragAndDropEventsFB(StringNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 100));
dragAndDropEventsFB(StringNamesHelper.E_SR_TREE_ITEM, new Point(300, 100));
dragAndDropEventsFB(StringNamesHelper.E_CYCLE_TREE_ITEM, new Point(500, 100));
dragAndDropEventsFB(StringNamesHelper.E_CYCLE_TREE_ITEM, new Point(100, 250));
dragAndDropEventsFB(StringNamesHelper.E_SR_TREE_ITEM, new Point(300, 250));
dragAndDropEventsFB(StringNamesHelper.E_CYCLE_TREE_ITEM, new Point(500, 250));

final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(StringNamesHelper.PROJECT_NAME);
assertNotNull(editor);

assertTrue(isFBNamePresendOnEditingArea(editor, E_CYCLE));
Expand Down Expand Up @@ -87,12 +88,12 @@ public void checkIfNewFbGetsNextFreeRunningNumber() {
@SuppressWarnings("static-method")
@Test
public void checkIfNewFbGetsSmallestNextFreeRunningNumber() {
dragAndDropEventsFB(E_SWITCH_TREE_ITEM, new Point(50, 100));
dragAndDropEventsFB(E_SWITCH_TREE_ITEM, new Point(250, 100));
dragAndDropEventsFB(E_SWITCH_TREE_ITEM, new Point(450, 100));
dragAndDropEventsFB(E_SWITCH_TREE_ITEM, new Point(50, 250));
dragAndDropEventsFB(StringNamesHelper.E_SWITCH_TREE_ITEM, new Point(50, 100));
dragAndDropEventsFB(StringNamesHelper.E_SWITCH_TREE_ITEM, new Point(250, 100));
dragAndDropEventsFB(StringNamesHelper.E_SWITCH_TREE_ITEM, new Point(450, 100));
dragAndDropEventsFB(StringNamesHelper.E_SWITCH_TREE_ITEM, new Point(50, 250));

final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(PROJECT_NAME);
final SWTBot4diacGefEditor editor = (SWTBot4diacGefEditor) bot.gefEditor(StringNamesHelper.PROJECT_NAME);
assertNotNull(editor);

assertTrue(isFBNamePresendOnEditingArea(editor, E_SWITCH));
Expand All @@ -104,18 +105,18 @@ public void checkIfNewFbGetsSmallestNextFreeRunningNumber() {

deleteFB(editor, E_SWITCH_2);
assertFalse(isFBNamePresendOnEditingArea(editor, E_SWITCH_2));
dragAndDropEventsFB(E_SWITCH_TREE_ITEM, new Point(450, 250));
dragAndDropEventsFB(StringNamesHelper.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(E_SWITCH_TREE_ITEM, new Point(450, 100));
dragAndDropEventsFB(E_SWITCH_TREE_ITEM, new Point(250, 100));
dragAndDropEventsFB(E_SWITCH_TREE_ITEM, new Point(250, 250));
dragAndDropEventsFB(E_SWITCH_TREE_ITEM, new Point(50, 100));
dragAndDropEventsFB(StringNamesHelper.E_SWITCH_TREE_ITEM, new Point(450, 100));
dragAndDropEventsFB(StringNamesHelper.E_SWITCH_TREE_ITEM, new Point(250, 100));
dragAndDropEventsFB(StringNamesHelper.E_SWITCH_TREE_ITEM, new Point(250, 250));
dragAndDropEventsFB(StringNamesHelper.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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.fordiac.ide.fbtypeeditor.network.viewer.CompositeInstanceViewer;
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.StringNamesHelper;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacGefViewer;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.GraphicalEditPart;
Expand All @@ -50,14 +52,14 @@ public class CompositeInstanceViewerTests extends Abstract4diacUITests {
@SuppressWarnings("static-method")
@Test
public void compositeInstanceViewerAppearsAfterDoubleClickOnFB() {
dragAndDropEventsFB(E_N_TABLE_TREE_ITEM, new Point(200, 100));
final SWTBotGefEditor editor = goToCompositeInstanceViewer(E_N_TABLE_FB);
dragAndDropEventsFB(StringNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 100));
final SWTBotGefEditor editor = goToCompositeInstanceViewer(StringNamesHelper.E_N_TABLE_FB);

UIThreadRunnable.syncExec(() -> {
final IEditorPart editorPart = editor.getReference().getEditor(false);
if (editorPart instanceof final AbstractBreadCrumbEditor breadCrumbEditor) {
final String title = breadCrumbEditor.getBreadcrumb().getActiveItem().getText();
assertEquals(E_N_TABLE_FB, title);
assertEquals(StringNamesHelper.E_N_TABLE_FB, title);
assertTrue(breadCrumbEditor.getActiveEditor() instanceof CompositeInstanceViewer);
}
});
Expand All @@ -79,14 +81,14 @@ public void compositeInstanceViewerAppearsAfterDoubleClickOnFB() {
@SuppressWarnings("static-method")
@Test
public void compositeInstanceViewerMoveFB() {
dragAndDropEventsFB(E_N_TABLE_TREE_ITEM, new Point(200, 200));
goToCompositeInstanceViewer(E_N_TABLE_FB);
dragAndDropEventsFB(StringNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 200));
goToCompositeInstanceViewer(StringNamesHelper.E_N_TABLE_FB);

final SWTBotGefEditor editor = bot.gefEditor(PROJECT_NAME);
final SWTBotGefEditor editor = bot.gefEditor(StringNamesHelper.PROJECT_NAME);
assertNotNull(editor);
assertNotNull(editor.getEditPart(F_SUB));
editor.click(F_SUB);
SWTBotGefEditPart parent = editor.getEditPart(F_SUB).parent();
assertNotNull(editor.getEditPart(StringNamesHelper.F_SUB));
editor.click(StringNamesHelper.F_SUB);
SWTBotGefEditPart parent = editor.getEditPart(StringNamesHelper.F_SUB).parent();
assertNotNull(parent);

IFigure figure = ((GraphicalEditPart) parent.part()).getFigure();
Expand All @@ -104,7 +106,7 @@ public void compositeInstanceViewerMoveFB() {
editor.drag(parent, pos2.x, pos2.y);
final org.eclipse.draw2d.geometry.Point posToCheck2 = new org.eclipse.draw2d.geometry.Point(pos2);

parent = editor.getEditPart(F_SUB).parent();
parent = editor.getEditPart(StringNamesHelper.F_SUB).parent();
figure = ((GraphicalEditPart) parent.part()).getFigure();
fbBounds = figure.getBounds().getCopy();
figure.translateToAbsolute(fbBounds);
Expand All @@ -124,25 +126,25 @@ public void compositeInstanceViewerMoveFB() {
@SuppressWarnings("static-method")
@Test
public void compositeInstanceViewerDeleteFB() {
dragAndDropEventsFB(E_N_TABLE_TREE_ITEM, new Point(200, 200));
goToCompositeInstanceViewer(E_N_TABLE_FB);
dragAndDropEventsFB(StringNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 200));
goToCompositeInstanceViewer(StringNamesHelper.E_N_TABLE_FB);

final SWTBotGefEditor editor = bot.gefEditor(PROJECT_NAME);
final SWTBotGefEditor editor = bot.gefEditor(StringNamesHelper.PROJECT_NAME);
assertNotNull(editor);
assertNotNull(editor.getEditPart(E_DEMUX_FB));
editor.click(E_DEMUX_FB);
final SWTBotGefEditPart parent = editor.getEditPart(E_DEMUX_FB).parent();
assertNotNull(editor.getEditPart(StringNamesHelper.E_DEMUX_FB));
editor.click(StringNamesHelper.E_DEMUX_FB);
final SWTBotGefEditPart parent = editor.getEditPart(StringNamesHelper.E_DEMUX_FB).parent();
assertNotNull(parent);
parent.click();

assertTrue(bot.menu(EDIT).isVisible());
bot.menu(EDIT).click();
assertTrue(bot.menu(DELETE).isVisible());
assertFalse(bot.menu(DELETE).isEnabled());
assertTrue(bot.menu(StringNamesHelper.EDIT).isVisible());
bot.menu(StringNamesHelper.EDIT).click();
assertTrue(bot.menu(StringNamesHelper.DELETE).isVisible());
assertFalse(bot.menu(StringNamesHelper.DELETE).isEnabled());

bot.menu(EDIT).menu(SELECT_ALL).click();
assertTrue(bot.menu(DELETE).isVisible());
assertFalse(bot.menu(DELETE).isEnabled());
bot.menu(StringNamesHelper.EDIT).menu(StringNamesHelper.SELECT_ALL).click();
assertTrue(bot.menu(StringNamesHelper.DELETE).isVisible());
assertFalse(bot.menu(StringNamesHelper.DELETE).isEnabled());

returnToEditingArea();
}
Expand All @@ -153,13 +155,13 @@ public void compositeInstanceViewerDeleteFB() {
@SuppressWarnings("static-method")
@Test
public void compositeInstanceViewerAddAnotherFB() {
dragAndDropEventsFB(E_CYCLE_TREE_ITEM, new Point(200, 200));
goToCompositeInstanceViewer(E_CYCLE_FB);
dragAndDropEventsFB(E_SWITCH_TREE_ITEM, new Point(100, 100));
final SWTBotGefEditor editor = bot.gefEditor(PROJECT_NAME);
dragAndDropEventsFB(StringNamesHelper.E_CYCLE_TREE_ITEM, new Point(200, 200));
goToCompositeInstanceViewer(StringNamesHelper.E_CYCLE_FB);
dragAndDropEventsFB(StringNamesHelper.E_SWITCH_TREE_ITEM, new Point(100, 100));
final SWTBotGefEditor editor = bot.gefEditor(StringNamesHelper.PROJECT_NAME);
assertNotNull(editor);
assertNotNull(editor.getEditPart(E_DELAY_FB));
assertNull(editor.getEditPart(E_SWITCH_FB));
assertNotNull(editor.getEditPart(StringNamesHelper.E_DELAY_FB));
assertNull(editor.getEditPart(StringNamesHelper.E_SWITCH_FB));
returnToEditingArea();
}

Expand All @@ -181,15 +183,15 @@ public void compositeInstanceViewerEditingOfFB() {
@SuppressWarnings("static-method")
@Test
public void compositeInstanceViewerConnectionCanBeAdded() {
dragAndDropEventsFB(E_N_TABLE_TREE_ITEM, new Point(200, 200));
goToCompositeInstanceViewer(E_N_TABLE_FB);
SWTBot4diacGefViewer viewer = createConnection(EO, EI);
dragAndDropEventsFB(StringNamesHelper.E_N_TABLE_TREE_ITEM, new Point(200, 200));
goToCompositeInstanceViewer(StringNamesHelper.E_N_TABLE_FB);
SWTBot4diacGefViewer viewer = createConnection(PinNamesHelper.EO, PinNamesHelper.EI);
assertThrows(TimeoutException.class, viewer::waitForConnection);
viewer = createConnection(N, CV);
viewer = createConnection(PinNamesHelper.N, PinNamesHelper.CV);
assertThrows(TimeoutException.class, viewer::waitForConnection);
viewer = createConnection(START, STOP);
viewer = createConnection(PinNamesHelper.START, PinNamesHelper.STOP);
assertThrows(TimeoutException.class, viewer::waitForConnection);
viewer = createConnection(START, EO0);
viewer = createConnection(PinNamesHelper.START, PinNamesHelper.EO0);
assertThrows(TimeoutException.class, viewer::waitForConnection);
returnToEditingArea();
}
Expand All @@ -200,12 +202,12 @@ public void compositeInstanceViewerConnectionCanBeAdded() {
@SuppressWarnings("static-method")
@Test
public void compositeInstanceViewerDeleteConnection() {
dragAndDropEventsFB(E_N_TABLE_TREE_ITEM, new Point(100, 100));
goToCompositeInstanceViewer(E_N_TABLE_FB);
dragAndDropEventsFB(StringNamesHelper.E_N_TABLE_TREE_ITEM, new Point(100, 100));
goToCompositeInstanceViewer(StringNamesHelper.E_N_TABLE_FB);

final SWTBotGefEditor editor = bot.gefEditor(PROJECT_NAME);
final SWTBotGefEditor editor = bot.gefEditor(StringNamesHelper.PROJECT_NAME);
final SWTBot4diacGefViewer viewer = (SWTBot4diacGefViewer) editor.getSWTBotGefViewer();
final ConnectionEditPart connection = findConnection(EO, REQ);
final ConnectionEditPart connection = findConnection(PinNamesHelper.EO, PinNamesHelper.REQ);
final PolylineConnection figure = (PolylineConnection) connection.getFigure();
final PointList points = figure.getPoints();
final org.eclipse.draw2d.geometry.Point firstPoint = points.getFirstPoint();
Expand All @@ -218,15 +220,15 @@ public void compositeInstanceViewerDeleteConnection() {
final IEditorPart editorPart = editor.getReference().getEditor(false);
if (editorPart instanceof final AbstractBreadCrumbEditor breadCrumbEditor) {
final String title = breadCrumbEditor.getBreadcrumb().getActiveItem().getText();
assertEquals(E_N_TABLE_FB, title);
assertEquals(StringNamesHelper.E_N_TABLE_FB, title);
assertTrue(breadCrumbEditor.getActiveEditor() instanceof CompositeInstanceViewer);
}
});

assertFalse(bot.menu(EDIT).menu(DELETE).isEnabled());
assertTrue(bot.menu(EDIT).menu(SELECT_ALL).isEnabled());
bot.menu(EDIT).menu(SELECT_ALL).click();
assertFalse(bot.menu(EDIT).menu(DELETE).isEnabled());
assertFalse(bot.menu(StringNamesHelper.EDIT).menu(StringNamesHelper.DELETE).isEnabled());
assertTrue(bot.menu(StringNamesHelper.EDIT).menu(StringNamesHelper.SELECT_ALL).isEnabled());
bot.menu(StringNamesHelper.EDIT).menu(StringNamesHelper.SELECT_ALL).click();
assertFalse(bot.menu(StringNamesHelper.EDIT).menu(StringNamesHelper.DELETE).isEnabled());
returnToEditingArea();
}

Expand Down
Loading

0 comments on commit 4053869

Please sign in to comment.