Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-17225] Added test cases that show that the regexp tags featu…
…re works.
  • Loading branch information
uhafner committed Sep 7, 2014
1 parent 59ecf51 commit 0d9bb7c
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -25,7 +25,7 @@
</scm>

<properties>
<selenium.version>2.41.0</selenium.version>
<selenium.version>2.42.2</selenium.version>
<aether.version>0.9.0.v20140226</aether.version>
<maven.version>3.1.0</maven.version>
<groovy.version>2.3.1</groovy.version>
Expand Down
Expand Up @@ -26,6 +26,7 @@ public abstract class AbstractTaskScannerBuildSettings extends AbstractCodeStyle
protected Control normalPriorityTags = control("normal");
protected Control lowPriorityTags = control("low");
protected Control ignoreCase = control("ignoreCase");
protected Control asRegexp = control("asRegexp");

protected Control shouldDetectModules = control("shouldDetectModules");

Expand All @@ -50,7 +51,7 @@ public void setPattern(String pattern){
}

/**
* Sets the input for the file names to be excluded
* Sets the input for the file names to be excluded.
*/
public void setExcludePattern(String pattern) {
this.excludePattern.set(pattern);
Expand Down Expand Up @@ -78,12 +79,19 @@ public void setLowPriorityTags(String tags) {
}

/**
* Decides whether to ignore the case when searching for task tags
* Decides whether to ignore the case when searching for task tags.
*/
public void setIgnoreCase(boolean ignore) {
this.ignoreCase.check(ignore);
}

/**
* Decides whether to treat tags as regular expressions.
*/
public void setAsRegexp(boolean asRegexp) {
this.asRegexp.check(asRegexp);
}

/**
* Decides whether Ant or Maven modules should be detected
*/
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/plugins/CheckstylePluginTest.java
Expand Up @@ -305,9 +305,7 @@ public void build_a_job_and_check_if_dashboard_list_view_shows_correct_warnings(
ListView view = addDashboardListViewColumn(CheckstyleListViewColumn.class);

String relativeUrl = "job/" + job.name + "/checkstyle";
By expectedDashboardLinkMatcher = by.css("a[href$='" +
relativeUrl +
"']");
By expectedDashboardLinkMatcher = by.css("a[href$='" + relativeUrl + "']");
assertThat(jenkins.all(expectedDashboardLinkMatcher).size(), is(1));
WebElement dashboardLink = jenkins.getElement(expectedDashboardLinkMatcher);
assertThat(dashboardLink.getText().trim(), is("12"));
Expand Down
70 changes: 64 additions & 6 deletions src/test/java/plugins/TaskScannerPluginTest.java
Expand Up @@ -17,6 +17,7 @@
import org.jenkinsci.test.acceptance.plugins.tasks.TaskScannerMavenBuildSettings;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.Job;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.xml.sax.SAXException;
Expand All @@ -37,7 +38,7 @@
public class TaskScannerPluginTest extends AbstractCodeStylePluginHelper{

/**
* This test's objective is to verify the basic functionality of the Task
* This tests objective is to verify the basic functionality of the Task
* Scanner plugin, i.e. finding different task tags, including / excluding
* files and providing the correct results.
* The test builds the same job twice with and without case sensitivity.
Expand Down Expand Up @@ -169,7 +170,64 @@ public void configure(TaskScannerFreestyleBuildSettings settings) {
}

/**
* This test's objective is to verify that the plugin correctly works for
* This tests objective is to verify that the plugin correctly works for
* tags that are treated as regular expression.
*/
@Test
public void regular_expression() throws Exception {
AbstractCodeStylePluginBuildConfigurator<TaskScannerFreestyleBuildSettings> buildConfigurator =
new AbstractCodeStylePluginBuildConfigurator<TaskScannerFreestyleBuildSettings>() {
@Override
public void configure(TaskScannerFreestyleBuildSettings settings) {
settings.setPattern("**/*.txt");
settings.setNormalPriorityTags("^.*(TODO(?:[0-9]*))(.*)$");
settings.setAsRegexp(true);
}
};

FreeStyleJob job = setupJob("/tasks_plugin/regexp", FreeStyleJob.class,
TaskScannerFreestyleBuildSettings.class, buildConfigurator);

verifyRegularExpressionScannerResult(job);
}

private void verifyRegularExpressionScannerResult(final Job job) {
Build lastBuild = buildJobWithSuccess(job);
lastBuild.open();
TaskScannerAction tsa = new TaskScannerAction(job);

assertThat(tsa.getResultLinkByXPathText("5 open tasks"), is("tasksResult"));
assertThat(tsa.getResultTextByXPathText("5 open tasks"), endsWith("in 1 workspace file."));
assertThat(tsa.getWarningNumber(), is(5));
assertThat(tsa.getNormalWarningNumber(), is(5));
}

/**
* This tests objective is to verify that the plugin correctly works for
* tags that are treated as regular expression.
*/
@Test
public void regular_expression_maven() throws Exception {
AbstractCodeStylePluginBuildConfigurator<TaskScannerMavenBuildSettings> buildConfigurator =
new AbstractCodeStylePluginBuildConfigurator<TaskScannerMavenBuildSettings>() {
@Override
public void configure(TaskScannerMavenBuildSettings settings) {
settings.setPattern("**/*.txt");
settings.setNormalPriorityTags("^.*(TODO(?:[0-9]*))(.*)$");
settings.setAsRegexp(true);
}
};

MavenModuleSet job = setupJob("/tasks_plugin/regexp",
MavenModuleSet.class, TaskScannerMavenBuildSettings.class,
buildConfigurator, null);

verifyRegularExpressionScannerResult(job);
}


/**
* This tests objective is to verify that the plugin correctly works for
* multiple tags per priority.
* In the first step the task scanner is configured with two tags for high
* priority tasks. Prior to the second build also the normal and low priority
Expand Down Expand Up @@ -251,7 +309,7 @@ public void configure(TaskScannerFreestyleBuildSettings settings) {


/**
* This test's objective is to verify the detection of closed tasks.
* This tests objective is to verify 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.
Expand Down Expand Up @@ -313,7 +371,7 @@ public void configure(TaskScannerFreestyleBuildSettings settings) {
}

/**
* This test's objective is to check the "Run always" option of the publisher,
* This tests objective is to check the "Run always" option of the publisher,
* i.e whether the task scanner activity is skipped in case the main build step
* has already failed and the option "run always" is not activated. The option
* is activated for the second part to also scan for tasks in this failed job
Expand Down Expand Up @@ -374,7 +432,7 @@ public void configure(TaskScannerFreestyleBuildSettings settings) {
}

/**
* This test's objective to check the correct treatment and display of tasks
* This tests objective to check the correct treatment and display of tasks
* in files with windows-1251 (a.k.a. cp1251) encoding.
*
* This test shall reproduce the observations described in JENKINS-22744:
Expand Down Expand Up @@ -503,7 +561,7 @@ public void configure(TaskScannerMavenBuildSettings settings) {


/**
* This test's objective is to the correct treatment of the status thresholds (totals).
* This tests objective is to 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.
*
Expand Down
24 changes: 24 additions & 0 deletions src/test/resources/tasks_plugin/regexp/pom.xml
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>

</project>
9 changes: 9 additions & 0 deletions src/test/resources/tasks_plugin/regexp/regexp.txt
@@ -0,0 +1,9 @@
TODO1: erstes
TODO2: zweites
TODO3: drittes
TODO4: viertes
TODO20: zwanzigstes




0 comments on commit 0d9bb7c

Please sign in to comment.