Skip to content
Permalink
Browse files
[JENKINS-24940] Added checking of fixed and new warnings.
Fixed and new warnings are now checked twice: right after a build
and after a restart of Jenkins.

Improved test cases:
- Added verification of fixed warnings.
- Use new summary table IDs when checking the cells.
- Check the overview values as well as the number of elements in the fixed warnings table.
  • Loading branch information
uhafner committed Jun 4, 2015
1 parent 6e46678 commit c8a96001366835afd3d8fa15e4e6ed0dfd611443
@@ -1,6 +1,5 @@
package org.jenkinsci.test.acceptance.plugins.analysis_core;

import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -43,14 +42,9 @@ public AnalysisAction(final Job parent, final String plugin) {
this(plugin, parent);
}

/**
* Constructor for a action.
*
* @param url path to plugin action without / at the end
* @param parent parent container page object
*/
public AnalysisAction(String url, ContainerPageObject parent) {
private AnalysisAction(String url, ContainerPageObject parent) {
super(parent, parent.url(url + '/'));

this.parent = parent;
plugin = url;
}
@@ -65,98 +59,78 @@ public String getResultUrl() {
}

/**
* Getter of the url for high prio Warnings.
* Returns the number of warnings.
*
* @return Url for high prio Warnings
* @return number of warnings
*/
public URL getHighPrioUrl() {
return parent.url(plugin + "/HIGH");
public int getNumberOfWarnings() {
return getSummaryCellXPath("all");
}

/**
* Getter of the relative path for new Warnings page.
* Returns the number of new warnings.
*
* @return String for new Warnings page
* @return number of new warnings
*/
public String getNewWarningsUrlAsRelativePath() {
return plugin + "/new";
public int getNumberOfNewWarnings() {
return getSummaryCellXPath("new");
}

/**
* Getter of all warnings.
* Returns the number of fixed warnings.
*
* @return Number of warnings
* @return number of fixed warnings
*/
public int getWarningNumber() {
return getIntByXPath("//table[@id='summary']/tbody/tr/td[@class='pane'][1]");
public int getNumberOfFixedWarnings() {
return getSummaryCellXPath("fixed");
}

/**
* Getter of new warnings.
*
* @return Number of new warnings
*/
public int getNewWarningNumber() {
return getIntByXPath("//table[@id='summary']/tbody/tr/td[@class='pane'][2]");
private int getSummaryCellXPath(final String element) {
return getIntByXPath("//td[@id='" + element + "']");
}

/**
* Getter of fixed warnings.
* Returns the number of warnings with high priority.
*
* @return Number of fixed warnings
* @return number of warnings with high priority
*/
public int getFixedWarningNumber() {
return getIntByXPath("//table[@id='summary']/tbody/tr/td[@class='pane'][3]");
}

/**
* Getter of high warnings.
*
* @return Number of high warnings
*/
public int getHighWarningNumber() {
public int getNumberOfWarningsWithHighPriority() {
return getPriorityWarningNumber("HIGH");
}

/**
* Getter of normal warnings.
* Returns the number of warnings with normal priority.
*
* @return Number of normal warnings
* @return number of warnings with normal priority
*/
public int getNormalWarningNumber() {
public int getNumberOfWarningsWithNormalPriority() {
return getPriorityWarningNumber("NORMAL");
}

/**
* Getter of low warnings.
* Returns the number of warnings with low priority.
*
* @return Number of low warnings.
* @return number of warnings with low priority
*/
public int getLowWarningNumber() {
public int getNumberOfWarningsWithLowPriority() {
return getPriorityWarningNumber("LOW");
}

private int getPriorityWarningNumber(final String priority) {
return getIntByXPath("//div[@id='" + priority + "']");
}

/**
* Getter for the href-value with the supplied text of a link.
*
* @param linkText Link text with href to get
* @return Href-value of link with given text
*/
public String getResultLinkByXPathText(final String linkText) {
final String htmlElement = find(by.xpath(".//A[text() = '" + linkText + "']")).getAttribute("outerHTML");
String htmlElement = find(by.xpath(".//A[text() = '" + linkText + "']")).getAttribute("outerHTML");
return StringUtils.substringBetween(htmlElement, "\"");
}

/**
* Getter for warning counts of a certain priority
*
* @param priority the desired priority whose number of warnings shall be extracted (LOW, NORMAL, HIGH)
* @return number of warnings of that priority
*/
private int getPriorityWarningNumber(String priority) {
return getIntByXPath("//table[@id='analysis.summary']/tbody/tr/td[@class='pane']/div[@id='" + priority + "']");
}

/**
* Get number of path.
*
@@ -281,6 +255,16 @@ public SortedMap<String, Integer> getWarningsTabContents() {
return getContentsOfVisibleTable(true, false);
}

/**
* Returns the number of fixed warnings by counting the number of rows in the 'fixed' warnings table.
*
* @return the number of fixed warnings
*/
// TODO: actually the content of each row should be validated
public int getNumberOfRowsInFixedWarningsTable() {
return getVisibleTableRows(true, false, find(by.xpath("//table[@id='fixed']"))).size();
}

/**
* Returns the first two columns of the "Fixed"-tab as key => value pairs, skipping the header row.
*
@@ -305,6 +289,10 @@ private <T extends Object> SortedMap<String, T> getContentsOfVisibleTable(Class<

protected List<WebElement> getVisibleTableRows(boolean removeHeader, boolean removeFooter) {
WebElement table = find(by.xpath("//div[@id='statistics']/div/div/table"));
return getVisibleTableRows(removeHeader, removeFooter, table);
}

private List<WebElement> getVisibleTableRows(final boolean removeHeader, final boolean removeFooter, final WebElement table) {
final List<WebElement> immediateChildRows = table.findElements(by.xpath("./tbody/tr"));

if (removeHeader) {
@@ -369,6 +357,13 @@ public void openNew() {
visit("new");
}

/**
* Opens the details page that show the fixed warnings.
*/
public void openFixed() {
visit("fixed");
}

/**
* Returns the affected source code as String which is linked by the specified tab table entry.
*
@@ -77,17 +77,17 @@ public void should_collect_warnings_of_all_tools() {
AnalysisCollectorAction action = new AnalysisCollectorAction(build);
action.open();

assertThat(action.getWarningNumber(), is(TOTAL));
assertThat(action.getNewWarningNumber(), is(TOTAL));
assertThat(action.getNumberOfWarnings(), is(TOTAL));
assertThat(action.getNumberOfNewWarnings(), is(TOTAL));

int high = CHECKSTYLE_HIGH + FINDBUGS_HIGH + PMD_HIGH + TASKS_HIGH + WARNINGS_HIGH;
assertThat(action.getHighWarningNumber(), is(high));
assertThat(action.getNumberOfWarningsWithHighPriority(), is(high));

int low = CHECKSTYLE_LOW + FINDBUGS_LOW + PMD_LOW + TASKS_LOW + WARNINGS_LOW;
assertThat(action.getLowWarningNumber(), is(low));
assertThat(action.getNumberOfWarningsWithLowPriority(), is(low));

int normal = TOTAL - low - high;
assertThat(action.getNormalWarningNumber(), is(normal));
assertThat(action.getNumberOfWarningsWithNormalPriority(), is(normal));
}

/**
@@ -109,11 +109,11 @@ public void should_compute_all_new_open_tasks() {
AnalysisCollectorAction action = new AnalysisCollectorAction(build);
action.open();

assertThat(action.getWarningNumber(), is(8));
assertThat(action.getHighWarningNumber(), is(2));
assertThat(action.getNormalWarningNumber(), is(4));
assertThat(action.getLowWarningNumber(), is(2));
assertThat(action.getNewWarningNumber(), is(4));
assertThat(action.getNumberOfWarnings(), is(8));
assertThat(action.getNumberOfWarningsWithHighPriority(), is(2));
assertThat(action.getNumberOfWarningsWithNormalPriority(), is(4));
assertThat(action.getNumberOfWarningsWithLowPriority(), is(2));
assertThat(action.getNumberOfNewWarnings(), is(4));
}

/**
@@ -154,22 +154,22 @@ public void should_collect_warnings_of_selected_tools_only() {
AnalysisCollectorAction action = deselectPluginAndBuild(CHECKSTYLE, job);

remaining -= CHECKSTYLE_ALL;
assertThat(action.getWarningNumber(), is(remaining));
assertThat(action.getNumberOfWarnings(), is(remaining));

action = deselectPluginAndBuild(FINDBUGS, job);
remaining -= FINDBUGS_ALL;
assertThat(action.getWarningNumber(), is(remaining));
assertThat(action.getNumberOfWarnings(), is(remaining));

action = deselectPluginAndBuild(PMD, job);
remaining -= PMD_ALL;
assertThat(action.getWarningNumber(), is(remaining));
assertThat(action.getNumberOfWarnings(), is(remaining));

action = deselectPluginAndBuild(TASKS, job);
remaining -= TASKS_ALL;
assertThat(action.getWarningNumber(), is(remaining));
assertThat(action.getNumberOfWarnings(), is(remaining));

action = deselectPluginAndBuild(WARNINGS, job);
assertThat(action.getWarningNumber(), is(0));
assertThat(action.getNumberOfWarnings(), is(0));
}

/**

0 comments on commit c8a9600

Please sign in to comment.