Search in sources :

Example 1 with TaskScannerAction

use of org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction in project acceptance-test-harness by jenkinsci.

the class TaskScannerPluginTest method should_report_closed_tasks.

/**
 * Verifies the detection of closed tasks. Therefore two runs of the same job with the same task scanner setup are
 * conducted but the fileset in the workspace will be replaced by the same files containing less warnings for the
 * second run. The tasks that have been removed shall be correctly listed as closed tasks.
 */
@Test
public void should_report_closed_tasks() throws Exception {
    FreeStyleJob job = createFreeStyleJob(settings -> {
        settings.setPattern("**/*.java");
        settings.setExcludePattern("**/*Test.java");
        settings.setHighPriorityTags("FIXME");
        settings.setNormalPriorityTags("TODO");
        settings.setLowPriorityTags("@Deprecated");
        settings.setIgnoreCase(false);
    });
    buildSuccessfulJob(job);
    // this time we do not check the task scanner output as the result is the same
    // as for single_task_tags_and_exclusion_pattern
    // So we proceed directly with the preparation of build #2
    editJob("/tasks_plugin/fileset1_less", false, job, TasksFreestyleSettings.class);
    Build build = buildSuccessfulJob(job);
    build.open();
    TaskScannerAction action = new TaskScannerAction(build);
    // In the first build the task priorities were
    // - 1x high
    // - 4x medium
    // - 1x low
    // 
    // For the second build (reduced warnings) the expected priorities are
    // - 3x medium
    // 
    // --> we expect 3 closed tasks (1x high, 1x normal, 1x low)
    assertThatOpenTaskCountLinkIs(action, 3, 7);
    assertThatClosedTaskCountLinkIs(action, 3);
    action.open();
    assertThat(action.getNumberOfWarnings(), is(3));
    assertThat(action.getNumberOfFixedWarnings(), is(3));
    assertThat(action.getNumberOfWarningsWithHighPriority(), is(0));
    assertThat(action.getNumberOfWarningsWithNormalPriority(), is(3));
    assertThat(action.getNumberOfWarningsWithLowPriority(), is(0));
    assertFixedTab(action);
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) TaskScannerAction(org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction) Test(org.junit.Test)

Example 2 with TaskScannerAction

use of org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction in project acceptance-test-harness by jenkinsci.

the class TaskScannerPluginTest method verifyRegularExpressionScannerResult.

private void verifyRegularExpressionScannerResult(final Job job) {
    Build build = buildSuccessfulJob(job);
    build.open();
    TaskScannerAction action = new TaskScannerAction(build);
    assertThatOpenTaskCountLinkIs(action, 5, 1);
    action.open();
    assertThat(action.getNumberOfWarnings(), is(5));
    assertThat(action.getNumberOfWarningsWithNormalPriority(), is(5));
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) TaskScannerAction(org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction)

Example 3 with TaskScannerAction

use of org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction in project acceptance-test-harness by jenkinsci.

the class TaskScannerPluginTest method should_find_tasks_in_maven_project.

/**
 * Verifies several task scanner functions for a maven project such as - treatment of exclusion pattern - correct
 * counting of warnings - correct prioritisation of warnings - changing build status based on thresholds.
 */
@Test
public void should_find_tasks_in_maven_project() throws Exception {
    MavenModuleSet job = createMavenJob("/tasks_plugin/sample_tasks_project", "clean package test", settings -> {
        settings.setPattern("**/*.java");
        settings.setExcludePattern("**/*Test.java");
        settings.setHighPriorityTags("FIXME");
        settings.setNormalPriorityTags("TODO");
        settings.setLowPriorityTags("@Deprecated");
        settings.setIgnoreCase(false);
    });
    // as one of the unit tests fail, the build should be unstable
    Build build = buildUnstableJob(job);
    assertThatTasksResultExists(job, build);
    build.open();
    TaskScannerAction action = new TaskScannerAction(build);
    // The expected task priorities are:
    // - 1x high
    // - 1x medium
    // - 1x low
    assertThatOpenTaskCountLinkIs(action, 3, 1);
    action.open();
    assertThat(action.getNumberOfWarnings(), is(3));
    assertThat(action.getNumberOfWarningsWithHighPriority(), is(1));
    assertThat(action.getNumberOfWarningsWithNormalPriority(), is(1));
    assertThat(action.getNumberOfWarningsWithLowPriority(), is(1));
    // re-configure the job and set a threshold to mark the build as failed
    editJob(false, job, TasksMavenSettings.class, settings -> {
        settings.setBuildFailedTotalHigh("0");
        settings.setBuildFailedTotalNormal("5");
        settings.setBuildFailedTotalLow("10");
    });
    // as the threshold for high priority warnings is exceeded, the build should be marked as failed
    build = buildFailingJob(job);
    assertThatTasksResultExists(job, build);
    build.open();
    // check build result text
    assertThat(action.getPluginResult(build), is("Plug-in Result: FAILED - 1 warning of priority High exceeds the threshold of 0 by 1 (Reference build: #1)"));
    action.open();
    // no change in warning counts expected
    assertThat(action.getNumberOfWarningsWithHighPriority(), is(1));
    assertThat(action.getNumberOfWarningsWithNormalPriority(), is(1));
    assertThat(action.getNumberOfWarningsWithLowPriority(), is(1));
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) TaskScannerAction(org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction) MavenModuleSet(org.jenkinsci.test.acceptance.plugins.maven.MavenModuleSet) Test(org.junit.Test)

