hudson.model.HealthReport Java Examples

The following examples show how to use hudson.model.HealthReport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 6 votes vote down vote up
/**
 * Schedules a new build for the specified job and returns the created {@link HealthReport} after the build has been
 * finished.
 *
 * @param job
 *         the job to schedule
 * @param status
 *         the expected result for the build
 *
 * @return the created {@link HealthReport}
 */
@SuppressWarnings({"illegalcatch", "OverlyBroadCatchBlock"})
private HealthReport scheduleBuildToGetHealthReportAndAssertStatus(final FreeStyleProject job,
        final Result status) {
    try {
        FreeStyleBuild build = getJenkins().assertBuildStatus(status, job.scheduleBuild2(0));

        getAnalysisResult(build);

        ResultAction action = build.getAction(ResultAction.class);

        assertThat(action).isNotNull();

        return action.getBuildHealth();
    }
    catch (Exception e) {
        throw new AssertionError(e);
    }
}
 
Example #2
Source File: HealthReportBuilder.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Computes the healthiness of a build based on the specified results. Reports a health of 100% when the specified
 * counter is less than {@link HealthDescriptor#getHealthy()}. Reports a health of 0% when the specified counter is
 * greater than {@link HealthDescriptor#getUnhealthy()}. The computation takes only annotations of the specified
 * severity into account.
 *
 * @param healthDescriptor
 *         health report configuration
 * @param labelProvider
 *         label provider to get the messages from
 * @param sizePerSeverity
 *         number of issues per severity
 *
 * @return the healthiness of a build
 */
@CheckReturnValue
HealthReport computeHealth(final HealthDescriptor healthDescriptor,
        final StaticAnalysisLabelProvider labelProvider,
        final Map<Severity, Integer> sizePerSeverity) {
    int relevantIssuesSize = 0;
    for (Severity severity : Severity.collectSeveritiesFrom(healthDescriptor.getMinimumSeverity())) {
        relevantIssuesSize += sizePerSeverity.getOrDefault(severity, 0);
    }

    if (healthDescriptor.isValid()) {
        int percentage;
        int healthy = healthDescriptor.getHealthy();
        if (relevantIssuesSize < healthy) {
            percentage = 100;
        }
        else {
            int unhealthy = healthDescriptor.getUnhealthy();
            if (relevantIssuesSize > unhealthy) {
                percentage = 0;
            }
            else {
                percentage = 100 - ((relevantIssuesSize - healthy + 1) * 100 / (unhealthy - healthy + 2));
            }
        }

        return new HealthReport(percentage, labelProvider.getToolTipLocalizable(relevantIssuesSize));
    }
    return null;
}
 
Example #3
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
private HealthReport createHealthReport(final int healthyThreshold, final int unhealthyThreshold,
        final Severity priority, final int highSize, final int normalSize, final int lowSize,
        final int expectedRelevantIssuesCount) {
    HealthDescriptor healthDescriptor = new HealthDescriptor(healthyThreshold, unhealthyThreshold, priority);
    HealthReportBuilder builder = new HealthReportBuilder();

    Map<Severity, Integer> sizesPerSeverity = Maps.mutable.of(
            Severity.WARNING_HIGH, highSize, Severity.WARNING_NORMAL, normalSize, Severity.WARNING_LOW, lowSize);
    sizesPerSeverity.put(Severity.ERROR, 0);
    StaticAnalysisLabelProvider labelProvider = mock(StaticAnalysisLabelProvider.class);
    Localizable message = mock(Localizable.class);
    when(message.toString()).thenReturn(HEALTH_REPORT_MESSAGE);
    when(labelProvider.getToolTipLocalizable(expectedRelevantIssuesCount)).thenReturn(message);
    return builder.computeHealth(healthDescriptor, labelProvider, sizesPerSeverity);
}
 
Example #4
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Tests the correct description for multiple items.
 */
@Test
void shouldReturnDescriptionForMultipleItem() {
    HealthReport report = createValidHealthReport(4, 10, Severity.WARNING_HIGH, 
            10, 30, 60, 10);
    assertThat(report.getDescription()).isEqualTo(HEALTH_REPORT_MESSAGE);
}
 
Example #5
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Tests the correct description for a single item.
 */
@Test
void shouldReturnDescriptionForSingleItem() {
    HealthReport report = createValidHealthReport(4, 10, Severity.WARNING_HIGH, 
            1, 0, 0, 1);
    assertThat(report.getDescription()).isEqualTo(HEALTH_REPORT_MESSAGE);
}
 
Example #6
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Tests the correct description for no items.
 */
@Test
void shouldReturnDescriptionForNoItem() {
    HealthReport report = createValidHealthReport(4, 10, Severity.WARNING_HIGH, 
            0, 0, 0, 0);
    assertThat(report.getDescription()).isEqualTo(HEALTH_REPORT_MESSAGE);
}
 
Example #7
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Tests whether we evaluate correctly to a 0% health if unhealthy threshold fits the priority issue number.
 */
@Test
void shouldTestUnHealthBoundary() {
    HealthReport reportHighPriority = createValidHealthReport(4, 9, Severity.WARNING_HIGH, 10, 20, 30, 0);
    HealthReport reportNormalPriority = createValidHealthReport(15, 29, Severity.WARNING_NORMAL, 10, 20, 30, 0);
    HealthReport reportLowPriority = createValidHealthReport(15, 59, Severity.WARNING_LOW, 10, 20, 30, 0);

    assertThat(reportHighPriority.getScore()).isEqualTo(0);
    assertThat(reportNormalPriority.getScore()).isEqualTo(0);
    assertThat(reportLowPriority.getScore()).isEqualTo(0);
}
 
Example #8
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Tests whether we evaluate correctly to a 100% health if healthy threshold fits the priority issue number.
 */
@Test
void shouldTestHealthBoundary() {
    assertThat(create20PercentSteps(0, 4).getScore()).isEqualTo(100);
    assertThat(create20PercentSteps(1, 4).getScore()).isEqualTo(80);
    assertThat(create20PercentSteps(2, 4).getScore()).isEqualTo(60);
    assertThat(create20PercentSteps(3, 4).getScore()).isEqualTo(40);
    assertThat(create20PercentSteps(4, 4).getScore()).isEqualTo(20);
    assertThat(create20PercentSteps(5, 4).getScore()).isEqualTo(0);

    assertThat(create20PercentSteps(0, 9).getScore()).isEqualTo(100);
    assertThat(create20PercentSteps(1, 9).getScore()).isEqualTo(90);
    assertThat(create20PercentSteps(2, 9).getScore()).isEqualTo(80);
    assertThat(create20PercentSteps(3, 9).getScore()).isEqualTo(70);
    assertThat(create20PercentSteps(4, 9).getScore()).isEqualTo(60);
    assertThat(create20PercentSteps(5, 9).getScore()).isEqualTo(50);
    assertThat(create20PercentSteps(6, 9).getScore()).isEqualTo(40);
    assertThat(create20PercentSteps(7, 9).getScore()).isEqualTo(30);
    assertThat(create20PercentSteps(8, 9).getScore()).isEqualTo(20);
    assertThat(create20PercentSteps(9, 9).getScore()).isEqualTo(10);
    assertThat(create20PercentSteps(10, 9).getScore()).isEqualTo(0);

    HealthReport reportHighPriority = createValidHealthReport(11, 15, Severity.WARNING_HIGH, 10, 20, 30, 0);
    HealthReport reportNormalPriority = createValidHealthReport(31, 35, Severity.WARNING_NORMAL, 10, 20, 30, 0);
    HealthReport reportLowPriority = createValidHealthReport(61, 65, Severity.WARNING_LOW, 10, 20, 30, 0);

    assertThat(reportHighPriority.getScore()).isEqualTo(100);
    assertThat(reportNormalPriority.getScore()).isEqualTo(100);
    assertThat(reportLowPriority.getScore()).isEqualTo(100);
}
 
Example #9
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Test whether the health descriptor is disabled.
 */
@Test
void shouldBeNullForInvalidHealthDescriptor() {
    HealthReport sameBoundaries = createHealthReport(15, 15, Severity.WARNING_NORMAL, 10, 20, 30, 0);
    assertThat(sameBoundaries).isNull();

    HealthReport wrongBoundaryOrder = createHealthReport(15, 15, Severity.WARNING_NORMAL, 10, 20, 30, 0);
    assertThat(wrongBoundaryOrder).isNull();
}
 
Example #10
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Test whether the health descriptor is disabled.
 */
@Test
void shouldBeNullForDisabledHealthDescriptor() {
    HealthReport report = createHealthReport(0, 0, Severity.WARNING_NORMAL, 10, 20, 30, 0);

    assertThat(report).isNull();
}
 
Example #11
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Test whether we evaluate correctly to 0% health.
 */
@Test
void shouldTest0Health() {
    HealthReport reportHighPriority = createValidHealthReport(4, 6, Severity.WARNING_HIGH, 10, 20, 30, 0);
    HealthReport reportNormalPriority = createValidHealthReport(15, 25, Severity.WARNING_NORMAL, 10, 20, 30, 0);
    HealthReport reportLowPriority = createValidHealthReport(15, 45, Severity.WARNING_LOW, 10, 20, 30, 0);

    assertThat(reportHighPriority.getScore()).isEqualTo(0);
    assertThat(reportNormalPriority.getScore()).isEqualTo(0);
    assertThat(reportLowPriority.getScore()).isEqualTo(0);
}
 
Example #12
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Tests whether we evaluate correctly to 100% health.
 */
@Test
void shouldTest100Health() {
    HealthReport reportHighPriority = createValidHealthReport(20, 22, Severity.WARNING_HIGH, 10, 20, 30, 0);
    HealthReport reportNormalPriority = createValidHealthReport(40, 45, Severity.WARNING_NORMAL, 10, 20, 30, 0);
    HealthReport reportLowPriority = createValidHealthReport(65, 105, Severity.WARNING_LOW, 10, 20, 30, 0);

    assertThat(reportHighPriority.getScore()).isEqualTo(100);
    assertThat(reportNormalPriority.getScore()).isEqualTo(100);
    assertThat(reportLowPriority.getScore()).isEqualTo(100);
}
 
Example #13
Source File: HealthReportBuilderTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Tests whether we evaluate correctly to a 50% health.
 */
@Test
void shouldTest50Health() {
    HealthReport reportHighPriority = createValidHealthReport(4, 16, Severity.WARNING_HIGH, 10, 20, 30, 0);
    HealthReport reportNormalPriority = createValidHealthReport(15, 45, Severity.WARNING_NORMAL, 10, 20, 30, 0);
    HealthReport reportLowPriority = createValidHealthReport(15, 105, Severity.WARNING_LOW, 10, 20, 30, 0);

    assertThat(reportHighPriority.getScore()).isEqualTo(50);
    assertThat(reportNormalPriority.getScore()).isEqualTo(50);
    assertThat(reportLowPriority.getScore()).isEqualTo(50);
}
 
Example #14
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a {@link HealthReport} under test with checkstyle workspace file.
 *
 * @param minimumSeverity
 *         the minimum severity to select
 *
 * @return a healthReport under test
 */
private HealthReport createHealthReportTestSetupCheckstyle(final Severity minimumSeverity) {
    FreeStyleProject project = createFreeStyleProjectWithWorkspaceFiles("checkstyle-healthReport.xml");
    enableGenericWarnings(project, publisher -> {
                publisher.setHealthy(10);
                publisher.setUnhealthy(15);
                publisher.setMinimumSeverity(minimumSeverity.getName());
            },
            createTool(new CheckStyle(), "**/*issues.txt")
    );
    return scheduleBuildToGetHealthReportAndAssertStatus(project, Result.SUCCESS);
}
 
Example #15
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Should create a health report for low priority issues. Error, warnings and info issues.
 */
@Test
public void shouldCreateHealthReportWithLowPriority() {
    HealthReport report = createHealthReportTestSetupCheckstyle(Severity.WARNING_LOW);
    assertThat(report.getDescription()).isEqualTo("CheckStyle: 6 warnings");
    assertThat(report.getIconClassName()).isEqualTo(H80PLUS);
}
 
Example #16
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Should create a health report for normal priority issues. Error and warning issues.
 */
@Test
public void shouldCreateHealthReportWithNormalPriority() {
    HealthReport report = createHealthReportTestSetupCheckstyle(Severity.WARNING_NORMAL);
    assertThat(report.getDescription()).isEqualTo("CheckStyle: 4 warnings");
    assertThat(report.getIconClassName()).isEqualTo(H80PLUS);
}
 
Example #17
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Should create a health report for only high priority issues. Only error issues
 */
@Test
public void shouldCreateHealthReportWithHighPriority() {
    HealthReport report = createHealthReportTestSetupCheckstyle(Severity.WARNING_HIGH);
    assertThat(report.getDescription()).isEqualTo("CheckStyle: 2 warnings");
    assertThat(report.getIconClassName()).isEqualTo(H80PLUS);
}
 
Example #18
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Should create a health report with icon health-00to19 (rainy).
 */
@Test
public void shouldCreate00To19HealthReport() {
    HealthReport report = createHealthReportTestSetupEclipse(1, 5);
    assertThat(report.getDescription()).isEqualTo("Eclipse ECJ: 8 warnings");
    assertThat(report.getIconClassName()).isEqualTo(H00TO19);
}
 
Example #19
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Should create a health report with icon health-20to39 (rainy).
 */
@Test
public void shouldCreate20To39HealthReport() {
    HealthReport report = createHealthReportTestSetupEclipse(4, 10);
    assertThat(report.getDescription()).isEqualTo("Eclipse ECJ: 8 warnings");
    assertThat(report.getIconClassName()).isEqualTo(H20TO39);
}
 
Example #20
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Should create a health report with icon health-40to59 (cloudy).
 */
@Test
public void shouldCreate40To59HealthReport() {
    HealthReport report = createHealthReportTestSetupEclipse(1, 15);
    assertThat(report.getDescription()).isEqualTo("Eclipse ECJ: 8 warnings");
    assertThat(report.getIconClassName()).isEqualTo(H40TO59);
}
 
Example #21
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Should create a health report with icon health-60to79 (cloudy sun).
 */
@Test
public void shouldCreate60To79HealthReport() {
    HealthReport report = createHealthReportTestSetupEclipse(5, 15);
    assertThat(report.getDescription()).isEqualTo("Eclipse ECJ: 8 warnings");
    assertThat(report.getIconClassName()).isEqualTo(H60TO79);
}
 
Example #22
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Should create a health report with icon health-80plus (sun).
 */
@Test
public void shouldCreate80plusHealthReport() {
    HealthReport report = createHealthReportTestSetupEclipse(10, 15);
    assertThat(report.getDescription()).isEqualTo("Eclipse ECJ: 8 warnings");
    assertThat(report.getIconClassName()).isEqualTo(H80PLUS);
}
 
Example #23
Source File: HealthReportITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a {@link HealthReport} under test with eclipse workspace file.
 *
 * @param health
 *         health threshold
 * @param unhealthy
 *         unhealthy threshold
 *
 * @return a healthReport under test
 */
private HealthReport createHealthReportTestSetupEclipse(final int health, final int unhealthy) {
    FreeStyleProject project = createFreeStyleProjectWithWorkspaceFiles("eclipse-healthReport.txt");
    enableGenericWarnings(project, publisher -> {
                publisher.setHealthy(health);
                publisher.setUnhealthy(unhealthy);
            },
            configurePattern(new Eclipse())
    );
    return scheduleBuildToGetHealthReportAndAssertStatus(project, Result.SUCCESS);
}
 
Example #24
Source File: JobDslITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a freestyle job from a YAML file and verifies that issue recorder finds warnings.
 */
@Test
public void shouldCreateFreestyleJobUsingJobDslAndVerifyIssueRecorderWithDefaultConfiguration() {
    configureJenkins("job-dsl-warnings-ng-default.yaml");

    TopLevelItem project = getJenkins().jenkins.getItem("dsl-freestyle-job");

    assertThat(project).isNotNull();
    assertThat(project).isInstanceOf(FreeStyleProject.class);

    DescribableList<Publisher, Descriptor<Publisher>> publishers = ((FreeStyleProject) project).getPublishersList();
    assertThat(publishers).hasSize(1);

    Publisher publisher = publishers.get(0);
    assertThat(publisher).isInstanceOf(IssuesRecorder.class);

    HealthReport healthReport = ((FreeStyleProject) project).getBuildHealth();
    assertThat(healthReport.getScore()).isEqualTo(100);

    IssuesRecorder recorder = (IssuesRecorder) publisher;

    assertThat(recorder.getAggregatingResults()).isFalse();
    assertThat(recorder.getTrendChartType()).isEqualTo(TrendChartType.AGGREGATION_TOOLS);
    assertThat(recorder.getBlameDisabled()).isFalse();
    assertThat(recorder.getForensicsDisabled()).isFalse();
    assertThat(recorder.getEnabledForFailure()).isFalse();
    assertThat(recorder.getHealthy()).isEqualTo(0);
    assertThat(recorder.getId()).isNull();
    assertThat(recorder.getIgnoreFailedBuilds()).isTrue();
    assertThat(recorder.getIgnoreQualityGate()).isFalse();
    assertThat(recorder.getMinimumSeverity()).isEqualTo("LOW");
    assertThat(recorder.getName()).isNull();
    assertThat(recorder.getQualityGates()).hasSize(0);
    assertThat(recorder.getSourceCodeEncoding()).isEmpty();
    assertThat(recorder.getUnhealthy()).isEqualTo(0);

    List<Tool> tools = recorder.getTools();
    assertThat(tools).hasSize(2);
    assertThat(tools.get(0)).isInstanceOf(Java.class);
}
 
Example #25
Source File: DbBackedProject.java    From DotCi with MIT License 4 votes vote down vote up
@Override
@Exported(name = "healthReport")
public List<HealthReport> getBuildHealthReports() {
    return new ArrayList<>();
}
 
Example #26
Source File: DbBackedProject.java    From DotCi with MIT License 4 votes vote down vote up
@Override
public HealthReport getBuildHealth() {
    return new HealthReport();
}
 
Example #27
Source File: JUnitFlakyTestDataAction.java    From flaky-test-handler-plugin with Apache License 2.0 4 votes vote down vote up
public static String getSmallImagePath(int score) {
  HealthReport healthReport = new HealthReport(score, (Localizable)null);
  return healthReport.getIconUrl("16x16");
}
 
Example #28
Source File: JUnitFlakyTestDataAction.java    From flaky-test-handler-plugin with Apache License 2.0 4 votes vote down vote up
public static String getBigImagePath(int score) {
  HealthReport healthReport = new HealthReport(score, (Localizable)null);
  return healthReport.getIconUrl("32x32");
}
 
Example #29
Source File: ResultAction.java    From warnings-ng-plugin with MIT License 4 votes vote down vote up
@Override
@Nullable
public HealthReport getBuildHealth() {
    return new HealthReportBuilder().computeHealth(healthDescriptor, getLabelProvider(),
            getResult().getSizePerSeverity());
}
 
Example #30
Source File: JobDslITest.java    From warnings-ng-plugin with MIT License 4 votes vote down vote up
/**
 * Creates a freestyle job from a YAML file and verifies that all fields in issue recorder are set correct.
 */
@Test
public void shouldCreateFreestyleJobUsingJobDslAndVerifyIssueRecorderWithValuesSet() {
    configureJenkins("job-dsl-warnings-ng.yaml");

    TopLevelItem project = getJenkins().jenkins.getItem("dsl-freestyle-job");

    assertThat(project).isNotNull();
    assertThat(project).isInstanceOf(FreeStyleProject.class);

    DescribableList<Publisher, Descriptor<Publisher>> publishers = ((FreeStyleProject) project).getPublishersList();
    assertThat(publishers).hasSize(1);

    Publisher publisher = publishers.get(0);
    assertThat(publisher).isInstanceOf(IssuesRecorder.class);

    HealthReport healthReport = ((FreeStyleProject) project).getBuildHealth();
    assertThat(healthReport.getScore()).isEqualTo(100);

    IssuesRecorder recorder = (IssuesRecorder) publisher;

    assertThat(recorder.getAggregatingResults()).isTrue();
    assertThat(recorder.getTrendChartType()).isEqualTo(TrendChartType.NONE);
    assertThat(recorder.getBlameDisabled()).isTrue();
    assertThat(recorder.getForensicsDisabled()).isTrue();
    assertThat(recorder.getEnabledForFailure()).isTrue();
    assertThat(recorder.getHealthy()).isEqualTo(10);
    assertThat(recorder.getId()).isEqualTo("test-id");
    assertThat(recorder.getIgnoreFailedBuilds()).isFalse();
    assertThat(recorder.getIgnoreQualityGate()).isTrue();
    assertThat(recorder.getMinimumSeverity()).isEqualTo("ERROR");
    assertThat(recorder.getName()).isEqualTo("test-name");
    assertThat(recorder.getSourceCodeEncoding()).isEqualTo("UTF-8");
    assertThat(recorder.getUnhealthy()).isEqualTo(50);
    assertThat(recorder.getReferenceJobName()).isEqualTo("test-job");
    assertThat(recorder.getQualityGates()).hasSize(1);

    List<Tool> tools = recorder.getTools();
    assertThat(tools).hasSize(2);
    assertThat(tools.get(0)).isInstanceOf(Java.class);

}