Skip to content

Commit

Permalink
[JENKINS-23614] Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Jan 11, 2015
1 parent 9ea857b commit 8600edd
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions src/test/java/hudson/matrix/AxisTest.java
Expand Up @@ -61,17 +61,39 @@ public void submitEmptyAxisName() throws Exception {
wc.setThrowExceptionOnFailingStatusCode(false);

final String expectedMsg = "Matrix axis name '' is invalid: Axis name can not be empty";
assertFailedWith(emptyName("User-defined Axis"), expectedMsg);
assertFailedWith(emptyName("Slaves"), expectedMsg);
assertFailedWith(emptyName("Label expression"), expectedMsg);
//assertFailedWith(emptyName("JDK"), expectedMsg); // No "name" attribute
assertFailedWith(expectedMsg, withName("", "User-defined Axis"));
assertFailedWith(expectedMsg, withName("", "Slaves"));
assertFailedWith(expectedMsg, withName("", "Label expression"));
}

private HtmlPage emptyName(String axis) throws Exception {
HtmlForm form = addAxis(axis);
form.getInputByName("_.name").setValueAttribute("");
HtmlPage ret = j.submit(form);
return ret;
@Test
public void submitInvalidAxisName() throws Exception {
wc.setThrowExceptionOnFailingStatusCode(false);

String expectedMsg = "Matrix axis name 'a,b' is invalid: ‘,’ is an unsafe character";
assertFailedWith(expectedMsg, withName("a,b", "User-defined Axis"));
assertFailedWith(expectedMsg, withName("a,b", "Slaves"));
assertFailedWith(expectedMsg, withName("a,b", "Label expression"));

expectedMsg = "Matrix axis name 'a=b' is invalid: ‘=’ is an unsafe character";
assertFailedWith(expectedMsg, withName("a=b", "User-defined Axis"));
assertFailedWith(expectedMsg, withName("a=b", "Slaves"));
assertFailedWith(expectedMsg, withName("a=b", "Label expression"));
}

@Test
public void submitInvalidAxisValue() throws Exception {
wc.setThrowExceptionOnFailingStatusCode(false);

HtmlForm form = addAxis("User-defined Axis");
form.getInputByName("_.name").setValueAttribute("a_name");
form.getInputByName("_.valueString").setValueAttribute("a,b");
assertFailedWith("Matrix axis value 'a,b' is invalid: ‘,’ is an unsafe character", j.submit(form));

form = addAxis("Label expression");
form.getInputByName("_.name").setValueAttribute("a_name");
form.getElementsByAttribute("textarea", "name", "values").get(0).setTextContent("a,b");
assertFailedWith("Matrix axis value 'a,b' is invalid: ‘,’ is an unsafe character", j.submit(form));
}

@Test
Expand All @@ -86,6 +108,13 @@ public void emptyAxisValueListResultInNoConfigurations() throws Exception {
assertThat(p.getItems(), new IsEmptyCollection<MatrixConfiguration>());
}

private HtmlPage withName(String value, String axis) throws Exception {
HtmlForm form = addAxis(axis);
form.getInputByName("_.name").setValueAttribute(value);
HtmlPage ret = j.submit(form);
return ret;
}

private HtmlPage emptyValue(String axis) throws Exception {
HtmlForm form = addAxis(axis);
if (!"JDK".equals(axis)) { // No "name" attribute
Expand All @@ -96,7 +125,7 @@ private HtmlPage emptyValue(String axis) throws Exception {
return ret;
}

private void assertFailedWith(HtmlPage res, String expected) {
private void assertFailedWith(String expected, HtmlPage res) {
String actual = res.getWebResponse().getContentAsString();

assertThat(actual, res.getWebResponse().getStatusCode(), equalTo(400));
Expand Down

0 comments on commit 8600edd

Please sign in to comment.