use of org.jenkinsci.test.acceptance.Matcher in project acceptance-test-harness by jenkinsci.
the class AnalysisCollectorPluginTest method hasWarnings.
public static Matcher<DashboardView> hasWarnings(final String jobName, final String pluginId, final int warningsCount) {
return new Matcher<DashboardView>(" shows %s warnings for plugin %s and job %s", warningsCount, pluginId, jobName) {
@Override
public boolean matchesSafely(final DashboardView view) {
view.open();
try {
WebElement warningsLink = findPortletLink(view, jobName, pluginId);
String linkText = warningsLink.getText();
return Integer.parseInt(linkText) == warningsCount;
} catch (NoSuchElementException | NumberFormatException e) {
return false;
}
}
@Override
public void describeMismatchSafely(final DashboardView view, final Description desc) {
desc.appendText("Portlet does not show expected warnings for plugin " + pluginId);
}
};
}
use of org.jenkinsci.test.acceptance.Matcher in project acceptance-test-harness by jenkinsci.
the class View method containsJob.
public static Matcher<View> containsJob(final Job needle) {
return new Matcher<View>("Contains job " + needle.name) {
@Override
public boolean matchesSafely(View view) {
for (JsonNode job : view.getJson().get("jobs")) {
String name = job.get("name").asText();
if (needle.name.equals(name))
return true;
}
return false;
}
@Override
public void describeMismatchSafely(View view, Description mismatchDescription) {
mismatchDescription.appendText("view containing:");
for (JsonNode job : view.getJson().get("jobs")) {
String name = job.get("name").asText();
mismatchDescription.appendText(" ").appendText(name);
}
}
};
}
use of org.jenkinsci.test.acceptance.Matcher in project acceptance-test-harness by jenkinsci.
the class DiskUsage method reloaded.
public static Matcher<DiskUsage> reloaded() {
return new Matcher<DiskUsage>("disk usage reloaded") {
private Exception cause;
@Override
public boolean matchesSafely(DiskUsage item) {
JenkinsLogger logger = item.getJenkins().getLogger("all");
try {
logger.waitForLogged(Pattern.compile("Finished Project disk usage. \\d+ ms"));
return true;
} catch (TimeoutException ex) {
// v0.22 and newer
cause = ex;
}
try {
logger.waitForLogged(Pattern.compile("Finished Calculation of builds disk usage.*"));
logger.waitForLogged(Pattern.compile("Finished Calculation of job directories.*"));
logger.waitForLogged(Pattern.compile("Finished Calculation of workspace usage.*"));
return true;
} catch (TimeoutException ex) {
cause = ex;
return false;
}
}
@Override
public void describeMismatchSafely(DiskUsage item, Description dsc) {
dsc.appendText(cause.getMessage());
}
};
}
use of org.jenkinsci.test.acceptance.Matcher in project acceptance-test-harness by jenkinsci.
the class FormValidation method reports.
public static Matcher<FormValidation> reports(final Kind kind, final org.hamcrest.Matcher<String> message) {
StringDescription sd = new StringDescription();
message.describeTo(sd);
return new Matcher<FormValidation>("Validation reporting " + kind + " with message: " + sd.toString()) {
@Override
public boolean matchesSafely(FormValidation item) {
return item.getKind() == kind && message.matches(item.getMessage());
}
@Override
public void describeMismatchSafely(FormValidation item, Description mismatchDescription) {
if (item.getKind() != kind) {
mismatchDescription.appendText("It is " + item.toString());
} else {
message.describeMismatch(item.getMessage(), mismatchDescription);
}
}
};
}
Aggregations