Skip to content
Permalink
Browse files

[JENKINS-28360] Added a test case to verify the health reports.

  • Loading branch information...
uhafner committed Sep 9, 2015
1 parent b769c10 commit b9c687643cc774c6e82de20662fff9b0236c2d82
@@ -1,6 +1,7 @@
package org.jenkinsci.test.acceptance.plugins.analysis_collector;

import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisAction;
import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisSettings;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.Job;

@@ -20,6 +21,16 @@ public AnalysisCollectorAction(final Job parent) {
super(parent, PLUGIN);
}

@Override
public String getName() {
return "Analysis";
}

@Override
public Class<? extends AnalysisSettings> getFreeStyleSettings() {
return AnalysisCollectorSettings.class;
}

@Override
public AnalysisGraphConfigurationView configureTrendGraphForUser() {
return new AnalysisGraphConfigurationView(getParent());
@@ -8,7 +8,7 @@
* @author Michael Prankl
*/
@Describable("Publish combined analysis results")
public class AnalysisCollectorFreestyleBuildSettings extends AnalysisFreestyleSettings {
public class AnalysisCollectorSettings extends AnalysisFreestyleSettings {

private AnalysisCollectorPluginArea pluginArea;

@@ -18,7 +18,7 @@
* @param parent the job currently being configured.
* @param selectorPath the selector path used as prefix.
*/
public AnalysisCollectorFreestyleBuildSettings(Job parent, String selectorPath) {
public AnalysisCollectorSettings(Job parent, String selectorPath) {
super(parent, selectorPath);
this.pluginArea = new AnalysisCollectorPluginArea(parent, selectorPath);
}
@@ -60,6 +60,20 @@ private AnalysisAction(final String url, final String pluginUrl, final Container
plugin = url;
}

/**
* Returns the human readable name of the plug-in under test.
*
* @return the plug-in name
*/
public abstract String getName();

/**
* Returns the class of the page object of the analysis settings used to configure the plug-in.
*
* @return the class of the freestyle publisher page object
*/
public abstract Class<? extends AnalysisSettings> getFreeStyleSettings();

/**
* Returns the URL of this action.
*
@@ -54,16 +54,20 @@ public AnalysisSettings(Job parent, String selectorPath) {

/**
* Sets the threshold in percent after which a build is marked as stable.
*
* @param threshold number of warnings threshold to get a healthy build
*/
public void setBuildHealthyThreshold(String threshold) {
public void setBuildHealthyThreshold(final int threshold) {
ensureAdvancedClicked();
buildHealthyThreshold.set(threshold);
}

/**
* Sets the threshold in percent after which a build is marked as stable.
*
* @param threshold number of warnings threshold to get an unhealthy build
*/
public void setBuildUnhealthyThreshold(String threshold) {
public void setBuildUnhealthyThreshold(final int threshold) {
ensureAdvancedClicked();
buildUnhealthyThreshold.set(threshold);
}
@@ -1,6 +1,7 @@
package org.jenkinsci.test.acceptance.plugins.checkstyle;

import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisAction;
import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisSettings;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.Job;

@@ -19,4 +20,14 @@ public CheckStyleAction(final Build parent) {
public CheckStyleAction(final Job parent) {
super(parent, PLUGIN);
}

@Override
public String getName() {
return "Checkstyle";
}

@Override
public Class<? extends AnalysisSettings> getFreeStyleSettings() {
return CheckStyleFreestyleSettings.class;
}
}
@@ -1,6 +1,7 @@
package org.jenkinsci.test.acceptance.plugins.findbugs;

import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisAction;
import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisSettings;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.Job;

@@ -19,4 +20,14 @@ public FindBugsAction(final Build parent) {
public FindBugsAction(final Job parent) {
super(parent, PLUGIN);
}

@Override
public String getName() {
return "FindBugs";
}

@Override
public Class<? extends AnalysisSettings> getFreeStyleSettings() {
return FindBugsFreestyleSettings.class;
}
}
@@ -1,6 +1,7 @@
package org.jenkinsci.test.acceptance.plugins.pmd;

import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisAction;
import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisSettings;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.Job;

@@ -19,4 +20,14 @@ public PmdAction(final Build parent) {
public PmdAction(final Job parent) {
super(parent, PLUGIN);
}

@Override
public String getName() {
return "PMD";
}

@Override
public Class<? extends AnalysisSettings> getFreeStyleSettings() {
return PmdFreestyleSettings.class;
}
}
@@ -5,6 +5,7 @@

import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisAction;
import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisSettings;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.Job;
import org.openqa.selenium.WebElement;
@@ -25,6 +26,16 @@ public TaskScannerAction(final Job parent) {
super(parent, PLUGIN);
}

@Override
public String getName() {
return "Task Scanner";
}

@Override
public Class<? extends AnalysisSettings> getFreeStyleSettings() {
return TasksFreestyleSettings.class;
}

/**
* Getter for the full result text surrounding the link text, split at the newline character.
*
@@ -1,6 +1,7 @@
package org.jenkinsci.test.acceptance.plugins.warnings;

import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisAction;
import org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisSettings;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.Job;

@@ -20,6 +21,16 @@ public WarningsAction(final Job parent) {
super(parent, PLUGIN);
}

@Override
public String getName() {
return "Java Compiler (javac)"; // TODO: check if this needs to be adaptable
}

@Override
public Class<? extends AnalysisSettings> getFreeStyleSettings() {
return WarningsBuildSettings.class;
}

@Override
public String getUrl() {
return super.getUrl().replace(PLUGIN, PLUGIN + ".*");
@@ -56,9 +56,12 @@
import static org.jenkinsci.test.acceptance.Matchers.*;

/**
* Base class for tests of the static analysis plug-ins.
* Base class for tests of the static analysis plug-ins. Contains several generic test cases that run for all
* participating plug-ins. Additionally, serveral helper methods are available for the concrete test cases of a
* plug-in.
*
* @param <P> the type of the project action
*
* @author Martin Ende
* @author Martin Kurz
* @author Fabian Trampusch
@@ -67,6 +70,56 @@
public abstract class AbstractAnalysisTest<P extends AnalysisAction> extends AbstractJUnitTest {
private static final List<String> PRIORITIES = Arrays.asList("HIGH", "LOW", "NORMAL");

/**
* Builds a freestyle job with an enabled publisher of the plug-in under test. Sets the thresholds for the trend
* report so that a health of 0-19% is evaluated for the plug-in under test (shown as tool tip in the Jenkins
* main view).
* TODO: Add different health percentages
*/
@Test @Issue("JENKINS-28360")
public void should_show_build_health() {
FreeStyleJob job = createFreeStyleJob();

AnalysisAction projectAction = createProjectAction(job);
editJob(job, projectAction, new AnalysisConfigurator<AnalysisSettings>() {
@Override
public void configure(final AnalysisSettings settings) {
settings.setBuildHealthyThreshold(0);
settings.setBuildUnhealthyThreshold(getNumberOfWarnings());
}
});

buildSuccessfulJob(job);

jenkins.open();

List<WebElement> healthElements = all(by.xpath("//div[@class='healthReportDetails']//tr"));
assertThat(healthElements.size(), is(3));

String expectedText = String.format("%s: %d %s%s found.", projectAction.getName(), getNumberOfWarnings(),
projectAction.getAnnotationName(), plural(getNumberOfWarnings()));
assertThatHealthReportIs(healthElements.get(1), expectedText, "00to19");
assertThatHealthReportIs(healthElements.get(2), "Build stability: No recent builds failed.", "80plus");
}

// First td contains icon, second td contains text
private void assertThatHealthReportIs(final WebElement healthReportTable, final String expectedText, final String expectedIconName) {
List<WebElement> descriptions = healthReportTable.findElements(By.xpath("td"));

assertThat(getDescriptionValue(descriptions, 0), containsString(expectedIconName + " "));
assertThat(getDescriptionValue(descriptions, 1), is(expectedText));
}

private String getDescriptionValue(final List<WebElement> descriptions, final int index) {
return descriptions.get(index).getAttribute("innerHTML");
}

private void editJob(final Job job, final AnalysisAction action, @CheckForNull final AnalysisConfigurator<AnalysisSettings> configurator) {
job.configure();
configurator.configure(job.getPublisher(action.getFreeStyleSettings()));
job.save();
}

/**
* Builds a freestyle job with an enabled publisher of the plug-in under test. Verifies that the project action from
* the job redirects to the result of the last build. The the correct number of warnings in the project overview and
@@ -388,11 +441,9 @@ else if (isFreeStyleOrMatrixJob(jobClass)) {
* @param configurator the new configuration of the publisher
* @return the edited job
*/
private <J extends Job, T extends AnalysisSettings & PostBuildStep> J edit(String newResourceToCopy,
boolean isAdditionalResource,
J job,
Class<T> publisherBuildSettingsClass,
@CheckForNull AnalysisConfigurator<T> configurator) {
private <J extends Job, T extends AnalysisSettings & PostBuildStep> J edit(
@CheckForNull final String newResourceToCopy, final boolean isAdditionalResource,
final J job, final Class<T> publisherBuildSettingsClass, @CheckForNull AnalysisConfigurator<T> configurator) {
job.configure();

if (newResourceToCopy != null) {
@@ -408,12 +459,7 @@ else if (isFreeStyleOrMatrixJob(jobClass)) {

// change the configuration of the publisher
if (configurator != null) {
if (job instanceof MavenModuleSet) {
configurator.configure(((MavenModuleSet) job).getBuildSettings(publisherBuildSettingsClass));
}
else if (job instanceof FreeStyleJob) {
configurator.configure(job.getPublisher(publisherBuildSettingsClass));
}
configurator.configure(job.getPublisher(publisherBuildSettingsClass));
}

job.save();
@@ -5,7 +5,7 @@
import org.jenkinsci.test.acceptance.junit.WithPlugins;
import org.jenkinsci.test.acceptance.plugins.analysis_collector.AnalysisCollectorAction;
import org.jenkinsci.test.acceptance.plugins.analysis_collector.AnalysisCollectorColumn;
import org.jenkinsci.test.acceptance.plugins.analysis_collector.AnalysisCollectorFreestyleBuildSettings;
import org.jenkinsci.test.acceptance.plugins.analysis_collector.AnalysisCollectorSettings;
import org.jenkinsci.test.acceptance.plugins.analysis_collector.AnalysisGraphConfigurationView;
import org.jenkinsci.test.acceptance.plugins.analysis_collector.AnalysisPlugin;
import org.jenkinsci.test.acceptance.plugins.analysis_collector.WarningsPerProjectPortlet;
@@ -184,10 +184,10 @@ public void should_set_build_result_to_unstable() {
job.copyResource(ANALYSIS_COLLECTOR_PLUGIN_RESOURCES + "/findbugs.xml");
job.addPublisher(FindBugsFreestyleSettings.class);

AnalysisCollectorFreestyleBuildSettings analysis = job.addPublisher(AnalysisCollectorFreestyleBuildSettings.class);
AnalysisConfigurator<AnalysisCollectorFreestyleBuildSettings> configurator = new AnalysisConfigurator<AnalysisCollectorFreestyleBuildSettings>() {
AnalysisCollectorSettings analysis = job.addPublisher(AnalysisCollectorSettings.class);
AnalysisConfigurator<AnalysisCollectorSettings> configurator = new AnalysisConfigurator<AnalysisCollectorSettings>() {
@Override
public void configure(AnalysisCollectorFreestyleBuildSettings settings) {
public void configure(AnalysisCollectorSettings settings) {
settings.setBuildUnstableTotalAll("5");
}
};
@@ -331,7 +331,7 @@ public void should_aggregate_warnings_in_dashboard_portlet() {

private AnalysisCollectorAction deselectPluginAndBuild(AnalysisPlugin plugin, Job job) {
job.configure();
AnalysisCollectorFreestyleBuildSettings publisher = job.getPublisher(AnalysisCollectorFreestyleBuildSettings.class);
AnalysisCollectorSettings publisher = job.getPublisher(AnalysisCollectorSettings.class);
publisher.checkCollectedPlugin(plugin, false);
job.save();
Build build = buildSuccessfulJob(job);
@@ -351,7 +351,7 @@ private FreeStyleJob createJob(final String resourceToCopy, final boolean addAna
addAndConfigureWarningsPublisher(job);

if (addAnalysisPublisher) {
job.addPublisher(AnalysisCollectorFreestyleBuildSettings.class);
job.addPublisher(AnalysisCollectorSettings.class);
}
job.save();
return job;

0 comments on commit b9c6876

Please sign in to comment.
You can’t perform that action at this time.