Skip to content

Commit

Permalink
[JENKINS-34759] [JENKINS-34760] Added test that exposes the bug in core.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed May 18, 2016
1 parent 41f873c commit 3bf4797
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
@@ -1,7 +1,11 @@
package org.jenkinsci.test.acceptance.plugins.analysis_core;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.Job;
import org.openqa.selenium.WebElement;

/**
* Abstract job configuration class.
Expand All @@ -22,4 +26,25 @@ public abstract class AnalysisFreestyleSettings extends AnalysisSettings {
public AnalysisFreestyleSettings(Job parent, String selectorPath) {
super(parent, selectorPath);
}

/**
* Sets the pattern to the specified value and leaves the input field with tab so that the background
* validation will be started.
*
* @param value the new pattern value
* @return the validation result
*/
public String validatePattern(final String value) {
pattern.set(value);
pattern.sendKeys("\t");
elasticSleep(50); // wait for validation

// TODO: Use pattern to find the error div rather than the publisher
WebElement element = find(by.xpath("//div[@name='publisher']"));
List<WebElement> errors = element.findElements(by.xpath(".//div[@class='error']"));
if (errors.isEmpty()) {
return StringUtils.EMPTY;
}
return errors.get(0).getText();
}
}
40 changes: 39 additions & 1 deletion src/test/java/plugins/PmdPluginTest.java
Expand Up @@ -20,6 +20,7 @@
import org.jenkinsci.test.acceptance.po.ListView;
import org.jenkinsci.test.acceptance.po.Node;
import org.jenkinsci.test.acceptance.po.PageObject;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.jvnet.hudson.test.Issue;
Expand All @@ -28,8 +29,9 @@

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.text.IsEmptyString.isEmptyString;
import static org.jenkinsci.test.acceptance.Matchers.*;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.*;

/**
* Acceptance tests for the PMD plugin.
Expand Down Expand Up @@ -72,6 +74,42 @@ protected int getNumberOfWarnings() {
return TOTAL_NUMBER_OF_WARNINGS;
}

/**
* Verifies the validation of the ant pattern input field. The workspace is populated with several pmd files. Then,
* different patterns are provided that all should match.
*/
@Test @Issue({"JENKINS-34759", "JENKINS-34760"}) @Ignore("Until JENKINS-34759 JENKINS-34760 has been fixed in core.")
public void should_show_no_warnings_for_correct_ant_patterns() {
FreeStyleJob job = createFreeStyleJob();

AnalysisConfigurator<PmdFreestyleSettings> buildConfigurator = new AnalysisConfigurator<PmdFreestyleSettings>() {
@Override
public void configure(PmdFreestyleSettings settings) {
settings.pattern.set(PATTERN_WITHOUT_WARNINGS);
}
};

editJob(PLUGIN_ROOT, false, job,
PmdFreestyleSettings.class, buildConfigurator);
buildSuccessfulJob(job);

validatePattern(job, "pmd.xml,not-here.xml");
validatePattern(job, "not-here.xml,pmd.xml");
validatePattern(job, "pmd.xml not-here.xml");
}

private void validatePattern(final FreeStyleJob job, final String pattern) {
AnalysisConfigurator<PmdFreestyleSettings> buildConfigurator = new AnalysisConfigurator<PmdFreestyleSettings>() {
@Override
public void configure(PmdFreestyleSettings settings) {
String validationMessage = settings.validatePattern(pattern);
assertThat(validationMessage, isEmptyString());
}
};
editJob(PLUGIN_ROOT, false, job,
PmdFreestyleSettings.class, buildConfigurator);
}

/**
* Checks that the plug-in sends a mail after a build has been failed. The content of the mail
* contains several tokens that should be expanded in the mail with the correct values.
Expand Down

0 comments on commit 3bf4797

Please sign in to comment.