Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package checkmarx.ast.eclipse.plugin.tests.ui;
// package checkmarx.ast.eclipse.plugin.tests.ui;

import static org.junit.Assert.assertTrue;
// import static org.junit.Assert.assertTrue;

import java.util.concurrent.TimeoutException;
// import java.util.concurrent.TimeoutException;

import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.Test;
import org.junit.runner.RunWith;
// import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
// import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
// import org.junit.Test;
// import org.junit.runner.RunWith;

import com.checkmarx.eclipse.utils.PluginConstants;
// import com.checkmarx.eclipse.utils.PluginConstants;

//@RunWith(SWTBotJunit4ClassRunner.class)
public class BestFixLocationTest extends BaseUITest{
// //@RunWith(SWTBotJunit4ClassRunner.class)
// public class BestFixLocationTest extends BaseUITest{

//@Test
public void testBestFixLocation() throws TimeoutException {
// setUpCheckmarxPlugin(true);
// SWTBotTreeItem firstNode = getFirstResultNode();
// firstNode.select();
// sleep(3000);
// String BFLText = _bot.textWithId(PluginConstants.BEST_FIX_LOCATION).getText();
// assertTrue(BFLText.equals(PluginConstants.BFL_FOUND) || BFLText.equals(PluginConstants.BFL_NOT_FOUND));
// _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
}
// //@Test
// public void testBestFixLocation() throws TimeoutException {
// // setUpCheckmarxPlugin(true);
// // SWTBotTreeItem firstNode = getFirstResultNode();
// // firstNode.select();
// // sleep(3000);
// // String BFLText = _bot.textWithId(PluginConstants.BEST_FIX_LOCATION).getText();
// // assertTrue(BFLText.equals(PluginConstants.BFL_FOUND) || BFLText.equals(PluginConstants.BFL_NOT_FOUND));
// // _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
// }


private SWTBotTreeItem getFirstResultNode() {
String firstNodeName = _bot.tree().cell(0, 0);
SWTBotTreeItem node = _bot.tree().getTreeItem(firstNodeName);
while(!node.getNodes().isEmpty()) {
node = node.expand().getNode(0);
}
return node;
}
}
// private SWTBotTreeItem getFirstResultNode() {
// String firstNodeName = _bot.tree().cell(0, 0);
// SWTBotTreeItem node = _bot.tree().getTreeItem(firstNodeName);
// while(!node.getNodes().isEmpty()) {
// node = node.expand().getNode(0);
// }
// return node;
// }
// }
Original file line number Diff line number Diff line change
@@ -1,140 +1,140 @@
package checkmarx.ast.eclipse.plugin.tests.ui;
// package checkmarx.ast.eclipse.plugin.tests.ui;

import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.bindings.keys.ParseException;
// import org.eclipse.jface.bindings.keys.KeyStroke;
// import org.eclipse.jface.bindings.keys.ParseException;

import static org.junit.Assert.assertTrue;
// import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
// import java.util.ArrayList;
// import java.util.Arrays;
// import java.util.List;
// import java.util.concurrent.TimeoutException;
// import java.util.stream.Collectors;

import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.Test;
import org.junit.runner.RunWith;
// import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
// import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
// import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton;
// import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
// import org.junit.Test;
// import org.junit.runner.RunWith;

import com.checkmarx.eclipse.enums.Severity;
import com.checkmarx.eclipse.enums.State;
import com.checkmarx.eclipse.views.actions.ToolBarActions;
// import com.checkmarx.eclipse.enums.Severity;
// import com.checkmarx.eclipse.enums.State;
// import com.checkmarx.eclipse.views.actions.ToolBarActions;


