Search in sources :

Example 11 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class ParametersTest method mixedSensitivity.

@Test
public void mixedSensitivity() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdb = new ParametersDefinitionProperty(new StringParameterDefinition("string", "defaultValue", "string description"), new PasswordParameterDefinition("password", "12345", "password description"), new StringParameterDefinition("string2", "Value2", "string description"));
    project.addProperty(pdb);
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);
    FreeStyleBuild build = j.buildAndAssertSuccess(project);
    Set<String> sensitiveVars = build.getSensitiveBuildVariables();
    assertNotNull(sensitiveVars);
    assertFalse(sensitiveVars.contains("string"));
    assertTrue(sensitiveVars.contains("password"));
    assertFalse(sensitiveVars.contains("string2"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Example 12 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class ParametersTest method parameterTypes.

@Test
public void parameterTypes() throws Exception {
    FreeStyleProject otherProject = j.createFreeStyleProject();
    j.buildAndAssertSuccess(otherProject);
    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(new StringParameterDefinition("string", "defaultValue", "string description"), new BooleanParameterDefinition("boolean", true, "boolean description"), new ChoiceParameterDefinition("choice", "Choice 1\nChoice 2", "choice description"), new RunParameterDefinition("run", otherProject.getName(), "run description", null));
    project.addProperty(pdp);
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);
    WebClient wc = j.createWebClient().withThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec");
    HtmlForm form = page.getFormByName("parameters");
    HtmlElement element = (HtmlElement) ((HtmlElement) DomNodeUtil.selectSingleNode(form, "//div[input/@value='string']")).getParentNode();
    assertNotNull(element);
    assertEquals("string description", element.getParentNode().querySelector(".jenkins-form-description").getTextContent());
    HtmlTextInput stringParameterInput = DomNodeUtil.selectSingleNode(element, ".//input[@name='value']");
    assertEquals("defaultValue", stringParameterInput.getAttribute("value"));
    assertEquals("string", ((HtmlElement) DomNodeUtil.selectSingleNode(element.getParentNode(), "div[contains(@class, 'jenkins-form-label')]")).getTextContent());
    stringParameterInput.setAttribute("value", "newValue");
    element = DomNodeUtil.selectSingleNode(form, "//div[input/@value='boolean']");
    assertNotNull(element);
    assertEquals("boolean description", element.getParentNode().getParentNode().querySelector(".jenkins-form-description").getTextContent());
    Object o = DomNodeUtil.selectSingleNode(element, ".//input[@name='value']");
    HtmlCheckBoxInput booleanParameterInput = (HtmlCheckBoxInput) o;
    assertTrue(booleanParameterInput.isChecked());
    assertEquals("boolean", element.getTextContent());
    element = (HtmlElement) ((HtmlElement) DomNodeUtil.selectSingleNode(form, ".//div[input/@value='choice']")).getParentNode();
    assertNotNull(element);
    assertEquals("choice description", element.getParentNode().querySelector(".jenkins-form-description").getTextContent());
    assertEquals("choice", ((HtmlElement) DomNodeUtil.selectSingleNode(element.getParentNode(), "div[contains(@class, 'jenkins-form-label')]")).getTextContent());
    element = (HtmlElement) ((HtmlElement) DomNodeUtil.selectSingleNode(form, ".//div[input/@value='run']")).getParentNode();
    assertNotNull(element);
    assertEquals("run description", element.getParentNode().querySelector(".jenkins-form-description").getTextContent());
    assertEquals("run", ((HtmlElement) DomNodeUtil.selectSingleNode(element.getParentNode(), "div[contains(@class, 'jenkins-form-label')]")).getTextContent());
    j.submit(form);
    j.waitUntilNoActivity();
    assertEquals("newValue", builder.getEnvVars().get("STRING"));
    assertEquals("true", builder.getEnvVars().get("BOOLEAN"));
    assertEquals("Choice 1", builder.getEnvVars().get("CHOICE"));
    assertEquals(j.jenkins.getRootUrl() + otherProject.getLastBuild().getUrl(), builder.getEnvVars().get("RUN"));
}
Also used : HtmlTextInput(com.gargoylesoftware.htmlunit.html.HtmlTextInput) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) HtmlCheckBoxInput(com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Example 13 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class ParametersTest method choiceWithLTGT.

@Test
public void choiceWithLTGT() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(new ChoiceParameterDefinition("choice", "Choice 1\nChoice <2>", "choice description"));
    project.addProperty(pdp);
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);
    WebClient wc = j.createWebClient().withThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec");
    HtmlForm form = page.getFormByName("parameters");
    HtmlElement element = (HtmlElement) (form.getElementsByAttribute("input", "name", "name")).get(0).getParentNode();
    assertNotNull(element);
    assertEquals("choice description", ((HtmlElement) DomNodeUtil.selectSingleNode(form, "//div[contains(@class, 'jenkins-form-description')]")).getTextContent());
    assertEquals("choice", ((HtmlElement) DomNodeUtil.selectSingleNode(form, "//div[contains(@class, 'jenkins-form-label')]")).getTextContent());
    HtmlSelect choiceSelect = (HtmlSelect) form.getElementsByAttribute("select", "name", "value").get(0);
    HtmlOption opt = DomNodeUtil.selectSingleNode(choiceSelect, "option[@value='Choice <2>']");
    assertNotNull(opt);
    assertEquals("Choice <2>", opt.asNormalizedText());
    opt.setSelected(true);
    j.submit(form);
    j.waitUntilNoActivity();
    assertNotNull(builder.getEnvVars());
    assertEquals("Choice <2>", builder.getEnvVars().get("CHOICE"));
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlSelect(com.gargoylesoftware.htmlunit.html.HtmlSelect) HtmlOption(com.gargoylesoftware.htmlunit.html.HtmlOption) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) Test(org.junit.Test)

