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"));
}
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"));
}
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"));
}
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();
}
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"));
}
Aggregations