Skip to content

Commit

Permalink
Refactoring of pipeline test: use same verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Sep 27, 2019
1 parent 7b3b691 commit 95caa00
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/test/java/plugins/WarningsNextGenerationPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ public class WarningsNextGenerationPluginTest extends AbstractJUnitTest {
private DockerContainerHolder<JavaGitContainer> dockerContainer;

/**
* Runs a pipeline with checkstyle and pmd. Verifies the expansion of tokens with the token-macro plugin.
* Runs a pipeline with all tools two times. Verifies the analysis results in several views. Additionally,
* verifies the expansion of tokens with the token-macro plugin.
*/
@Test
@WithPlugins({"token-macro", "workflow-cps", "pipeline-stage-step", "workflow-durable-task-step", "workflow-basic-steps"})
public void should_expand_token() {
public void should_record_issues_in_pipeline_and_expand_tokens() {
WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
job.sandbox.check();

Expand All @@ -122,20 +123,29 @@ public void should_expand_token() {
Build referenceBuild = buildJob(job);

assertThat(referenceBuild.getConsole()).contains("[total=4]");
assertThat(referenceBuild.getConsole()).contains("[new=0]");
assertThat(referenceBuild.getConsole()).contains("[fixed=0]");
assertThat(referenceBuild.getConsole()).contains("[checkstyle=1]");
assertThat(referenceBuild.getConsole()).contains("[pmd=3]");

job.configure(() -> createRecordIssuesStep(job, 2));

Build build = buildJob(job);

assertThat(build.getConsole()).contains("[total=5]");
assertThat(build.getConsole()).contains("[total=25]");
assertThat(build.getConsole()).contains("[new=23]");
assertThat(build.getConsole()).contains("[fixed=2]");
assertThat(build.getConsole()).contains("[checkstyle=3]");
assertThat(build.getConsole()).contains("[pmd=2]");

verifyPmd(build);
verifyFindBugs(build);
verifyCheckStyle(build);
verifyCpd(build);
}

private void createRecordIssuesStep(final WorkflowJob job, final int build) {
String[] fileNames = {"checkstyle-result.xml", "pmd.xml", "findbugsXml.xml", "cpd.xml"};
String[] fileNames = {"checkstyle-result.xml", "pmd.xml", "findbugsXml.xml", "cpd.xml", "Main.java"};
StringBuilder resourceCopySteps = new StringBuilder();
for (String fileName : fileNames) {
resourceCopySteps.append(job.copyResourceStep(WARNINGS_PLUGIN_PREFIX
Expand All @@ -145,12 +155,17 @@ private void createRecordIssuesStep(final WorkflowJob job, final int build) {
+ resourceCopySteps.toString()
+ "recordIssues tool: checkStyle(pattern: '**/checkstyle*')\n"
+ "recordIssues tool: pmdParser(pattern: '**/pmd*')\n"
+ "recordIssues tools: [cpd(pattern: '**/cpd*', highThreshold:8, normalThreshold:3), findBugs()], aggregatingResults: 'false' \n"
+ "def total = tm('${ANALYSIS_ISSUES_COUNT}')\n"
+ "echo '[total=' + total + ']' \n"
+ "def checkstyle = tm('${ANALYSIS_ISSUES_COUNT, tool=\"checkstyle\"}')\n"
+ "echo '[checkstyle=' + checkstyle + ']' \n"
+ "def pmd = tm('${ANALYSIS_ISSUES_COUNT, tool=\"pmd\"}')\n"
+ "echo '[pmd=' + pmd + ']' \n"
+ "def newSize = tm('${ANALYSIS_ISSUES_COUNT, type=\"NEW\"}')\n"
+ "echo '[new=' + newSize + ']' \n"
+ "def fixedSize = tm('${ANALYSIS_ISSUES_COUNT, type=\"FIXED\"}')\n"
+ "echo '[fixed=' + fixedSize + ']' \n"
+ "}");
}

Expand All @@ -161,7 +176,7 @@ private void createRecordIssuesStep(final WorkflowJob job, final int build) {
@Test
public void should_show_build_summary_and_link_to_details() {
FreeStyleJob job = createFreeStyleJob("build_status_test/build_01");
addRecorderWith3Tools(job);
addRecorder(job);
job.save();

buildJob(job);
Expand Down Expand Up @@ -329,7 +344,7 @@ private InfoView openInfoView(final Build build, final String toolId) {
@Test
public void should_aggregate_tools_into_single_result() {
FreeStyleJob job = createFreeStyleJob("build_status_test/build_01");
IssuesRecorder recorder = addRecorderWith3Tools(job);
IssuesRecorder recorder = addRecorder(job);
recorder.setEnabledForAggregation(true);
recorder.addQualityGateConfiguration(4, QualityGateType.TOTAL, QualityGateBuildResult.UNSTABLE);
recorder.addQualityGateConfiguration(3, QualityGateType.NEW, QualityGateBuildResult.FAILED);
Expand Down Expand Up @@ -403,7 +418,7 @@ private void reconfigureJobWithResource(final FreeStyleJob job, final String fil
job.configure(() -> job.copyResource(WARNINGS_PLUGIN_PREFIX + fileName));
}

private IssuesRecorder addRecorderWith3Tools(final FreeStyleJob job) {
private IssuesRecorder addRecorder(final FreeStyleJob job) {
return job.addPublisher(IssuesRecorder.class, recorder -> {
recorder.setTool("CheckStyle");
recorder.addTool("FindBugs");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class Main{
public static voic main(final String args...){
functionOne();
functionTwo();
functionThree();
}

public static void functionOne()
{
System.out.println("testfile for redundancy");
for(int i = 0; i < 10; i++)
{
System.out.println(i);
}
}

public static void functionTwo()
{
System.out.println("testfile for redundancy");
for(int i = 0; i < 10; i++)
{
System.out.println(i);
}
}

public static void functionThree()
{
System.out.println("testfile for redundancy");
for(int i = 0; i < 10; i++)
{
System.out.println(i);
}
}

}

0 comments on commit 95caa00

Please sign in to comment.