Skip to content

Commit

Permalink
Restructured supporting Bot class SWTNatTable eclipse-4diac#377
Browse files Browse the repository at this point in the history
This is not a stand-alone commit, the related tests will be adapted to
the new structure in the next commit and therefore only be executable
again at that point in future.

- The class SWTNatTable no longer derives from Abstract4diacUITests
- The class now has a constructor with parameters
SWT4diacGefBot and SWTBot4diacNatTable and corresponding fields.
- The methods are no longer static and the Bot parameters was removed.

Addresses eclipse-4diac#377
  • Loading branch information
Andrearium committed Sep 6, 2024
1 parent 29d5e86 commit 02d83d7
Showing 1 changed file with 90 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Prashantkumar Khatri
* Copyright (c) 2024 Prashantkumar Khatri, 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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* Prashantkumar Khatri - initial API and implementation and/or initial documentation
* Andrea Zoitl - Creation of a fluid API design for UI SWTBot testing
*******************************************************************************/
package org.eclipse.fordiac.ide.test.ui.helpers;

Expand All @@ -20,63 +21,70 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.fordiac.ide.model.datatype.helper.RetainHelper.RetainTag;
import org.eclipse.fordiac.ide.test.ui.Abstract4diacUITests;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWT4diacGefBot;
import org.eclipse.fordiac.ide.test.ui.swtbot.SWTBot4diacNatTable;
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;

