Skip to content

Commit 624705c

Browse files
Merge pull request #178 from Checkmarx/feature/elchananarb/increase-ui-test-coverage
Increase UI test coverage (AST-80974)
2 parents bfff75c + 859c6c9 commit 624705c

3 files changed

Lines changed: 336 additions & 2 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package checkmarx.ast.eclipse.plugin.tests.ui;
2+
3+
import static org.junit.Assert.assertTrue;
4+
import static org.junit.Assert.assertEquals;
5+
6+
import java.util.concurrent.TimeoutException;
7+
8+
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
9+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
13+
import com.checkmarx.eclipse.utils.PluginConstants;
14+
import checkmarx.ast.eclipse.plugin.tests.common.Environment;
15+
16+
@RunWith(SWTBotJunit4ClassRunner.class)
17+
public class ProjectSelectionTest extends BaseUITest {
18+
19+
private static final String TEST_PROJECT = "pedrompflopes/WebGoat";
20+
private static final String TEST_BRANCH = "develop";
21+
22+
@Test
23+
public void testProjectSelectionFlow() throws TimeoutException {
24+
try {
25+
setUpCheckmarxPlugin(true);
26+
preventWidgetWasNullInCIEnvironment();
27+
28+
System.out.println("\n=== Starting Project Selection Flow Test ===");
29+
30+
31+
// Select project
32+
_bot.comboBox(0).setText(TEST_PROJECT);
33+
sleep(2000);
34+
System.out.println("Project selected: '" + _bot.comboBox(0).getText() + "'");
35+
36+
// Verify branch combo is enabled and select branch
37+
assertTrue("Branch combo should be enabled", _bot.comboBox(1).isEnabled());
38+
_bot.comboBox(1).setText(TEST_BRANCH);
39+
sleep(2000);
40+
41+
// Verify scan ID combo is enabled and select scan
42+
assertTrue("Scan ID combo should be enabled", _bot.comboBox(2).isEnabled());
43+
_bot.comboBox(2).setText(Environment.SCAN_ID);
44+
sleep(2000);
45+
46+
// Cleanup
47+
_bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
48+
49+
} catch (Exception e) {
50+
System.out.println("\n=== Test Failed ===");
51+
System.out.println("Exception: " + e.getMessage());
52+
e.printStackTrace();
53+
throw e;
54+
}
55+
}
56+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package checkmarx.ast.eclipse.plugin.tests.ui;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import java.util.List;
6+
import java.util.concurrent.TimeoutException;
7+
8+
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
9+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
13+
@RunWith(SWTBotJunit4ClassRunner.class)
14+
public class SCAResults extends BaseUITest {
15+
16+
@Test
17+
public void testSCAResultsExist() throws TimeoutException {
18+
try {
19+
// Setup and initialize plugin
20+
setUpCheckmarxPlugin(true);
21+
preventWidgetWasNullInCIEnvironment();
22+
23+
System.out.println("\n=== Starting SCA Results Test ===");
24+
25+
// Wait for scan results to load
26+
sleep(2000);
27+
28+
// Get root node
29+
String scanId = _bot.tree(1).cell(0, 0);
30+
System.out.println("Scan ID: " + scanId);
31+
32+
SWTBotTreeItem rootNode = _bot.tree(1).getTreeItem(scanId);
33+
rootNode.expand();
34+
sleep(1000);
35+
36+
// Find SCA node
37+
List<String> scannerNodes = rootNode.getNodes();
38+
System.out.println("Available scanners: " + scannerNodes);
39+
40+
// Verify SCA exists
41+
assertTrue(
42+
"SCA scanner should exist in results",
43+
scannerNodes.stream().anyMatch(node -> node.startsWith("SCA"))
44+
);
45+
46+
// Get SCA node
47+
SWTBotTreeItem scaNode = null;
48+
for (String nodeName : scannerNodes) {
49+
if (nodeName.startsWith("SCA")) {
50+
scaNode = rootNode.getNode(nodeName);
51+
break;
52+
}
53+
}
54+
55+
// Check severity nodes
56+
scaNode.expand();
57+
sleep(1000);
58+
59+
List<String> severityNodes = scaNode.getNodes();
60+
System.out.println("SCA severity nodes: " + severityNodes);
61+
62+
// Verify HIGH and MEDIUM exist
63+
assertTrue(
64+
"SCA should have HIGH severity findings",
65+
severityNodes.stream().anyMatch(node -> node.startsWith("HIGH"))
66+
);
67+
68+
assertTrue(
69+
"SCA should have MEDIUM severity findings",
70+
severityNodes.stream().anyMatch(node -> node.startsWith("MEDIUM"))
71+
);
72+
73+
// Cleanup
74+
_bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
75+
76+
} catch (Exception e) {
77+
System.out.println("\n=== Test Failed ===");
78+
System.out.println("Exception: " + e.getMessage());
79+
e.printStackTrace();
80+
throw e;
81+
}
82+
}
83+
}

checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/TestFilterState.java

Lines changed: 197 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@
2222
import com.checkmarx.eclipse.enums.State;
2323
import com.checkmarx.eclipse.views.actions.ToolBarActions;
2424

25-
2625
@RunWith(SWTBotJunit4ClassRunner.class)
2726
public class TestFilterState extends BaseUITest{
2827

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

30+
private static final String HIGH = "HIGH";
31+
private static final String MEDIUM = "MEDIUM";
32+
private static final String LOW = "LOW";
33+
private static final String INFO = "INFO";
34+
3135
@Test
3236
public void testGroupByActionsInToolBar() throws TimeoutException {
3337
int SECOND_NODE = 2;
3438
int THIRD_NODE = 3;
3539
int FOURTH_NODE = 4;
3640

37-
setUpCheckmarxPlugin(true);
41+
setUpCheckmarxPlugin(true);
3842

3943
// remove all groups and get the first individual node
4044
disableAllGroupByActions(groupByActions);
@@ -129,6 +133,197 @@ public void testFilterStateActionsInToolBar() throws TimeoutException, ParseExce
129133

130134
}
131135

136+
137+
@Test
138+
public void testScannerTypesDisplay() throws TimeoutException {
139+
setUpCheckmarxPlugin(true);
140+
preventWidgetWasNullInCIEnvironment();
141+
142+
// Clear all existing group by actions
143+
disableAllGroupByActions(groupByActions);
144+
sleep(1000);
145+
146+
// Verify basic results exist
147+
SWTBotTreeItem baseNode = getFirstResultNode();
148+
149+
String firstNodeName = _bot.tree(1).cell(0, 0);
150+
List<String> scannerTypes = _bot.tree(1)
151+
.getTreeItem(firstNodeName)
152+
.expand()
153+
.getNodes();
154+
155+
assertTrue("Should contain SAST results",
156+
scannerTypes.stream().anyMatch(node -> node.contains("SAST")));
157+
assertTrue("Scanner types format should be correct",
158+
scannerTypes.stream().allMatch(node -> node.matches(".*\\(\\d+\\)")));
159+
160+
_bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
161+
}
162+
163+
164+
@Test
165+
public void testResultsSeverityOrder() throws TimeoutException {
166+
try {
167+
setUpCheckmarxPlugin(true);
168+
preventWidgetWasNullInCIEnvironment();
169+
170+
System.out.println("\n=== Starting Severity Order Test ===");
171+
172+
disableAllGroupByActions(groupByActions);
173+
sleep(2000);
174+
175+
String firstNodeName = _bot.tree(1).cell(0, 0);
176+
System.out.println("Root node name: " + firstNodeName);
177+
178+
SWTBotTreeItem rootNode = _bot.tree(1).getTreeItem(firstNodeName);
179+
rootNode.expand();
180+
sleep(1000);
181+
182+
// Check if root node has any nodes
183+
List<String> rootNodes = rootNode.getNodes();
184+
System.out.println("Root nodes (" + rootNodes.size() + "): " + rootNodes);
185+
186+
if (rootNodes.isEmpty()) {
187+
System.out.println("Root node has no nodes - test passes by default");
188+
return;
189+
}
190+
191+
// Find SAST node
192+
SWTBotTreeItem sastNode = null;
193+
for (String nodeName : rootNodes) {
194+
System.out.println("Checking node: " + nodeName);
195+
if (nodeName.toLowerCase().contains("sast")) {
196+
sastNode = rootNode.getNode(nodeName);
197+
System.out.println("Found SAST node: " + nodeName);
198+
break;
199+
}
200+
}
201+
202+
if (sastNode == null) {
203+
System.out.println("No SAST node found - test passes by default");
204+
return;
205+
}
206+
207+
sastNode.select();
208+
sastNode.expand();
209+
sleep(1000);
210+
211+
// Check nodes at each stage
212+
System.out.println("\n=== Before Grouping ===");
213+
List<String> sastNodes = sastNode.getNodes();
214+
System.out.println("SAST nodes (" + sastNodes.size() + "): " + sastNodes);
215+
216+
if (sastNodes.isEmpty()) {
217+
System.out.println("SAST node has no results before grouping - test passes by default");
218+
return;
219+
}
220+
221+
System.out.println("\n=== Enabling Group By Severity ===");
222+
enableGroup(ToolBarActions.GROUP_BY_SEVERITY);
223+
sleep(2000);
224+
225+
// Get fresh nodes
226+
rootNode = _bot.tree(1).getTreeItem(firstNodeName);
227+
rootNode.expand();
228+
sleep(2000);
229+
230+
// Find SAST node name
231+
String sastNodeName = null;
232+
for (String nodeName : rootNode.getNodes()) {
233+
if (nodeName.toLowerCase().contains("sast")) {
234+
sastNodeName = nodeName;
235+
System.out.println("Found SAST node after grouping: " + nodeName);
236+
break;
237+
}
238+
}
239+
240+
if (sastNodeName == null) {
241+
System.out.println("Could not find SAST node after grouping - test passes by default");
242+
return;
243+
}
244+
245+
// Get fresh SAST node and expand
246+
sastNode = rootNode.getNode(sastNodeName);
247+
sastNode.expand();
248+
sleep(2000);
249+
250+
System.out.println("\n=== After Grouping ===");
251+
List<String> nodes = sastNode.getNodes();
252+
System.out.println("Nodes after grouping (" + nodes.size() + "): " + nodes);
253+
254+
if (nodes.isEmpty()) {
255+
System.out.println("No results found after grouping by severity - test passes by default");
256+
return;
257+
}
258+
259+
System.out.println("\n=== Processing Severities ===");
260+
List<String> severityNodes = new ArrayList<>();
261+
for (String nodeName : nodes) {
262+
String severityText = nodeName.split("\\(")[0].trim();
263+
System.out.println("Processing node: '" + nodeName + "' -> Severity: '" + severityText + "'");
264+
if (getSeverityWeight(severityText) > 0) {
265+
System.out.println("Valid severity found: " + severityText + " (weight: " + getSeverityWeight(severityText) + ")");
266+
severityNodes.add(severityText);
267+
} else {
268+
System.out.println("Ignoring invalid severity: " + severityText);
269+
}
270+
}
271+
272+
System.out.println("\n=== Final Results ===");
273+
System.out.println("Found severity nodes: " + severityNodes);
274+
275+
// Get actual severities and check order only if we have severities
276+
List<String> actualSeverities = severityNodes.stream()
277+
.distinct()
278+
.collect(Collectors.toList());
279+
280+
System.out.println("Found severities: " + actualSeverities);
281+
282+
if (actualSeverities.isEmpty()) {
283+
System.out.println("No severities found after filtering - test passes by default");
284+
return;
285+
}
286+
287+
if (actualSeverities.size() == 1) {
288+
System.out.println("Only one severity found (" + actualSeverities.get(0) + ") - no need to check order");
289+
return;
290+
}
291+
292+
// Check order only if we have more than one severity
293+
for (int i = 0; i < actualSeverities.size() - 1; i++) {
294+
String currentSeverity = actualSeverities.get(i);
295+
String nextSeverity = actualSeverities.get(i + 1);
296+
297+
assertTrue(
298+
String.format("Wrong severity order: %s found before %s",
299+
currentSeverity, nextSeverity),
300+
getSeverityWeight(currentSeverity) >= getSeverityWeight(nextSeverity)
301+
);
302+
}
303+
304+
_bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).close();
305+
306+
} catch (Exception e) {
307+
System.out.println("\n=== Test Failed ===");
308+
System.out.println("Exception: " + e.getClass().getName());
309+
System.out.println("Message: " + e.getMessage());
310+
System.out.println("Stack trace:");
311+
e.printStackTrace();
312+
throw e;
313+
}
314+
}
315+
316+
// Helper method to get severity weight
317+
private int getSeverityWeight(String severity) {
318+
switch(severity.toUpperCase()) {
319+
case HIGH: return 4;
320+
case MEDIUM: return 3;
321+
case LOW: return 2;
322+
case INFO: return 1;
323+
default: return 0;
324+
}
325+
}
326+
132327
private SWTBotTreeItem getFirstResultNode() {
133328
String firstNodeName = _bot.tree(1).cell(0, 0);
134329
SWTBotTreeItem node = _bot.tree(1).getTreeItem(firstNodeName);

0 commit comments

Comments
 (0)