Search in sources :

Example 26 with Job

use of org.jenkinsci.test.acceptance.po.Job in project acceptance-test-harness by jenkinsci.

the class GerritTriggerTest method gerrit_trigger_build_when_changes_merged.

@Test
public void gerrit_trigger_build_when_changes_merged() {
    GerritTriggerNewServer newServer = new GerritTriggerNewServer(jenkins);
    newServer.saveNewTestServerConfigIfNone(gtHostname);
    GerritTriggerServer server = new GerritTriggerServer(jenkins, gtHostname);
    server.saveTestServerConfig(gtHostname, gtGerritFrontUrl, gtGerrituser, gtPrivateKey);
    Job j = jenkins.jobs.create(FreeStyleJob.class);
    String jobName = j.name;
    GerritTriggerJob job = new GerritTriggerJob(jenkins, jobName);
    job.saveTestJobConfig(GerritTriggerJob.EventToTriggerOn.ChangeMerged, gtHostname, gtProject);
    try {
        String changeId = pushChangeForMerge(jobName);
        changes.add(changeId);
        Build b = new Build(j, j.getNextBuildNumber());
        assertTrue(b.waitUntilFinished().isSuccess());
        elasticSleep(10000);
        ProcessBuilder gerritQuery = new ProcessBuilder("ssh", "-p", "29418", "-i", gtPrivateKey, gtGerrituser + "@" + gtHostname, "gerrit", "query", "change_id=" + changeId, "--all-approvals", "--format JSON");
        String json = removeLastLine(stringFrom(logProcessBuilderIssues(gerritQuery, "gerrit query")));
        checkApprovalValueFromJSON(json, "Verified", 1);
        checkApprovalValueFromJSON(json, "Code-Review", 1);
    } catch (InterruptedException | IOException e) {
        fail(e.getMessage());
    }
}
Also used : GerritTriggerNewServer(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerNewServer) GerritTriggerServer(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerServer) Build(org.jenkinsci.test.acceptance.po.Build) GerritTriggerJob(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerJob) IOException(java.io.IOException) Job(org.jenkinsci.test.acceptance.po.Job) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) GerritTriggerJob(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 27 with Job

use of org.jenkinsci.test.acceptance.po.Job in project acceptance-test-harness by jenkinsci.

the class JobsGridPortlet method getJob.

/**
 * Opens and returns the job at the given position in the grid.
 *
 * @param column the column of the job
 * @param row    the row of the job
 * @return The job at the given position. Null if the position exists, but is empty.
 * @throws NoSuchElementException if column or row are below 0 or higher than the column- or row-number of the grid.
 */
@CheckForNull
public Job getJob(int row, int column) throws NoSuchElementException {
    getPage().open();
    getTable().findElement(By.xpath("//tbody/tr[" + row + "]/td[" + column + "]"));
    try {
        WebElement link = getTable().findElement(By.xpath("//tbody/tr[" + row + "]/td[" + column + "]/a[2]"));
        String name = link.getText();
        URL url = new URL(link.getAttribute("href"));
        return new Job(injector, url, name);
    } catch (NoSuchElementException e) {
        // position exists in grid, but is empty
        return null;
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) WebElement(org.openqa.selenium.WebElement) Job(org.jenkinsci.test.acceptance.po.Job) URL(java.net.URL) NoSuchElementException(org.openqa.selenium.NoSuchElementException) CheckForNull(javax.annotation.CheckForNull)

Example 28 with Job

use of org.jenkinsci.test.acceptance.po.Job in project acceptance-test-harness by jenkinsci.

the class GerritTriggerTest method gerrit_trigger_build_when_draft_published.

@Test
public void gerrit_trigger_build_when_draft_published() {
    GerritTriggerNewServer newServer = new GerritTriggerNewServer(jenkins);
    newServer.saveNewTestServerConfigIfNone(gtHostname);
    GerritTriggerServer server = new GerritTriggerServer(jenkins, gtHostname);
    server.saveTestServerConfig(gtHostname, gtGerritFrontUrl, gtGerrituser, gtPrivateKey);
    Job j = jenkins.jobs.create(FreeStyleJob.class);
    GerritTriggerJob job = new GerritTriggerJob(jenkins, j.name);
    job.saveTestJobConfig(GerritTriggerJob.EventToTriggerOn.DraftPublished, gtHostname, gtProject);
    try {
        String changeId = pushDraftForPublishing(j.name);
        changes.add(changeId);
        Build b = new Build(j, j.getNextBuildNumber());
        assertTrue(b.waitUntilFinished().isSuccess());
        elasticSleep(10000);
        ProcessBuilder gerritQuery = new ProcessBuilder("ssh", "-p", "29418", "-i", gtPrivateKey, gtGerrituser + "@" + gtHostname, "gerrit", "query", "change_id=" + changeId, "--all-approvals", "--format JSON");
        String json = removeLastLine(stringFrom(logProcessBuilderIssues(gerritQuery, "gerrit query")));
        LOGGER.info(json);
        checkApprovalValueFromJSON(json, "Verified", 1);
        checkApprovalValueFromJSON(json, "Code-Review", 1);
    } catch (InterruptedException | IOException e) {
        fail(e.getMessage());
    }
}
Also used : GerritTriggerNewServer(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerNewServer) GerritTriggerServer(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerServer) Build(org.jenkinsci.test.acceptance.po.Build) GerritTriggerJob(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerJob) IOException(java.io.IOException) Job(org.jenkinsci.test.acceptance.po.Job) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) GerritTriggerJob(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 29 with Job

use of org.jenkinsci.test.acceptance.po.Job in project acceptance-test-harness by jenkinsci.

the class GerritTriggerTest method gerrit_has_review_flags_checked_after_jenkins_set_them.

@Test
public void gerrit_has_review_flags_checked_after_jenkins_set_them() {
    GerritTriggerNewServer newServer = new GerritTriggerNewServer(jenkins);
    newServer.saveNewTestServerConfigIfNone(gtHostname);
    GerritTriggerServer server = new GerritTriggerServer(jenkins, gtHostname);
    server.saveTestServerConfig(gtHostname, gtGerritFrontUrl, gtGerrituser, gtPrivateKey);
    Job j = jenkins.jobs.create(FreeStyleJob.class);
    String jobName = j.name;
    GerritTriggerJob job = new GerritTriggerJob(jenkins, jobName);
    job.saveTestJobConfig(GerritTriggerJob.EventToTriggerOn.PatchsetCreated, gtHostname, gtProject);
    try {
        String changeId = pushChangeForReview(jobName).changeId;
        changes.add(changeId);
        Build b = new Build(j, j.getNextBuildNumber());
        assertTrue(b.waitUntilFinished().isSuccess());
        elasticSleep(10000);
        ProcessBuilder gerritQuery = new ProcessBuilder("ssh", "-p", "29418", "-i", gtPrivateKey, gtGerrituser + "@" + gtHostname, "gerrit", "query", "change_id=" + changeId, "--all-approvals", "--format JSON");
        String json = removeLastLine(stringFrom(logProcessBuilderIssues(gerritQuery, "gerrit query")));
        checkApprovalValueFromJSON(json, "Verified", 1);
        checkApprovalValueFromJSON(json, "Code-Review", 1);
    } catch (InterruptedException | IOException e) {
        fail(e.getMessage());
    }
}
Also used : GerritTriggerNewServer(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerNewServer) GerritTriggerServer(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerServer) Build(org.jenkinsci.test.acceptance.po.Build) GerritTriggerJob(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerJob) IOException(java.io.IOException) Job(org.jenkinsci.test.acceptance.po.Job) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) GerritTriggerJob(org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test)

Example 30 with Job

use of org.jenkinsci.test.acceptance.po.Job in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_create_job.

@Test
@WithPlugins({ "sidebar-link", "build-name-setter", "envinject" })
public void should_create_job() {
    // Arrange
    String jobName = "MyJob";
    String jobDescription = "My sample description";
    String jobDisplayName = "My job display name";
    String jobLabel = "!ubuntu";
    String linkUrl = "https://jenkins.io";
    String linkLabel = "jenkins.io";
    String jobDslScript = String.format(multiline("job('%s') {", "    description('%s');", "    displayName('%s');", "    label('%s');", "    customWorkspace('/tmp/custom-workspace')", "    environmentVariables(varname: 'varval')", "    properties {", "        sidebarLinks {", "            link('%s', '%s')", "        }", "    };", "    wrappers { buildName('custom-name') }", "    concurrentBuild();", "    steps {", "        shell('sleep 10')", "    }", "}"), jobName, jobDescription, jobDisplayName, jobLabel, linkUrl, linkLabel);
    Job seed = createSeedJobWithJobDsl(jobDslScript);
    seed.startBuild().shouldSucceed();
    // Verify configuration
    Job job = jenkins.jobs.get(Job.class, jobName);
    job.open();
    assertThat(job.getDescription(), containsString(jobDescription));
    assertThat(job.getDisplayName(), containsString(jobDisplayName));
    assertThat(driver, hasElement(by.href(linkUrl)));
    job.configure();
    WebElement labelElement = driver.findElement(By.xpath("//input[@name='_.label']"));
    assertEquals(jobLabel, labelElement.getAttribute("value"));
    Build build = job.scheduleBuild().waitUntilStarted();
    {
        // Verify concurrent build
        Build secondBuild = job.scheduleBuild().waitUntilStarted();
        assertTrue(build.isInProgress());
        assertTrue(secondBuild.isInProgress());
        build.stop();
        secondBuild.stop();
        build.waitUntilFinished();
        secondBuild.waitUntilFinished();
    }
    build.open();
    assertThat(build.getDisplayName(), containsString("custom-name"));
    build.open();
    driver.findElement(By.partialLinkText("Environment Variables")).click();
    assertThat(driver, hasElement(by.xpath(String.format("//tr/td[contains(text(), '%s')]", "varname"))));
    assertThat(build.getConsole(), containsString("/tmp/custom-workspace"));
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Job(org.jenkinsci.test.acceptance.po.Job) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) WebElement(org.openqa.selenium.WebElement) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Aggregations

Job (org.jenkinsci.test.acceptance.po.Job)55 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)48 Test (org.junit.Test)45 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)42 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)37 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)22 ListView (org.jenkinsci.test.acceptance.po.ListView)21 View (org.jenkinsci.test.acceptance.po.View)18 Build (org.jenkinsci.test.acceptance.po.Build)13 WebElement (org.openqa.selenium.WebElement)7 IOException (java.io.IOException)5 GerritTriggerJob (org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerJob)5 GerritTriggerNewServer (org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerNewServer)5 GerritTriggerServer (org.jenkinsci.test.acceptance.plugins.gerrit_trigger.GerritTriggerServer)5 GitScm (org.jenkinsci.test.acceptance.plugins.git.GitScm)5 Since (org.jenkinsci.test.acceptance.junit.Since)4 AnalysisAction (org.jenkinsci.test.acceptance.plugins.analysis_core.AnalysisAction)4 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)4 Issue (org.jvnet.hudson.test.Issue)4 Arrays (java.util.Arrays)3