Search in sources :

Example 1 with CLICommandInvoker

use of hudson.cli.CLICommandInvoker in project workflow-job-plugin by jenkinsci.

the class CLITest method reload.

@Issue("JENKINS-30785")
@Test
public void reload() throws Exception {
    WorkflowJob p = r.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("echo 'first version'", true));
    r.assertLogContains("first version", r.buildAndAssertSuccess(p));
    File configXml = new File(p.getRootDir(), "config.xml");
    FileUtils.write(configXml, FileUtils.readFileToString(configXml).replace("first version", "second version"));
    assertThat(new CLICommandInvoker(r, "reload-job").invokeWithArgs("p"), CLICommandInvoker.Matcher.succeededSilently());
    r.assertLogContains("second version", r.buildAndAssertSuccess(p));
    CLICommandInvoker.Result res = new CLICommandInvoker(r, "reload-job").invokeWithArgs("q");
    assertThat(res, CLICommandInvoker.Matcher.failedWith(3));
    assertThat(res.stderr(), containsString("No such item ā€˜qā€™ exists. Perhaps you meant ā€˜pā€™?"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CLICommandInvoker(hudson.cli.CLICommandInvoker) File(java.io.File) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 2 with CLICommandInvoker

use of hudson.cli.CLICommandInvoker in project workflow-job-plugin by jenkinsci.

the class CLITest method setBuildDescriptionAndDisplayName.

@Test
public void setBuildDescriptionAndDisplayName() throws Exception {
    WorkflowJob p = r.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("", true));
    WorkflowRun b = r.buildAndAssertSuccess(p);
    assertThat(new CLICommandInvoker(r, "set-build-description").invokeWithArgs("p", "1", "the desc"), CLICommandInvoker.Matcher.succeededSilently());
    assertEquals("the desc", b.getDescription());
    assertThat(new CLICommandInvoker(r, "set-build-display-name").invokeWithArgs("p", "1", "the name"), CLICommandInvoker.Matcher.succeededSilently());
    assertEquals("the name", b.getDisplayName());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CLICommandInvoker(hudson.cli.CLICommandInvoker) Test(org.junit.Test)

Example 3 with CLICommandInvoker

use of hudson.cli.CLICommandInvoker in project workflow-job-plugin by jenkinsci.

the class CLITest method listChanges.

@Test
public void listChanges() throws Exception {
    WorkflowJob p = r.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("node {def s = new org.jvnet.hudson.test.FakeChangeLogSCM(); s.addChange().withAuthor('alice').withMsg('hello'); checkout s}", false));
    r.buildAndAssertSuccess(p);
    CLICommandInvoker.Result res = new CLICommandInvoker(r, "list-changes").invokeWithArgs("p", "1");
    assertThat(res, CLICommandInvoker.Matcher.succeeded());
    assertThat(res.stdout(), containsString("alice\thello"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CLICommandInvoker(hudson.cli.CLICommandInvoker) Test(org.junit.Test)

Example 4 with CLICommandInvoker

use of hudson.cli.CLICommandInvoker in project workflow-job-plugin by jenkinsci.

the class WorkflowJobTest method disabled.

@Issue("JENKINS-27299")
@Test
public void disabled() throws Exception {
    WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
    assertFalse(p.isDisabled());
    assertTrue(p.isBuildable());
    JenkinsRule.WebClient wc = j.createWebClient();
    j.submit(wc.getPage(p).<HtmlForm>getHtmlElementById("disable-project"));
    assertTrue(p.isDisabled());
    assertFalse(p.isBuildable());
    HtmlForm form = wc.getPage(p, "configure").getFormByName("config");
    HtmlCheckBoxInput checkbox = form.getInputByName("disable");
    assertTrue(checkbox.isChecked());
    checkbox.setChecked(false);
    j.submit(form);
    assertFalse(p.isDisabled());
    wc.getPage(new WebRequest(wc.createCrumbedUrl(p.getUrl() + "disable"), HttpMethod.POST));
    assertTrue(p.isDisabled());
    assertNull(p.scheduleBuild2(0));
    assertThat(new CLICommandInvoker(j, "enable-job").invokeWithArgs("p"), CLICommandInvoker.Matcher.succeededSilently());
    assertFalse(p.isDisabled());
}
Also used : HtmlCheckBoxInput(com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) CLICommandInvoker(hudson.cli.CLICommandInvoker) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 5 with CLICommandInvoker

use of hudson.cli.CLICommandInvoker in project workflow-job-plugin by jenkinsci.

the class CLITest method deleteBuilds.

@Test
public void deleteBuilds() throws Exception {
    WorkflowJob p = r.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("", true));
    for (int i = 0; i < 5; i++) {
        r.buildAndAssertSuccess(p);
    }
    assertThat(new CLICommandInvoker(r, "delete-builds").invokeWithArgs("p", "2-4"), CLICommandInvoker.Matcher.succeeded());
    assertEquals("[5, 1]", p.getBuildsAsMap().keySet().toString());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CLICommandInvoker(hudson.cli.CLICommandInvoker) Test(org.junit.Test)

Aggregations

CLICommandInvoker (hudson.cli.CLICommandInvoker)6 Test (org.junit.Test)6 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)5 Issue (org.jvnet.hudson.test.Issue)3 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)1 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)1 File (java.io.File)1 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)1