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
1 change: 1 addition & 0 deletions checkmarx-ast-eclipse-plugin-tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand Down
3 changes: 2 additions & 1 deletion checkmarx-ast-eclipse-plugin-tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Require-Bundle:
Bundle-RequiredExecutionEnvironment: JavaSE-17
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
Automatic-Module-Name: com.checkmarx.ast.eclipse.tests
Import-Package: com.checkmarx.eclipse.common.runner
Import-Package: com.checkmarx.eclipse.common.runner,
org.slf4j;version="[2.0.0,3.0.0)"
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package checkmarx.ast.eclipse.plugin.tests.integration;


import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.checkmarx.eclipse.common.runner.Authenticator;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;

import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;

import com.checkmarx.eclipse.common.runner.Authenticator;

public class AuthenticatorIntegrationTest extends BaseIntegrationTest {

private static final Logger logger = LoggerFactory.getLogger(AuthenticatorIntegrationTest.class);

@Mock

private Authenticator authenticator;

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package checkmarx.ast.eclipse.plugin.tests.unit.wrapper;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.util.concurrent.atomic.AtomicReference;

import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;

import com.checkmarx.ast.wrapper.CxConfig;
import com.checkmarx.ast.wrapper.CxWrapper;
import com.checkmarx.eclipse.common.preferences.Preferences;
import com.checkmarx.eclipse.common.wrapper.CxWrapperFactory;

class CxWrapperFactoryTest {

@Test
void testBuildWithNoArgs_usesSavedPreferencesAndStampsAgentName() throws Exception {
AtomicReference<CxConfig> capturedConfig = new AtomicReference<>();

try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> capturedConfig.set((CxConfig) context.arguments().get(0)));
var mockedPreferences = mockStatic(Preferences.class)) {

mockedPreferences.when(Preferences::getApiKey).thenReturn("saved-api-key");
mockedPreferences.when(Preferences::getAdditionalOptions).thenReturn("--saved-param");

CxWrapperFactory.build();

assertEquals(1, mocked.constructed().size());
CxConfig config = capturedConfig.get();
assertNotNull(config);
assertEquals("saved-api-key", config.getApiKey());
assertEquals("--saved-param", String.join(" ", config.getAdditionalParameters()));
assertNotNull(config.getAgentName());
assertTrue(config.getAgentName().startsWith("Eclipse_"),
"Agent name should be stamped as Eclipse_<version>, was: " + config.getAgentName());
}
}

@Test
void testBuildWithExplicitCredentials_doesNotUseSavedPreferences() throws Exception {
AtomicReference<CxConfig> capturedConfig = new AtomicReference<>();

try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> capturedConfig.set((CxConfig) context.arguments().get(0)));
var mockedPreferences = mockStatic(Preferences.class)) {

CxWrapperFactory.build("typed-api-key", "--typed-param");

assertEquals(1, mocked.constructed().size());
CxConfig config = capturedConfig.get();
assertNotNull(config);
assertEquals("typed-api-key", config.getApiKey());
assertEquals("--typed-param", String.join(" ", config.getAdditionalParameters()));
assertTrue(config.getAgentName().startsWith("Eclipse_"));

mockedPreferences.verifyNoInteractions();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package checkmarx.ast.eclipse.plugin.tests.unit.wrapper;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;

import com.checkmarx.ast.project.Project;
import com.checkmarx.ast.wrapper.CxWrapper;
import com.checkmarx.eclipse.common.wrapper.WrapperProvider;

class WrapperProviderTest {

private final WrapperProvider wrapperProvider = new WrapperProvider();

@Test
void testIsAiMcpServerEnabled_forwardsCredentialsAndReturnsWrapperResult() throws Exception {
try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> when(mock.aiMcpServerEnabled()).thenReturn(true))) {

boolean result = wrapperProvider.isAiMcpServerEnabled("api-key", "--param");

assertTrue(result);
assertEquals(1, mocked.constructed().size());
}
}

@Test
void testIsAiMcpServerEnabled_propagatesFalseWhenDisabled() throws Exception {
try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> when(mock.aiMcpServerEnabled()).thenReturn(false))) {

boolean result = wrapperProvider.isAiMcpServerEnabled("api-key", "--param");

assertFalse(result);
}
}

@Test
void testGetProjects_forwardsLimitAndReturnsWrapperResult() throws Exception {
Project mockProject = mock(Project.class);
try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> when(mock.projectList("limit=10")).thenReturn(List.of(mockProject)))) {

List<Project> projects = wrapperProvider.getProjects("limit=10");

assertEquals(1, projects.size());
assertSame(mockProject, projects.get(0));
}
}

@Test
void testTriageGetStates_propagatesExceptionFromWrapper() throws Exception {
try (MockedConstruction<CxWrapper> mocked = mockConstruction(CxWrapper.class,
(mock, context) -> when(mock.triageGetStates(false)).thenThrow(new RuntimeException("boom")))) {

assertThrows(RuntimeException.class, () -> wrapperProvider.triageGetStates(false));
}
}
}
3 changes: 2 additions & 1 deletion checkmarx-ast-eclipse-plugin/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand All @@ -12,7 +13,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="../common-lib/lib/ast-cli-java-wrapper-2.4.24.jar"/>
<classpathentry exported="true" kind="lib" path="../common-lib/lib/ast-cli-java-wrapper-2.4.27.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/commons-lang3-3.18.0.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/jackson-core-2.21.4.jar"/>
<classpathentry kind="lib" path="../common-lib/lib/jackson-databind-2.21.5.jar"/>
Expand Down
2 changes: 0 additions & 2 deletions checkmarx-ast-eclipse-plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ Import-Package: org.eclipse.core.resources,
Bundle-ActivationPolicy: lazy
Bundle-Activator: com.checkmarx.eclipse.Activator
Export-Package: com.checkmarx.eclipse.enums,
com.checkmarx.eclipse.properties,
com.checkmarx.eclipse.utils
Bundle-ClassPath: .,
lib/org.eclipse.mylyn.commons.ui_4.9.0.v20251121-0615.jar,
lib/org-eclipse-mylyn-commons-core.jar

Loading
Loading