Search in sources :

Example 1 with Matcher

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);
        }
    };
}
Also used : Description(org.hamcrest.Description) Matcher(org.jenkinsci.test.acceptance.Matcher) DashboardView(org.jenkinsci.test.acceptance.plugins.dashboard_view.DashboardView) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 2 with Matcher

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);
            }
        }
    };
}
Also used : Description(org.hamcrest.Description) Matcher(org.jenkinsci.test.acceptance.Matcher) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with Matcher

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());
        }
    };
}
Also used : Description(org.hamcrest.Description) Matcher(org.jenkinsci.test.acceptance.Matcher) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException) JenkinsLogger(org.jenkinsci.test.acceptance.po.JenkinsLogger) TimeoutException(org.openqa.selenium.TimeoutException)

Example 4 with Matcher

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);
            }
        }
    };
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) Matcher(org.jenkinsci.test.acceptance.Matcher)

Aggregations

Description (org.hamcrest.Description)4 Matcher (org.jenkinsci.test.acceptance.Matcher)4 NoSuchElementException (org.openqa.selenium.NoSuchElementException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 StringDescription (org.hamcrest.StringDescription)1 DashboardView (org.jenkinsci.test.acceptance.plugins.dashboard_view.DashboardView)1 JenkinsLogger (org.jenkinsci.test.acceptance.po.JenkinsLogger)1 TimeoutException (org.openqa.selenium.TimeoutException)1 WebElement (org.openqa.selenium.WebElement)1