|
22 | 22 | import com.checkmarx.eclipse.enums.State; |
23 | 23 | import com.checkmarx.eclipse.views.actions.ToolBarActions; |
24 | 24 |
|
25 | | - |
26 | 25 | @RunWith(SWTBotJunit4ClassRunner.class) |
27 | 26 | public class TestFilterState extends BaseUITest{ |
28 | 27 |
|
29 | 28 | List<String> groupByActions = Arrays.asList(ToolBarActions.GROUP_BY_QUERY_NAME,ToolBarActions.GROUP_BY_SEVERITY,ToolBarActions.GROUP_BY_STATE_NAME); |
30 | 29 |
|
| 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 | + |
31 | 35 | @Test |
32 | 36 | public void testGroupByActionsInToolBar() throws TimeoutException { |
33 | 37 | int SECOND_NODE = 2; |
34 | 38 | int THIRD_NODE = 3; |
35 | 39 | int FOURTH_NODE = 4; |
36 | 40 |
|
37 | | - setUpCheckmarxPlugin(true); |
| 41 | + setUpCheckmarxPlugin(true); |
38 | 42 |
|
39 | 43 | // remove all groups and get the first individual node |
40 | 44 | disableAllGroupByActions(groupByActions); |
@@ -129,6 +133,197 @@ public void testFilterStateActionsInToolBar() throws TimeoutException, ParseExce |
129 | 133 |
|
130 | 134 | } |
131 | 135 |
|
| 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 | + |
132 | 327 | private SWTBotTreeItem getFirstResultNode() { |
133 | 328 | String firstNodeName = _bot.tree(1).cell(0, 0); |
134 | 329 | SWTBotTreeItem node = _bot.tree(1).getTreeItem(firstNodeName); |
|
0 commit comments