Skip to content

Commit ba85277

Browse files
Other/Unite tests and small improvements (AST-128958) (#239)
* Resolved preferences page bugs * Unit tests for dataProvider and code coverage report * Corrected ci.yml * Jars updated * Corrected ci.yml * Corrected ci.yml * pom corrected for results * Corrected ci.yml * Corrected ci.yml * Corrected ci.yml * changes for summary report * changes for summary report * Checkmarx View ubnit tests * ToolbarActionTest ubnit tests * Resolved UI test cases issue * Resolved UI test cases issue * Resolved UI test cases issue * Resolved empty scan Id and and result not loaded issue * Resolved UI test cases issue * Resolved UI test cases issue * Resolved UI test cases issue * Resolved UI test cases issue * Resolved UI test cases issue * Resolved UI test cases issue * Resolved UI test cases issue * Resolved UI test cases issue * Resolved UI test cases issue * Authenticator Unit test cases * Authenticator Unit test cases * Unit test cases for Plugin Utils * Unit test cases for Plugin Utils * Unit test cases for action filter state * Unit test cases for action filter state * Unit test cases increase coverage * Unit test cases for global settings * Resolved latest scan id not appeard * Reseted the ci.yml changes for Push on branch * Jar jackson core changed to resolve scan vuln * Jar jackson core changed to resolve scan vuln * Jar jackson core changed to resolve scan vuln * Jacoco summary report * Jacoco summary report * Jacoco summary report * Review comment resolved
1 parent ee39acb commit ba85277

23 files changed

Lines changed: 1571 additions & 55 deletions

File tree

.github/workflows/ci.yml

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ on:
33
pull_request:
44
branches:
55
- main
6-
push:
7-
branches:
8-
- codeMigration
96

107
jobs:
118

@@ -36,7 +33,16 @@ jobs:
3633
run: |
3734
Xvfb -ac :99 -screen 0 1920x1080x16 &
3835
mvn verify -Dtest.includes="**/ui/*.java"
39-
36+
- name: Upload Coverage Report
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: jacoco-coverage-report-ui
40+
path: checkmarx-ast-eclipse-plugin-tests/target/site/jacoco-aggregate
41+
- name: Generate JaCoCo Badge
42+
uses: cicirello/jacoco-badge-generator@f33476a5a3fd5a4f77cb5eef2ebe728c1dd5b921
43+
with:
44+
jacoco-csv-file: checkmarx-ast-eclipse-plugin-tests/target/site/jacoco-aggregate/jacoco.csv
45+
generate-summary: true
4046
integration-tests:
4147
runs-on: ubuntu-latest
4248
steps:
@@ -64,5 +70,50 @@ jobs:
6470
run: |
6571
Xvfb -ac :99 -screen 0 1920x1080x16 &
6672
mvn verify -Dtest.includes="**/integration/*Test.java"
67-
68-
73+
- name: Upload Coverage Report
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: jacoco-coverage-report-integration
77+
path: checkmarx-ast-eclipse-plugin-tests/target/site/jacoco-aggregate
78+
- name: Generate JaCoCo Badge
79+
uses: cicirello/jacoco-badge-generator@f33476a5a3fd5a4f77cb5eef2ebe728c1dd5b921
80+
with:
81+
jacoco-csv-file: checkmarx-ast-eclipse-plugin-tests/target/site/jacoco-aggregate/jacoco.csv
82+
generate-summary: true
83+
unit-tests:
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v3.5.2
87+
with:
88+
lfs: true
89+
- name: Checkout LFS objects
90+
run: git lfs checkout
91+
- uses: actions/setup-java@v4
92+
with:
93+
distribution: temurin
94+
java-version: 17
95+
- uses: actions/cache@v3
96+
with:
97+
path: ~/.m2/repository
98+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
99+
restore-keys: ${{ runner.os }}-maven-
100+
- name: Run Unit Tests with Coverage
101+
env:
102+
CX_BASE_URI: ${{ secrets.CX_BASE_URI }}
103+
CX_TENANT: ${{ secrets.CX_TENANT }}
104+
CX_APIKEY: ${{ secrets.CX_APIKEY }}
105+
CX_TEST_SCAN: ${{ secrets.CX_TEST_SCAN }}
106+
DISPLAY: :99.0
107+
run: |
108+
Xvfb -ac :99 -screen 0 1920x1080x16 &
109+
mvn clean verify -Dtest.includes="**/unit/**/*Test.java"
110+
- name: Upload Coverage Report
111+
uses: actions/upload-artifact@v4
112+
with:
113+
name: jacoco-coverage-report-unit
114+
path: checkmarx-ast-eclipse-plugin-tests/target/site/jacoco-aggregate
115+
- name: Generate JaCoCo Badge
116+
uses: cicirello/jacoco-badge-generator@f33476a5a3fd5a4f77cb5eef2ebe728c1dd5b921
117+
with:
118+
jacoco-csv-file: checkmarx-ast-eclipse-plugin-tests/target/site/jacoco-aggregate/jacoco.csv
119+
generate-summary: true

checkmarx-ast-eclipse-plugin-tests/.classpath

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@
1414
</attributes>
1515
</classpathentry>
1616
<classpathentry exported="true" kind="lib" path="lib/mockito-core-5.14.2.jar"/>
17-
<classpathentry exported="true" kind="lib" path="lib/objenesis-2.2.jar"/>
18-
<classpathentry exported="true" kind="lib" path="lib/junit-jupiter-5.11.4.jar"/>
19-
<classpathentry kind="lib" path="lib/objenesis-3.3.jar"/>
20-
<classpathentry kind="lib" path="lib/powermock-api-mockito2-2.0.7.jar"/>
2117
<classpathentry kind="lib" path="lib/powermock-core-2.0.9.jar"/>
22-
<classpathentry kind="lib" path="lib/powermock-api-support-1.4.9.jar"/>
23-
<classpathentry kind="lib" path="lib/powermock-module-junit4-2.0.9.jar"/>
24-
<classpathentry kind="lib" path="lib/powermock-module-junit4-common-2.0.9.jar"/>
25-
<classpathentry kind="lib" path="lib/powermock-module-junit4-rule-2.0.9.jar"/>
26-
<classpathentry kind="lib" path="lib/powermock-reflect-2.0.9.jar"/>
2718
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
2819
<attributes>
2920
<attribute name="maven.pomderived" value="true"/>

checkmarx-ast-eclipse-plugin-tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ Require-Bundle:
1212
org.eclipse.jdt.junit5.runtime,
1313
junit-jupiter-api
1414
Bundle-RequiredExecutionEnvironment: JavaSE-17
15-
Bundle-ClassPath: .,lib/mockito-core-5.14.2.jar,lib/powermock-core-*.jar
15+
Bundle-ClassPath: .,lib/mockito-core-5.14.2.jar,lib/powermock-core-*.jar, lib/byte-buddy-1.17.8.jar, lib/byte-buddy-agent-1.17.8.jar
1616
Automatic-Module-Name: com.checkmarx.ast.eclipse.tests
8.6 MB
Binary file not shown.
Binary file not shown.

checkmarx-ast-eclipse-plugin-tests/pom.xml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<properties>
7-
<test.includes>**/Test*.java,**/*Test.java,**/*Tests.java,**/*TestCase.java</test.includes>
7+
<test.includes>
8+
**/Test*.java,**/*Test.java,**/*Tests.java,**/*TestCase.java</test.includes>
89
</properties>
910
<groupId>com.checkmarx.ast.eclipse.tests</groupId>
1011
<artifactId>com.checkmarx.ast.eclipse.tests</artifactId>
@@ -17,6 +18,36 @@
1718
</parent>
1819
<build>
1920
<plugins>
21+
<plugin>
22+
<groupId>org.jacoco</groupId>
23+
<artifactId>jacoco-maven-plugin</artifactId>
24+
<version>0.8.11</version>
25+
<executions>
26+
<execution>
27+
<id>prepare-agent</id>
28+
<goals>
29+
<goal>prepare-agent</goal>
30+
</goals>
31+
<configuration>
32+
<propertyName>tycho.testArgLine</propertyName>
33+
<destFile>${project.build.directory}/jacoco.exec</destFile>
34+
</configuration>
35+
</execution>
36+
<execution>
37+
<id>report</id>
38+
<phase>verify</phase>
39+
<goals>
40+
<goal>report</goal>
41+
</goals>
42+
<configuration>
43+
<formats>
44+
<format>XML</format>
45+
<format>CSV</format>
46+
</formats>
47+
</configuration>
48+
</execution>
49+
</executions>
50+
</plugin>
2051
<plugin>
2152
<groupId>org.eclipse.tycho</groupId>
2253
<artifactId>tycho-surefire-plugin</artifactId>
@@ -26,11 +57,13 @@
2657
<useUIThread>false</useUIThread>
2758
<providerHint>junit5</providerHint>
2859
<failIfNoTests>true</failIfNoTests>
60+
<argLine>${tycho.testArgLine}</argLine>
2961
<includes>
3062
<include>${test.includes}</include>
3163
</includes>
3264
</configuration>
3365
</plugin>
66+
3467
</plugins>
3568
</build>
3669
</project>

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

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.junit.jupiter.api.AfterEach;
1818
import org.junit.jupiter.api.BeforeAll;
1919
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
20+
import org.eclipse.swt.widgets.Decorations;
2021
import org.eclipse.swt.widgets.Tree;
2122

2223
import com.checkmarx.eclipse.utils.PluginConstants;
@@ -302,18 +303,48 @@ protected static void waitUntilBranchComboIsEnabled() throws TimeoutException {
302303
* Wait for connection response
303304
*/
304305
protected static void waitForConnectionResponse() throws TimeoutException {
305-
int retryIdx = 0;
306-
while (!_bot.text(3).getText().equals(INFO_SUCCESSFUL_CONNECTION)) {
307-
if (retryIdx == 10) {
308-
break;
309-
}
310-
_bot.sleep(1000);
311-
retryIdx++;
312-
}
313-
314-
if (retryIdx == 10) {
315-
throw new TimeoutException("Connection validation timeout after 10000ms.");
316-
}
306+
int retryIdx = 0;
307+
while (retryIdx < 10) {
308+
boolean found = false;
309+
int index = 0;
310+
// Search text widgets
311+
while (true) {
312+
try {
313+
String textValue = _bot.text(index).getText();
314+
System.out.println("[waitForConnectionResponse] text[" + index + "]: '" + textValue + "'");
315+
if (textValue.contains(INFO_SUCCESSFUL_CONNECTION)) {
316+
found = true;
317+
break;
318+
}
319+
index++;
320+
} catch (Exception e) {
321+
break;
322+
}
323+
}
324+
// Search label widgets if not found
325+
if (!found) {
326+
index = 0;
327+
while (true) {
328+
try {
329+
String labelValue = _bot.label(index).getText();
330+
System.out.println("[waitForConnectionResponse] label[" + index + "]: '" + labelValue + "'");
331+
if (labelValue.contains(INFO_SUCCESSFUL_CONNECTION)) {
332+
found = true;
333+
break;
334+
}
335+
index++;
336+
} catch (Exception e) {
337+
break;
338+
}
339+
}
340+
}
341+
if (found) {
342+
return;
343+
}
344+
_bot.sleep(1000);
345+
retryIdx++;
346+
}
347+
throw new TimeoutException("Connection validation timeout after 10000ms. See logs for widget contents.");
317348
}
318349

319350
/**
@@ -381,4 +412,4 @@ protected SWTBotTree getResultsTree() {
381412
return _bot.tree(0);
382413
}
383414
}
384-
}
415+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package checkmarx.ast.eclipse.plugin.tests.unit.runner;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
import static org.mockito.Mockito.*;
5+
6+
import java.io.IOException;
7+
8+
import org.junit.jupiter.api.Test;
9+
import org.mockito.MockedConstruction;
10+
import org.mockito.Mockito;
11+
import org.slf4j.Logger;
12+
13+
import com.checkmarx.ast.wrapper.CxException;
14+
import com.checkmarx.ast.wrapper.CxWrapper;
15+
import com.checkmarx.eclipse.runner.Authenticator;
16+
import com.checkmarx.eclipse.utils.PluginConstants;
17+
18+
class AuthenticatorTest {
19+
20+
@Test
21+
void testDoAuthenticationSuccess() throws Exception {
22+
23+
Logger mockLogger = mock(Logger.class);
24+
25+
try (MockedConstruction<CxWrapper> mocked =
26+
Mockito.mockConstruction(CxWrapper.class,
27+
(mock, context) -> when(mock.authValidate()).thenReturn("SUCCESS"))) {
28+
29+
Authenticator authenticator = new Authenticator(mockLogger);
30+
31+
String result = authenticator.doAuthentication("dummyKey", "--param");
32+
33+
assertEquals("SUCCESS", result);
34+
verify(mockLogger).info("Authentication Status: SUCCESS");
35+
}
36+
}
37+
38+
@Test
39+
void testDoAuthenticationIOException() throws Exception {
40+
41+
Logger mockLogger = mock(Logger.class);
42+
43+
try (MockedConstruction<CxWrapper> mocked =
44+
Mockito.mockConstruction(CxWrapper.class,
45+
(mock, context) -> when(mock.authValidate())
46+
.thenThrow(new IOException("IO error")))) {
47+
48+
Authenticator authenticator = new Authenticator(mockLogger);
49+
50+
String result = authenticator.doAuthentication("dummyKey", "--param");
51+
52+
assertEquals("IO error", result);
53+
verify(mockLogger).error(
54+
eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "IO error")),
55+
any(IOException.class)
56+
);
57+
}
58+
}
59+
60+
@Test
61+
void testDoAuthenticationInterruptedException() throws Exception {
62+
63+
Logger mockLogger = mock(Logger.class);
64+
65+
try (MockedConstruction<CxWrapper> mocked =
66+
Mockito.mockConstruction(CxWrapper.class,
67+
(mock, context) -> when(mock.authValidate())
68+
.thenThrow(new InterruptedException("Interrupted")))) {
69+
70+
Authenticator authenticator = new Authenticator(mockLogger);
71+
72+
String result = authenticator.doAuthentication("dummyKey", "--param");
73+
74+
assertEquals("Interrupted", result);
75+
verify(mockLogger).error(
76+
eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Interrupted")),
77+
any(InterruptedException.class)
78+
);
79+
}
80+
}
81+
82+
@Test
83+
void testDoAuthenticationCxException() throws Exception {
84+
85+
Logger mockLogger = mock(Logger.class);
86+
87+
try (MockedConstruction<CxWrapper> mocked =
88+
Mockito.mockConstruction(CxWrapper.class,
89+
(mock, context) -> when(mock.authValidate())
90+
.thenThrow(new CxException(1, "Cx error")))) {
91+
92+
Authenticator authenticator = new Authenticator(mockLogger);
93+
94+
String result = authenticator.doAuthentication("dummyKey", "--param");
95+
96+
assertEquals("Cx error", result);
97+
verify(mockLogger).error(
98+
eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Cx error")),
99+
any(CxException.class)
100+
);
101+
}
102+
}
103+
104+
@Test
105+
void testSingletonInstanceNotNull() {
106+
assertNotNull(Authenticator.INSTANCE);
107+
}
108+
}

0 commit comments

Comments
 (0)