Skip to content

Commit

Permalink
Merge pull request #786 from jenkinsci/parasoft
Browse files Browse the repository at this point in the history
Add an integration test for the parser of the parasoft-findings plugin
  • Loading branch information
uhafner authored Jan 6, 2024
2 parents d58413e + 545fa8a commit a698285
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 5 deletions.
6 changes: 6 additions & 0 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@
</dependency>

<!-- Jenkins Plug-in Dependencies required for integration tests -->
<dependency>
<groupId>com.parasoft</groupId>
<artifactId>parasoft-findings</artifactId>
<version>10.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>flexible-publish</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

import org.junit.jupiter.api.Test;

import com.parasoft.findings.jenkins.tool.ParasoftTool;

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.Report;

import org.jenkinsci.plugins.workflow.job.WorkflowJob;

import io.jenkins.plugins.analysis.core.model.AnalysisModelParser;
import io.jenkins.plugins.analysis.core.model.AnalysisResult;
import io.jenkins.plugins.analysis.core.model.ReportScanningTool;
import io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProvider;
import io.jenkins.plugins.analysis.core.model.Tool;
import io.jenkins.plugins.analysis.core.testutil.IntegrationTestWithJenkinsPerSuite;
Expand Down Expand Up @@ -69,6 +72,13 @@ class ParsersITest extends IntegrationTestWithJenkinsPerSuite {
+ "files&#61;&#34;$files $directory/$i&#34;\n"
+ "done</code></pre>";

/** Runs the Parasoft parser (part of the parasoft-findings plugin) on a file that contains 5 issues. */
@Test
void shouldReadParasoftWarnings() {
shouldFindIssuesOfTool(5, new ParasoftTool(), "parasoft.xml");
}

/** Runs the native parser on a file that contains 9 issues. */
@Test
void shouldFindAllRevapiIssues() {
shouldFindIssuesOfTool(7, new RevApi(), "revapi-result.json");
Expand Down Expand Up @@ -992,7 +1002,7 @@ void shouldFindAllCrossCoreEmbeddedStudioIssues() {
void shouldFindAllCodeGeneratorIssues() {
shouldFindIssuesOfTool(8, new CodeGenerator(), "CodeGenerator.log");
}

/** Runs the trivy parser on an output file that contains 4 issues. */
@Test
void shouldFindAllTrivyIssues() {
Expand Down Expand Up @@ -1029,7 +1039,7 @@ void shouldFindAllGrypeIssues() {
shouldFindIssuesOfTool(3, new Grype(), "grype-report.json");
}

private void shouldFindIssuesOfTool(final int expectedSizeOfIssues, final AnalysisModelParser tool,
private void shouldFindIssuesOfTool(final int expectedSizeOfIssues, final ReportScanningTool tool,
final String... fileNames) {
String defaultPipelineDefinition = "recordIssues tool: %s(pattern:'**/%s', reportEncoding:'UTF-8')";

Expand All @@ -1044,15 +1054,15 @@ private void shouldFindIssuesOfTool(final int expectedSizeOfIssues, final Analys
expectedSizeOfIssues, tool, fileNames);
}

private Report findIssuesWithoutAnsiColorPlugin(final int expectedSizeOfIssues, final AnalysisModelParser tool,
private Report findIssuesWithoutAnsiColorPlugin(final int expectedSizeOfIssues, final ReportScanningTool tool,
final String... fileNames) {
return findIssuesInPipeline(
"recordIssues tool: %s(pattern:'**/%s', reportEncoding:'UTF-8')", expectedSizeOfIssues, tool,
fileNames);
}

private Report findIssuesWithAnsiColorPlugin(final int expectedSizeOfIssues,
final AnalysisModelParser tool, final String... fileNames) {
final ReportScanningTool tool, final String... fileNames) {
String pipelineDefinition = "wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {\n"
+ " recordIssues tool: %s(pattern:'**/%s', reportEncoding:'UTF-8')\n"
+ "}";
Expand All @@ -1061,7 +1071,7 @@ private Report findIssuesWithAnsiColorPlugin(final int expectedSizeOfIssues,

@SuppressWarnings({"illegalcatch", "OverlyBroadCatchBlock", "PMD.LinguisticNaming"})
private Report findIssuesInPipeline(final String pipelineDefinition,
final int expectedSizeOfIssues, final AnalysisModelParser tool, final String... fileNames) {
final int expectedSizeOfIssues, final ReportScanningTool tool, final String... fileNames) {
try {
WorkflowJob job = createPipeline();
copyMultipleFilesToWorkspace(job, fileNames);
Expand Down
Loading

0 comments on commit a698285

Please sign in to comment.