Skip to content

Commit

Permalink
Add CPD to freestyle test.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Sep 27, 2019
1 parent 1383a38 commit eaa36d4
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author Alexandra Wenzel
*/
public class AnalysisSummary extends PageObject {
private static final Pattern NUMBER = Pattern.compile(".*(\\d)+.*");
private static final Pattern NUMBER = Pattern.compile("\\d+");
private static final String UNDEFINED = "-";

private final WebElement summary;
Expand Down Expand Up @@ -140,8 +140,8 @@ private int getSize(final String linkName) {

private int extractNumber(final String linkText) {
Matcher matcher = NUMBER.matcher(linkText);
if (matcher.matches()) {
return Integer.parseInt(matcher.group(1));
if (matcher.find()) {
return Integer.parseInt(matcher.group(0));
}
else if (linkText.startsWith("One")) {
return 1;
Expand Down Expand Up @@ -227,6 +227,36 @@ public QualityGateResult getQualityGateResult() {
return QualityGateResult.INACTIVE;
}

/**
* Gets the Webelement of the reset button.
*
* @throws org.openqa.selenium.NoSuchElementException
* When there is no quality gate reset button.
*/
public WebElement getQualityGateResetButton() throws org.openqa.selenium.NoSuchElementException {
for (WebElement result : results) {
if (result.getText().contains("Quality gate")) {
return result.findElement(by.id(id + "-resetReference"));
}
}
throw new org.openqa.selenium.NoSuchElementException("Quality gate reset button not found");
}

/**
* Checks if the quality gate reset button is present.
*
* @return True, if quality gate reset button is present.
*/
public boolean hasQualityGateResetButton() {
try {
if (getQualityGateResetButton() != null) {
return true;
}
} catch (org.openqa.selenium.NoSuchElementException ignored) { }

return false;
}

/**
* Returns a clickable WebElement (a-tag), by a part of the elements text.
*
Expand Down Expand Up @@ -266,11 +296,11 @@ private WebElement getSummary() {
}

private WebElement getTitleResultLink() {
return summary.findElement(by.href(this.id));
return summary.findElement(by.href(id));
}

private WebElement getTitleResultInfoLink() {
return summary.findElement(by.href(this.id + "/info"));
return summary.findElement(by.href(id + "/info"));
}

private WebElement getTitle() {
Expand Down Expand Up @@ -307,6 +337,6 @@ static InfoType valueOfClass(final String iconName) {
* Determines the quality gate result.
*/
public enum QualityGateResult {
SUCCESS, FAILED, UNSTABLE, INACTIVE;
SUCCESS, FAILED, UNSTABLE, INACTIVE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import java.util.function.Consumer;

import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.Select;

import org.jenkinsci.test.acceptance.po.AbstractStep;
import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.Describable;
Expand All @@ -25,12 +22,14 @@ public class IssuesRecorder extends AbstractStep implements PostBuildStep {
private Control qualityGatesRepeatable = findRepeatableAddButtonFor("qualityGates");
private Control advancedButton = control("advanced-button");
private Control enabledForFailureCheckBox = control("enabledForFailure");
private Control ignoreAnalysisResultCheckBox = control("ignoreAnalysisResult");
private Control ignoreQualityGate = control("ignoreQualityGate");
private Control overallResultMustBeSuccessCheckBox = control("overallResultMustBeSuccess");
private Control referenceJobField = control("referenceJob");
private Control aggregatingResultsCheckBox = control("aggregatingResults");
private Control sourceCodeEncoding = control("sourceCodeEncoding");

public enum QualityGateBuildResult {UNSTABLE, FAILED}

/**
* Returns the repeatable add button for the specified property.
*
Expand All @@ -55,6 +54,7 @@ public IssuesRecorder(final Job parent, final String path) {
super(parent, path);

ScrollerUtil.hideScrollerTabBar(driver);
openAdvancedOptions();
}

/**
Expand Down Expand Up @@ -150,9 +150,7 @@ public StaticAnalysisTool addTool(final String toolName, final String pattern) {
* the encoding to use when reading source files
*/
public void setSourceCodeEncoding(final String encoding) {
openAdvancedOptions();

this.sourceCodeEncoding.set(encoding);
sourceCodeEncoding.set(encoding);
}

/**
Expand Down Expand Up @@ -181,10 +179,8 @@ public void setEnabledForAggregation(final boolean isChecked) {
* @param isChecked
* determines if the checkbox should be checked or not
*/
public void setIgnoreAnalysisResult(final boolean isChecked) {
openAdvancedOptions();

ignoreAnalysisResultCheckBox.check(isChecked);
public void setIgnoreQualityGate(final boolean isChecked) {
ignoreQualityGate.check(isChecked);
}

/**
Expand All @@ -194,8 +190,6 @@ public void setIgnoreAnalysisResult(final boolean isChecked) {
* determines if the checkbox should be checked or not
*/
public void setOverallResultMustBeSuccess(final boolean isChecked) {
openAdvancedOptions();

overallResultMustBeSuccessCheckBox.check(isChecked);
}

Expand All @@ -206,8 +200,6 @@ public void setOverallResultMustBeSuccess(final boolean isChecked) {
* the name of the referenceJob
*/
public void setReferenceJobField(final String referenceJob) {
openAdvancedOptions();

referenceJobField.set(referenceJob);
}

Expand Down Expand Up @@ -249,17 +241,15 @@ public void setToolWithPattern(final String toolName, final String pattern) {
* the minimum number of issues that fails the quality gate
* @param type
* the type of the quality gate
* @param isUnstable
* @param result
* determines whether the quality gate sets the build result to Unstable or Failed
*/
public void addQualityGateConfiguration(final int threshold, final QualityGateType type, final boolean isUnstable) {
openAdvancedOptions();

public void addQualityGateConfiguration(final int threshold, final QualityGateType type, final QualityGateBuildResult result) {
String path = createPageArea("qualityGates", () -> qualityGatesRepeatable.click());
QualityGatePanel qualityGate = new QualityGatePanel(this, path);
qualityGate.setThreshold(threshold);
qualityGate.setType(type);
qualityGate.setUnstable(isUnstable);
qualityGate.setUnstable(result == QualityGateBuildResult.UNSTABLE);
}

/**
Expand All @@ -271,8 +261,6 @@ public void addQualityGateConfiguration(final int threshold, final QualityGateTy
* regular expression to apply
*/
public void addIssueFilter(final String filterName, final String regex) {
openAdvancedOptions();

String path = createPageArea("filters", () -> filtersRepeatable.selectDropdownMenu(filterName));
IssueFilterPanel filter = new IssueFilterPanel(this, path);
filter.setFilter(regex);
Expand All @@ -282,38 +270,23 @@ public void addIssueFilter(final String filterName, final String regex) {
* Available quality gate types.
*/
public enum QualityGateType {
/** Total number of issues. */
TOTAL("Total number of issues (any severity)"),
/** Total number of issues (severity Error). */
TOTAL_ERROR("Total number of errors"),
/** Total number of issues (severity Warning High). */
TOTAL_HIGH("Total number of warnings (severity high)"),
/** Total number of issues (severity Warning Normal). */
TOTAL_NORMAL("Total number of warnings (severity normal)"),
/** Total number of issues (severity Warning Low). */
TOTAL_LOW("Total number of warnings (severity low)"),

/** Number of new issues. */
NEW("Number of new issues (any severity)"),
/** Number of new issues (severity Error). */
NEW_ERROR("Number of new errors"),
/** Number of new issues (severity Warning High). */
NEW_HIGH("Number of new warnings (severity high)"),
/** Number of new issues (severity Warning Normal). */
NEW_NORMAL("Number of new warnings (severity normal)"),
/** Number of new issues (severity Warning Low). */
NEW_LOW("Number of new warnings (severity low)"),

/** Delta current build - reference build. */
TOTAL("Total (any severity)"),
TOTAL_ERROR("Total (errors only)"),
TOTAL_HIGH("Total (severity high only)"),
TOTAL_NORMAL("Total (severity normal only)"),
TOTAL_LOW("Total (severity low only)"),

NEW("New (any severity)"),
NEW_ERROR("New (errors only)"),
NEW_HIGH("New (severity high only)"),
NEW_NORMAL("New (severity normal only)"),
NEW_LOW("New (severity low only)"),

DELTA("Delta (any severity)"),
/** Delta current build - reference build (severity Error). */
DELTA_ERROR("Delta of errors"),
/** Delta current build - reference build (severity Warning High). */
DELTA_HIGH("Delta of warnings (severity high)"),
/** Delta current build - reference build (severity Warning Normal). */
DELTA_NORMAL("Delta of warnings (severity normal)"),
/** Delta current build - reference build (severity Warning Low). */
DELTA_LOW("Delta of warnings (severity low)");
DELTA_ERROR("Delta (errors only)"),
DELTA_HIGH("Delta (severity high only)"),
DELTA_NORMAL("Delta (severity normal only)"),
DELTA_LOW("Delta (severity low only)");

private final String displayName;

Expand Down Expand Up @@ -379,7 +352,7 @@ public StaticAnalysisTool setPattern(final String pattern) {
*
* @return this
*/
public StaticAnalysisTool setNormalThreshold(int normalThreshold) {
public StaticAnalysisTool setNormalThreshold(final int normalThreshold) {
this.normalThreshold.set(normalThreshold);

return this;
Expand All @@ -393,7 +366,7 @@ public StaticAnalysisTool setNormalThreshold(int normalThreshold) {
*
* @return this
*/
public StaticAnalysisTool setHighThreshold(int highThreshold) {
public StaticAnalysisTool setHighThreshold(final int highThreshold) {
this.highThreshold.set(highThreshold);

return this;
Expand Down Expand Up @@ -421,7 +394,6 @@ private void setFilter(final String regex) {
private static class QualityGatePanel extends PageAreaImpl {
private final Control threshold = control("threshold");
private final Control type = control("type");
private final Control unstable = control("unstable");

QualityGatePanel(final PageArea area, final String path) {
super(area, path);
Expand All @@ -436,7 +408,7 @@ public void setType(final QualityGateType type) {
}

public void setUnstable(final boolean isUnstable) {
find(by.xpath("//input[@type='radio' and contains(@path,'unstable[" + isUnstable + "]')]")).click();
self().findElement(by.xpath(".//input[@type='radio' and contains(@path,'unstable[" + isUnstable + "]')]")).click();
}
}
}

0 comments on commit eaa36d4

Please sign in to comment.