@RunWith(SWTBotJunit4ClassRunner.class)
public class TestFilterState extends BaseUITest{
// @RunWith(SWTBotJunit4ClassRunner.class)
// public class TestFilterState extends BaseUITest{

List<String> groupByActions = Arrays.asList(ToolBarActions.GROUP_BY_QUERY_NAME,ToolBarActions.GROUP_BY_SEVERITY,ToolBarActions.GROUP_BY_STATE_NAME);
// List<String> groupByActions = Arrays.asList(ToolBarActions.GROUP_BY_QUERY_NAME,ToolBarActions.GROUP_BY_SEVERITY,ToolBarActions.GROUP_BY_STATE_NAME);

@Test
public void testGroupByActionsInToolBar() throws TimeoutException {
int SECOND_NODE = 2;
int THIRD_NODE = 3;
int FOURTH_NODE = 4;
// @Test
// public void testGroupByActionsInToolBar() throws TimeoutException {
// int SECOND_NODE = 2;
// int THIRD_NODE = 3;
// int FOURTH_NODE = 4;

setUpCheckmarxPlugin(true);
// setUpCheckmarxPlugin(true);

// remove all groups and get the first individual node
disableAllGroupByActions(groupByActions);
// // remove all groups and get the first individual node
// disableAllGroupByActions(groupByActions);

sleep(1000);
// sleep(1000);

SWTBotTreeItem ll = getFirstResultNode();
ArrayList<String> severityFilters = new ArrayList<>(Arrays.asList(Severity.HIGH.name(), Severity.MEDIUM.name(),Severity.LOW.name(),Severity.INFO.name()));
ArrayList<String> stateFilters = new ArrayList<>(Arrays.asList(State.CONFIRMED.name(),State.IGNORED.name(),State.NOT_EXPLOITABLE.name(),State.NOT_IGNORED.name(),State.PROPOSED_NOT_EXPLOITABLE.name(),State.TO_VERIFY.name(),State.URGENT.name()));
assertTrue(!severityFilters.contains(ll.getText()));
// SWTBotTreeItem ll = getFirstResultNode();
// ArrayList<String> severityFilters = new ArrayList<>(Arrays.asList(Severity.HIGH.name(), Severity.MEDIUM.name(),Severity.LOW.name(),Severity.INFO.name()));
// ArrayList<String> stateFilters = new ArrayList<>(Arrays.asList(State.CONFIRMED.name(),State.IGNORED.name(),State.NOT_EXPLOITABLE.name(),State.NOT_IGNORED.name(),State.PROPOSED_NOT_EXPLOITABLE.name(),State.TO_VERIFY.name(),State.URGENT.name()));
// assertTrue(!severityFilters.contains(ll.getText()));

//enable group by severity (1st level group)
enableGroup(ToolBarActions.GROUP_BY_SEVERITY);
sleep(1000);
String severityFilter = getNodeLabel(SECOND_NODE);
assertTrue(severityFilters.contains(severityFilter));
// //enable group by severity (1st level group)
// enableGroup(ToolBarActions.GROUP_BY_SEVERITY);
// sleep(1000);
// String severityFilter = getNodeLabel(SECOND_NODE);
// assertTrue(severityFilters.contains(severityFilter));

// enable group by state (2nd level group)
enableGroup(ToolBarActions.GROUP_BY_STATE_NAME);
sleep(1000);
String stateFilter = getNodeLabel(THIRD_NODE);
assertTrue(stateFilters.contains(stateFilter));
// // enable group by state (2nd level group)
// enableGroup(ToolBarActions.GROUP_BY_STATE_NAME);
// sleep(1000);
// String stateFilter = getNodeLabel(THIRD_NODE);
// assertTrue(stateFilters.contains(stateFilter));

// enable group by query name (3rd level group)
enableGroup(ToolBarActions.GROUP_BY_QUERY_NAME);
sleep(1000);
String queryNameFilter = getNodeLabel(FOURTH_NODE);
assertTrue(queryNameFilter.startsWith(ll.getText()));
// // enable group by query name (3rd level group)
// enableGroup(ToolBarActions.GROUP_BY_QUERY_NAME);
// sleep(1000);
// String queryNameFilter = getNodeLabel(FOURTH_NODE);
// assertTrue(queryNameFilter.startsWith(ll.getText()));

// Close Checkmarx One Scan view
_bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
}
// // Close Checkmarx One Scan view
// _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
// }

private String getNodeLabel(int i) {
SWTBotTreeItem treeNode = _bot.tree(1).getTreeItem(_bot.tree(1).cell(0, 0));
String value = "";
while(i>0) {
treeNode = treeNode.expand().getNode(0);
i--;
}
value= treeNode.getText().split("\\(")[0].trim();
return value;
}
// private String getNodeLabel(int i) {
// SWTBotTreeItem treeNode = _bot.tree(1).getTreeItem(_bot.tree(1).cell(0, 0));
// String value = "";
// while(i>0) {
// treeNode = treeNode.expand().getNode(0);
// i--;
// }
// value= treeNode.getText().split("\\(")[0].trim();
// return value;
// }

private void enableGroup(String groupBy) {
_bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(ToolBarActions.MENU_GROUP_BY).menu(groupBy).click();
}
// private void enableGroup(String groupBy) {
// _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(ToolBarActions.MENU_GROUP_BY).menu(groupBy).click();
// }

private void disableAllGroupByActions(List<String> groupByActions) {
for(String action : groupByActions) {
SWTBotMenu groupMenu = _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(ToolBarActions.MENU_GROUP_BY).menu(action);
if(groupMenu.isChecked())
groupMenu.click();
}
// private void disableAllGroupByActions(List<String> groupByActions) {
// for(String action : groupByActions) {
// SWTBotMenu groupMenu = _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(ToolBarActions.MENU_GROUP_BY).menu(action);
// if(groupMenu.isChecked())
// groupMenu.click();
// }

}
// }

@Test
public void testFilterStateActionsInToolBar() throws TimeoutException, ParseException{
sleep(1000);
setUpCheckmarxPlugin(true);
// @Test
// public void testFilterStateActionsInToolBar() throws TimeoutException, ParseException{
// sleep(1000);
// setUpCheckmarxPlugin(true);

// deselect all group by actions and enable only the state group by
disableAllGroupByActions(groupByActions);
// // deselect all group by actions and enable only the state group by
// disableAllGroupByActions(groupByActions);

sleep(1000);
_bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(ToolBarActions.MENU_GROUP_BY).menu(ToolBarActions.GROUP_BY_STATE_NAME).click();
// sleep(1000);
// _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(ToolBarActions.MENU_GROUP_BY).menu(ToolBarActions.GROUP_BY_STATE_NAME).click();

// get all filter nodes
List<String> filterStateButtons = Arrays.asList("Not Exploitable","Confirmed","Proposed Not Exploitable","Urgent","Ignored","Not Ignored","To Verify");
List<String> enabledFilters = _bot.tree(1).getTreeItem(_bot.tree(1).cell(0, 0)).expand().getNode(0).expand().getNodes().stream().map(node -> node.split("\\(")[0].trim()).collect(Collectors.toList());
String firstGroup = enabledFilters.get(0);
List<String> filterButton = filterStateButtons.stream().filter(node -> node.equalsIgnoreCase(firstGroup.replace("_", " "))).collect(Collectors.toList());
assertTrue(filterButton.size()==1);
SWTBotToolbarDropDownButton stateFilter = _bot.toolbarDropDownButtonWithTooltip("State");
final SWTBotMenu menuItem = stateFilter.menuItem(filterButton.get(0));
menuItem.setFocus();
menuItem.click();
stateFilter.pressShortcut(KeyStroke.getInstance("ESC"));
// // get all filter nodes
// List<String> filterStateButtons = Arrays.asList("Not Exploitable","Confirmed","Proposed Not Exploitable","Urgent","Ignored","Not Ignored","To Verify");
// List<String> enabledFilters = _bot.tree(1).getTreeItem(_bot.tree(1).cell(0, 0)).expand().getNode(0).expand().getNodes().stream().map(node -> node.split("\\(")[0].trim()).collect(Collectors.toList());
// String firstGroup = enabledFilters.get(0);
// List<String> filterButton = filterStateButtons.stream().filter(node -> node.equalsIgnoreCase(firstGroup.replace("_", " "))).collect(Collectors.toList());
// assertTrue(filterButton.size()==1);
// SWTBotToolbarDropDownButton stateFilter = _bot.toolbarDropDownButtonWithTooltip("State");
// final SWTBotMenu menuItem = stateFilter.menuItem(filterButton.get(0));
// menuItem.setFocus();
// menuItem.click();
// stateFilter.pressShortcut(KeyStroke.getInstance("ESC"));

sleep(1000);
List<String> filteredGroup = new ArrayList<String>();
if(enabledFilters.size()>0) {
filteredGroup = _bot.tree(1).getTreeItem(_bot.tree(1).cell(0, 0)).expand().getNode(0).expand().getNodes().stream().map(node -> node.split("\\(")[0].trim()).collect(Collectors.toList());
assertTrue(!filteredGroup.contains(firstGroup));
}
else {
assertTrue(TestUI.ASSERT_NO_CHINDREN, _bot.tree(1).getTreeItem(_bot.tree(1).cell(0, 0)).expand().getNodes().isEmpty());
}
// sleep(1000);
// List<String> filteredGroup = new ArrayList<String>();
// if(enabledFilters.size()>0) {
// filteredGroup = _bot.tree(1).getTreeItem(_bot.tree(1).cell(0, 0)).expand().getNode(0).expand().getNodes().stream().map(node -> node.split("\\(")[0].trim()).collect(Collectors.toList());
// assertTrue(!filteredGroup.contains(firstGroup));
// }
// else {
// assertTrue(TestUI.ASSERT_NO_CHINDREN, _bot.tree(1).getTreeItem(_bot.tree(1).cell(0, 0)).expand().getNodes().isEmpty());
// }

_bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
// _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();

}
// }

private SWTBotTreeItem getFirstResultNode() {
String firstNodeName = _bot.tree(1).cell(0, 0);
SWTBotTreeItem node = _bot.tree(1).getTreeItem(firstNodeName);
while(!node.getNodes().isEmpty()) {
node = node.expand().getNode(0);
}
return node;
}
}
// private SWTBotTreeItem getFirstResultNode() {
// String firstNodeName = _bot.tree(1).cell(0, 0);
// SWTBotTreeItem node = _bot.tree(1).getTreeItem(firstNodeName);
// while(!node.getNodes().isEmpty()) {
// node = node.expand().getNode(0);
// }
// return node;
// }
// }
Loading
Loading