Skip to content

Commit 48b4c08

Browse files
committed
add test
1 parent ad00f0d commit 48b4c08

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.checkmarx.ast;
2+
3+
import com.checkmarx.ast.asca.ScanDetail;
4+
import com.checkmarx.ast.asca.ScanResult;
5+
import com.checkmarx.ast.asca.Error;
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.util.List;
10+
11+
class ScanResultTest extends BaseTest {
12+
13+
@Test
14+
void testScanAsca_WhenFileWithVulnerabilitiesIsSentWithAgent_ReturnSuccessfulResponseWithCorrectValues() throws Exception {
15+
ScanResult scanResult = wrapper.ScanAsca("src/test/resources/python-vul-file.py", true, "vscode");
16+
17+
// Assertions for the scan result
18+
Assertions.assertNotNull(scanResult.getRequestId(), "Request ID should not be null");
19+
Assertions.assertTrue(scanResult.isStatus(), "Status should be true");
20+
Assertions.assertNull(scanResult.getError(), "Error should be null");
21+
22+
// Ensure scan details are not null and contain at least one entry
23+
Assertions.assertNotNull(scanResult.getScanDetails(), "Scan details should not be null");
24+
Assertions.assertFalse(scanResult.getScanDetails().isEmpty(), "Scan details should contain at least one entry");
25+
26+
// Iterate over all scan details and validate each one
27+
for (ScanDetail scanDetail : scanResult.getScanDetails()) {
28+
Assertions.assertNotNull(scanDetail.getRemediationAdvise(), "Remediation advise should not be null");
29+
Assertions.assertNotNull(scanDetail.getDescription(), "Description should not be null");
30+
}
31+
}
32+
33+
@Test
34+
void testScanAsca_WhenFileWithoutVulnerabilitiesIsSent_ReturnSuccessfulResponseWithCorrectValues() throws Exception {
35+
ScanResult scanResult = wrapper.ScanAsca("src/test/resources/csharp-no-vul.cs", true, null);
36+
Assertions.assertNotNull(scanResult.getRequestId());
37+
Assertions.assertTrue(scanResult.isStatus());
38+
Assertions.assertNull(scanResult.getError());
39+
Assertions.assertNull(scanResult.getScanDetails()); // When no vulnerabilities are found, scan details is null
40+
}
41+
42+
@Test
43+
void testScanAsca_WhenMissingFileExtension_ReturnFileExtensionIsRequiredFailure() throws Exception {
44+
ScanResult scanResult = wrapper.ScanAsca("CODEOWNERS", true, null);
45+
Assertions.assertNotNull(scanResult.getRequestId());
46+
Assertions.assertNotNull(scanResult.getError());
47+
Assertions.assertEquals("The file name must have an extension.", scanResult.getError().getDescription());
48+
}
49+
}

0 commit comments

Comments
 (0)