-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Create draft release | ||
name: Create draft release | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
...y-plugin-server/src/test/java/com/checkmarx/teamcity/server/CheckmarxScanRunTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.checkmarx.teamcity.server; | ||
|
||
import com.checkmarx.teamcity.common.CheckmarxParams; | ||
import com.checkmarx.teamcity.common.CheckmarxScanRunnerConstants; | ||
import jetbrains.buildServer.serverSide.InvalidProperty; | ||
import jetbrains.buildServer.serverSide.PropertiesProcessor; | ||
import jetbrains.buildServer.serverSide.RunTypeRegistry; | ||
import jetbrains.buildServer.web.openapi.PluginDescriptor; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class CheckmarxScanRunTypeTest { | ||
|
||
@Mock | ||
private PluginDescriptor pluginDescriptor; | ||
|
||
@Mock | ||
private RunTypeRegistry runTypeRegistry; | ||
|
||
private CheckmarxScanRunType scanRunType; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
scanRunType = new CheckmarxScanRunType(runTypeRegistry, pluginDescriptor); | ||
verify(runTypeRegistry).registerRunType(scanRunType); | ||
} | ||
|
||
@Test | ||
void testRunTypeBasicProperties() { | ||
when(pluginDescriptor.getPluginResourcesPath("editCheckmarxScanRunnerParameters.jsp")) | ||
.thenReturn("checkmarx/editScan.jsp"); | ||
when(pluginDescriptor.getPluginResourcesPath("viewCheckmarxScanRunnerParameters.jsp")) | ||
.thenReturn("checkmarx/viewScan.jsp"); | ||
|
||
assertEquals(CheckmarxScanRunnerConstants.RUNNER_TYPE, scanRunType.getType()); | ||
assertEquals(CheckmarxScanRunnerConstants.RUNNER_DISPLAY_NAME, scanRunType.getDisplayName()); | ||
assertEquals(CheckmarxScanRunnerConstants.RUNNER_DESCRIPTION, scanRunType.getDescription()); | ||
assertEquals("checkmarx/editScan.jsp", scanRunType.getEditRunnerParamsJspFilePath()); | ||
assertEquals("checkmarx/viewScan.jsp", scanRunType.getViewRunnerParamsJspFilePath()); | ||
} | ||
|
||
@Test | ||
void testGetDefaultRunnerProperties() { | ||
Map<String, String> defaults = scanRunType.getDefaultRunnerProperties(); | ||
assertNotNull(defaults); | ||
assertTrue(defaults.isEmpty()); | ||
} | ||
|
||
@Test | ||
void testPropertiesProcessorWithNullProperties() { | ||
PropertiesProcessor processor = scanRunType.getRunnerPropertiesProcessor(); | ||
Collection<InvalidProperty> errors = processor.process(null); | ||
assertTrue(errors.isEmpty()); | ||
} | ||
|
||
@Test | ||
void testPropertiesProcessorWithValidCustomServerProperties() { | ||
PropertiesProcessor processor = scanRunType.getRunnerPropertiesProcessor(); | ||
|
||
Map<String, String> properties = new HashMap<>(); | ||
properties.put(CheckmarxParams.USE_DEFAULT_SERVER, "false"); | ||
properties.put(CheckmarxParams.SERVER_URL, "https://test.checkmarx.com"); | ||
properties.put(CheckmarxParams.BRANCH_NAME, "main"); | ||
|
||
Collection<InvalidProperty> errors = processor.process(properties); | ||
assertTrue(errors.isEmpty()); | ||
} | ||
|
||
@Test | ||
void testPropertiesProcessorWithMissingServerUrl() { | ||
PropertiesProcessor processor = scanRunType.getRunnerPropertiesProcessor(); | ||
|
||
Map<String, String> properties = new HashMap<>(); | ||
properties.put(CheckmarxParams.USE_DEFAULT_SERVER, "false"); | ||
properties.put(CheckmarxParams.BRANCH_NAME, "main"); | ||
|
||
Collection<InvalidProperty> errors = processor.process(properties); | ||
assertFalse(errors.isEmpty()); | ||
assertTrue(errors.stream() | ||
.anyMatch(error -> error.getPropertyName().equals(CheckmarxParams.SERVER_URL))); | ||
} | ||
|
||
@Test | ||
void testPropertiesProcessorWithMissingBranchName() { | ||
PropertiesProcessor processor = scanRunType.getRunnerPropertiesProcessor(); | ||
|
||
Map<String, String> properties = new HashMap<>(); | ||
properties.put(CheckmarxParams.USE_DEFAULT_SERVER, "false"); | ||
properties.put(CheckmarxParams.SERVER_URL, "https://test.checkmarx.com"); | ||
|
||
Collection<InvalidProperty> errors = processor.process(properties); | ||
assertFalse(errors.isEmpty()); | ||
assertTrue(errors.stream() | ||
.anyMatch(error -> error.getPropertyName().equals(CheckmarxParams.BRANCH_NAME))); | ||
} | ||
|
||
@Test | ||
void testPropertiesProcessorWithDefaultServer() { | ||
PropertiesProcessor processor = scanRunType.getRunnerPropertiesProcessor(); | ||
|
||
Map<String, String> properties = new HashMap<>(); | ||
properties.put(CheckmarxParams.USE_DEFAULT_SERVER, CheckmarxScanRunnerConstants.TRUE); | ||
properties.put(CheckmarxParams.BRANCH_NAME, "main"); | ||
|
||
Collection<InvalidProperty> errors = processor.process(properties); | ||
assertTrue(errors.isEmpty()); | ||
} | ||
|
||
@Test | ||
void testPropertiesProcessorWithDefaultServerMissingBranch() { | ||
PropertiesProcessor processor = scanRunType.getRunnerPropertiesProcessor(); | ||
|
||
Map<String, String> properties = new HashMap<>(); | ||
properties.put(CheckmarxParams.USE_DEFAULT_SERVER, CheckmarxScanRunnerConstants.TRUE); | ||
|
||
Collection<InvalidProperty> errors = processor.process(properties); | ||
assertFalse(errors.isEmpty()); | ||
assertTrue(errors.stream() | ||
.anyMatch(error -> error.getPropertyName().equals(CheckmarxParams.BRANCH_NAME))); | ||
} | ||
} |