Example 4 with TaskScannerAction

use of org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction in project acceptance-test-harness by jenkinsci.

the class TaskScannerPluginTest method should_set_build_result_based_on_status_thresholds.

/**
 * Verifies the correct treatment of the status thresholds (totals). Therefore a more complex test case has been
 * created which modifies files and task tags to scan for multiple times to create appropriate scenarios for
 * different thresholds.
 * <p/>
 * It shall also check whether the determination / justification of the build status is done based on the highest
 * priority threshold that has been exceeded.
 * <p/>
 * The test case consists of 6 steps: 1 - create reference build (SUCCESS) -> no threshold exceeded 2 - exceed the
 * UNSTABLE LOW threshold 3 - exceed the UNSTABLE NORMAL threshold but do not exceed UNSTABLE LOW 4 - exceed
 * UNSTABLE LOW, NORMAL and HIGH -> build status justified with HIGH priority tasks 5 - further exceed the UNSTABLE
 * TOTAL threshold -> new justification for build status 6 - further exceed the FAILURE TOTAL threshold -> build
 * failed 7 - remove most of the task tags -> build is stable again
 */
@Test
public void should_set_build_result_based_on_status_thresholds() {
    FreeStyleJob job = createFreeStyleJob("/tasks_plugin/fileset1_less", settings -> {
        settings.setPattern("**/*.java");
        settings.setExcludePattern("**/*Test.java");
        // no high prio tags
        settings.setHighPriorityTags("");
        settings.setNormalPriorityTags("TODO");
        settings.setLowPriorityTags("@Deprecated");
        settings.setIgnoreCase(false);
        // setup thresholds
        settings.setBuildUnstableTotalLow("1");
        settings.setBuildUnstableTotalNormal("4");
        settings.setBuildUnstableTotalHigh("0");
        settings.setBuildUnstableTotalAll("10");
        settings.setBuildFailedTotalAll("15");
    });
    TaskScannerAction action = new TaskScannerAction(job.getLastBuild());
    // In order to increase readability each step has been placed in a separate
    // private function
    job = status_thresholds_step1(job, action);
    job = status_thresholds_step2(job, action);
    job = status_thresholds_step3(job, action);
    job = status_thresholds_step4(job, action);
    job = status_thresholds_step5(job, action);
    job = status_thresholds_step6(job, action);
    status_thresholds_step7(job, action);
}
Also used : FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) TaskScannerAction(org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction) Test(org.junit.Test)

Example 5 with TaskScannerAction

use of org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction in project acceptance-test-harness by jenkinsci.

the class TaskScannerPluginTest method should_use_file_encoding_windows1251_when_parsing_files.

/**
 * Check the correct treatment and display of tasks in files with windows-1251 (a.k.a. cp1251) encoding. Reproduces
 * the observations described in JENKINS-22744.
 */
// Note: In order to run this test in IntelliJ the encoding of the source needs to be set to windows-1251
@Test
@Issue("JENKINS-22744")
public void should_use_file_encoding_windows1251_when_parsing_files() throws Exception {
    FreeStyleJob job = createFreeStyleJob("/tasks_plugin/cp1251_files", settings -> {
        settings.setPattern("**/*.java");
        settings.setExcludePattern("**/*Test.java");
        settings.setHighPriorityTags("FIXME");
        settings.setNormalPriorityTags("TODO");
        settings.setIgnoreCase(true);
        settings.setDefaultEncoding("windows-1251");
    });
    Build build = buildSuccessfulJob(job);
    assertThatTasksResultExists(job, build);
    build.open();
    TaskScannerAction action = new TaskScannerAction(build);
    assertThatOpenTaskCountLinkIs(action, 2, 1);
    action.open();
    assertThat(action.getNumberOfWarnings(), is(2));
    assertThat(action.getNumberOfWarningsWithHighPriority(), is(1));
    assertThat(action.getNumberOfWarningsWithNormalPriority(), is(1));
    assertWarningExtraction(action, "TestTaskScanner.java", 5, "TODO", "пример комментария на русском");
    verifySourceLine(action, "TestTaskScanner.java", 4, "4   //FIXME тестирование Jenkins", "High Priority");
    verifySourceLine(action, "TestTaskScanner.java", 5, "5   //TODO пример комментария на русском", "Normal Priority");
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) TaskScannerAction(org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

TaskScannerAction (org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerAction)8 Build (org.jenkinsci.test.acceptance.po.Build)7 Test (org.junit.Test)7 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)6 MavenModuleSet (org.jenkinsci.test.acceptance.plugins.maven.MavenModuleSet)1 Issue (org.jvnet.hudson.test.Issue)1