public class SWTBotNatTable extends Abstract4diacUITests {
public class SWTBotNatTable {

private final SWT4diacGefBot bot;
private final SWTBot4diacNatTable natTable;

@SuppressWarnings("static-access")
public SWTBotNatTable(final SWT4diacGefBot bot, final SWTBot4diacNatTable natTableBot) {
this.bot = bot;
this.natTable = natTableBot;
}

/**
* Creates a new variable in the Data Type Editor.
*
* @param natTableBot NatTable in which the variable needs to be created.
* @param natTable NatTable in which the variable needs to be created.
*/
public static void createNewVariableInDataTypeEditor(final SWTBot4diacNatTable natTableBot) {
final int rowCount = natTableBot.rowCount();
public void createNewVariableInDataTypeEditor() {
final int rowCount = natTable.rowCount();
bot.button(0).click();
assertEquals(natTableBot.rowCount(), rowCount + 1);
assertEquals(natTable.rowCount(), rowCount + 1);
}

/**
* Changes the value of a specific cell in the NatTable.
*
* @param dataTypeTableBot NatTable containing the targeted cell.
* @param newValue The new value to set in the cell.
* @param row The row number of the cell.
* @param col The column number of the cell.
* @param natTable NatTable containing the targeted cell.
* @param newValue The new value to set in the cell.
* @param row The row number of the cell.
* @param col The column number of the cell.
*/
public static void changeCellValueInNatTbale(final SWTBot4diacNatTable dataTypeTableBot, final String newValue,
final int row, final int col) {
dataTypeTableBot.doubleclick(row, col);
dataTypeTableBot.setCellDataValueByPosition(row, col, newValue);
dataTypeTableBot.doubleclick(row, col);
assertEquals(dataTypeTableBot.getCellDataValueByPosition(row, col), newValue);
public void changeCellValueInNatTbale(final String newValue, final int row, final int col) {
natTable.doubleclick(row, col);
natTable.setCellDataValueByPosition(row, col, newValue);
natTable.doubleclick(row, col);
assertEquals(natTable.getCellDataValueByPosition(row, col), newValue);
}

/**
* Deletes a variable from the Data Type Editor.
*
* @param natTableBot NatTable from which the variable has to be deleted.
* @param srNo The serial number of the variable to be deleted.
* @param natTable NatTable from which the variable has to be deleted.
* @param srNo The serial number of the variable to be deleted.
*/
public static void deleteVariable(final SWTBot4diacNatTable natTableBot, final int srNo) {
final int rowCount = natTableBot.rowCount();
natTableBot.click(srNo, 0);
public void deleteVariable(final int srNo) {
final int rowCount = natTable.rowCount();
natTable.click(srNo, 0);
bot.button(1).click();
assertEquals(natTableBot.rowCount(), rowCount - 1);
assertEquals(natTable.rowCount(), rowCount - 1);
}

/**
* Changes the name of a variable using the toolbar button tool.
*
* @param natTableBot NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param newName The new name for the variable.
* @param natTable NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param newName The new name for the variable.
*/
public static void changeVariableNameWithButtonTool(final SWTBot4diacNatTable natTableBot, final int srNo,
final String newName) {
natTableBot.click(srNo, 1);
public void changeVariableNameWithButtonTool(final int srNo, final String newName) {
natTable.click(srNo, 1);
bot.toolbarButtonWithTooltip(UITestNamesHelper.RENAME_ELEMENT).click();
final SWTBotShell shell = bot.shell(UITestNamesHelper.REFACTORING);
assertNotNull(shell);
Expand All @@ -89,152 +97,148 @@ public static void changeVariableNameWithButtonTool(final SWTBot4diacNatTable na
bot.button(UITestNamesHelper.OK).click();
bot.waitUntil(shellCloses(shell));

assertEquals(natTableBot.getCellDataValueByPosition(srNo, 1), newName);
assertEquals(natTable.getCellDataValueByPosition(srNo, 1), newName);
}

/**
* Attempts to change the name of a variable to an existing name, which should
* fail.
*
* @param natTableBot NatTable containing the variable.
* @param natTable NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param existingName The existing name to be used (which should cause a
* conflict).
* @param curentName The current name of the variable, expected to remain
* unchanged.
*/
public static void changeNameWithExistingName(final SWTBot4diacNatTable natTableBot, final int srNo,
final String existingName, final String curentName) {
createNewVariableInDataTypeEditor(natTableBot);
natTableBot.doubleclick(srNo, 1);
natTableBot.setCellDataValueByPosition(srNo, 1, existingName);
natTableBot.doubleclick(srNo, 1);
public void changeNameWithExistingName(final int srNo, final String existingName, final String curentName) {
createNewVariableInDataTypeEditor();
natTable.doubleclick(srNo, 1);
natTable.setCellDataValueByPosition(srNo, 1, existingName);
natTable.doubleclick(srNo, 1);

// Name should not be changed
assertEquals(natTableBot.getCellDataValueByPosition(srNo, 1), curentName);
assertEquals(natTable.getCellDataValueByPosition(srNo, 1), curentName);
}

/**
* Attempts to set an invalid name for a variable, which should not succeed.
*
* @param natTableBot NatTable containing the variable.
* @param natTable NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param invalidName The invalid name to be set.
* @param curentName The current name of the variable, expected to remain
* unchanged.
*/
public static void setInvalidName(final SWTBot4diacNatTable natTableBot, final int srNo, final String invalidName,
final String curentName) {
natTableBot.doubleclick(srNo, 1);
natTableBot.setCellDataValueByPosition(srNo, 1, invalidName);
natTableBot.doubleclick(srNo, 1);
public void setInvalidName(final int srNo, final String invalidName, final String curentName) {
natTable.doubleclick(srNo, 1);
natTable.setCellDataValueByPosition(srNo, 1, invalidName);
natTable.doubleclick(srNo, 1);

// Name should not be changed
assertEquals(natTableBot.getCellDataValueByPosition(srNo, 1), curentName);
assertEquals(natTable.getCellDataValueByPosition(srNo, 1), curentName);
}

/**
* Changes the data type of a variable in the NatTable.
*
* @param natTableBot NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param dataType The new data type to set for the variable.
* @param natTable NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param dataType The new data type to set for the variable.
*/
public static void changeDataType(final SWTBot4diacNatTable natTableBot, final int srNo, final String dataType) {
natTableBot.doubleclick(1, 2);
public void changeDataType(final int srNo, final String dataType) {
natTable.doubleclick(1, 2);

// Assign the value, e.g., "int"
natTableBot.setCellDataValueByPosition(srNo, 2, dataType);
natTable.setCellDataValueByPosition(srNo, 2, dataType);
final String expectedDataType = dataType.toUpperCase();
natTableBot.doubleclick(srNo, 2);
natTable.doubleclick(srNo, 2);

// It should be converted to uppercase and the change should be valid
assertEquals(natTableBot.getCellDataValueByPosition(1, 2), expectedDataType);
assertEquals(natTable.getCellDataValueByPosition(1, 2), expectedDataType);
}

/**
* Attempts to set an invalid data type for a variable, which should cause an
* error.
*
* @param natTableBot NatTable containing the variable.
* @param natTable NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param dataTypeColumnNo The column number of the data type.
* @param invalidDataType The invalid data type to set.
*/
public static void setInvalidDataType(final SWTBot4diacNatTable natTableBot, final int srNo,
final int dataTypeColumnNo, final String invalidDataType) {
natTableBot.doubleclick(srNo, dataTypeColumnNo);
natTableBot.setCellDataValueByPosition(srNo, dataTypeColumnNo, invalidDataType);
natTableBot.doubleclick(srNo, dataTypeColumnNo);
public void setInvalidDataType(final int srNo, final int dataTypeColumnNo, final String invalidDataType) {
natTable.doubleclick(srNo, dataTypeColumnNo);
natTable.setCellDataValueByPosition(srNo, dataTypeColumnNo, invalidDataType);
natTable.doubleclick(srNo, dataTypeColumnNo);

// Data Type will be changed, but with an error
assertEquals(natTableBot.getCellDataValueByPosition(srNo, dataTypeColumnNo), invalidDataType);
assertEquals(natTable.getCellDataValueByPosition(srNo, dataTypeColumnNo), invalidDataType);
// The cell's background color will change to red
assertNotEquals(natTableBot.click(srNo, dataTypeColumnNo).backgroundColor(), GUIHelper.COLOR_RED);
assertNotEquals(natTable.click(srNo, dataTypeColumnNo).backgroundColor(), GUIHelper.COLOR_RED);
}

/**
* Attempts to set an invalid initial value for a variable.
*
* @param natTableBot NatTable containing the variable.
* @param natTable NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param initialValueColumnNo The column number of the initial value.
* @param invalidInitialValue The invalid initial value to set.
*/
public static void setInvalidInitialValue(final SWTBot4diacNatTable natTableBot, final int srNo,
final int initialValueColumnNo, final String invalidInitialValue) {
setInvalidDataType(natTableBot, srNo, initialValueColumnNo, invalidInitialValue);
public void setInvalidInitialValue(final int srNo, final int initialValueColumnNo,
final String invalidInitialValue) {
setInvalidDataType(srNo, initialValueColumnNo, invalidInitialValue);
}

/**
* Moves a variable up one row in the NatTable.
*
* @param natTableBot NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param natTable NatTable containing the variable.
* @param srNo The serial number of the variable.
*/
public static void moveElementUp(final SWTBot4diacNatTable natTableBot, final int srNo) {
final String upperRowName = natTableBot.getCellDataValueByPosition(srNo - 1, 1);
final String currentRowName = natTableBot.getCellDataValueByPosition(srNo, 1);
natTableBot.click(srNo, 0);
public void moveElementUp(final int srNo) {
final String upperRowName = natTable.getCellDataValueByPosition(srNo - 1, 1);
final String currentRowName = natTable.getCellDataValueByPosition(srNo, 1);
natTable.click(srNo, 0);

// Move the selected variable up
bot.arrowButtonWithTooltip(UITestNamesHelper.MOVE_ELEMENTS_UP).click();
assertEquals(natTableBot.getCellDataValueByPosition(srNo - 1, 1), currentRowName);
assertEquals(natTableBot.getCellDataValueByPosition(srNo, 1), upperRowName);
assertEquals(natTable.getCellDataValueByPosition(srNo - 1, 1), currentRowName);
assertEquals(natTable.getCellDataValueByPosition(srNo, 1), upperRowName);
}

/**
* Moves a variable down one row in the NatTable.
*
* @param natTableBot NatTable containing the variable.
* @param srNo The serial number of the variable.
* @param natTable NatTable containing the variable.
* @param srNo The serial number of the variable.
*/
public static void moveElementDown(final SWTBot4diacNatTable natTableBot, final int srNo) {
final String lowerRowName = natTableBot.getCellDataValueByPosition(srNo + 1, 1);
final String currentRowName = natTableBot.getCellDataValueByPosition(srNo, 1);
natTableBot.click(srNo, 0);
public void moveElementDown(final int srNo) {
final String lowerRowName = natTable.getCellDataValueByPosition(srNo + 1, 1);
final String currentRowName = natTable.getCellDataValueByPosition(srNo, 1);
natTable.click(srNo, 0);

// Move the selected variable down
bot.arrowButtonWithTooltip(UITestNamesHelper.MOVE_ELEMENTS_DOWN).click();
assertEquals(natTableBot.getCellDataValueByPosition(srNo + 1, 1), currentRowName);
assertEquals(natTableBot.getCellDataValueByPosition(srNo, 1), lowerRowName);
assertEquals(natTable.getCellDataValueByPosition(srNo + 1, 1), currentRowName);
assertEquals(natTable.getCellDataValueByPosition(srNo, 1), lowerRowName);
}

/**
* Sets the retain value for a variable in the Data Type Editor.
*
* @param natTableBot NatTable containing the targeted cell for the retain
* @param natTable NatTable containing the targeted cell for the retain
* value.
* @param srNo The row number of the variable for which the retain value
* is to be set.
* @param retainCol The column number where the retain value is to be set.
* @param retainValue The RetainTag value (RETAIN, NO_RETAIN, NOTHING) to be set
* for the variable.
*/
public static void setRetainValue(final SWTBot4diacNatTable natTableBot, final int srNo, final int retainCol,
final RetainTag retainValue) {
natTableBot.doubleclick(srNo, retainCol);
public void setRetainValue(final int srNo, final int retainCol, final RetainTag retainValue) {
natTable.doubleclick(srNo, retainCol);
bot.table().select(retainValue.toString());
assertEquals(natTableBot.getCellDataValueByPosition(srNo, retainCol), retainValue.toString());
assertEquals(natTable.getCellDataValueByPosition(srNo, retainCol), retainValue.toString());
}
}

0 comments on commit 02d83d7

Please sign in to comment.