Example 14 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class EnvironmentVariableNodePropertyTest method executeBuild.

/**
 * Launches project on this node, waits for the result, and returns the environment that is used
 */
private Map<String, String> executeBuild(Node node) throws Exception {
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);
    project.setAssignedLabel(node.getSelfLabel());
    FreeStyleBuild build = j.buildAndAssertSuccess(project);
    return builder.getEnvVars();
}
Also used : FreeStyleBuild(hudson.model.FreeStyleBuild) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder)

Example 15 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class AbstractBuildTest method variablesResolved.

@Test
public void variablesResolved() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    j.jenkins.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("KEY1", "value"), new EnvironmentVariablesNodeProperty.Entry("KEY2", "$KEY1")));
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);
    j.buildAndAssertSuccess(project);
    EnvVars envVars = builder.getEnvVars();
    assertEquals("value", envVars.get("KEY1"));
    assertEquals("value", envVars.get("KEY2"));
}
Also used : EnvVars(hudson.EnvVars) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) EnvironmentVariablesNodeProperty(hudson.slaves.EnvironmentVariablesNodeProperty) Test(org.junit.Test) LogRotatorTest(hudson.tasks.LogRotatorTest)

Aggregations

CaptureEnvironmentBuilder (org.jvnet.hudson.test.CaptureEnvironmentBuilder)19 Test (org.junit.Test)17 FreeStyleProject (hudson.model.FreeStyleProject)5 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)3 UserCause (hudson.model.Cause.UserCause)3 FreeStyleBuild (hudson.model.FreeStyleBuild)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Issue (org.jvnet.hudson.test.Issue)3 WebClient (org.jvnet.hudson.test.JenkinsRule.WebClient)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)2 FileWriteBuilder (hudson.plugins.copyartifact.testutils.FileWriteBuilder)2 ArtifactArchiver (hudson.tasks.ArtifactArchiver)2 WebClientOptions (com.gargoylesoftware.htmlunit.WebClientOptions)1 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)1 HtmlOption (com.gargoylesoftware.htmlunit.html.HtmlOption)1 HtmlSelect (com.gargoylesoftware.htmlunit.html.HtmlSelect)1 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)1