diff --git a/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterDefinitionTest.java b/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterDefinitionTest.java index 5f9c92d..dbf3b64 100644 --- a/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterDefinitionTest.java +++ b/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterDefinitionTest.java @@ -3,6 +3,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -14,6 +15,8 @@ import org.junit.ClassRule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.jenkins.plugins.nodelabelparameter.node.AllNodeEligibility; +import org.jvnet.jenkins.plugins.nodelabelparameter.node.IgnoreOfflineNodeEligibility; public class LabelParameterDefinitionTest { @@ -46,6 +49,7 @@ public void testNodeParameterDefinitionDeprecated() { assertThat(nodeParameterDefinition.getDescription(), is(description)); assertThat(nodeParameterDefinition.getDefaultParameterValue().getLabel(), is(defaultValue)); assertThat(nodeParameterDefinition.getTriggerIfResult(), is(triggerIfResult)); + assertThat(nodeParameterDefinition.getNodeEligibility(), is(instanceOf(IgnoreOfflineNodeEligibility.class))); assertTrue(nodeParameterDefinition.isAllNodesMatchingLabel()); } @@ -64,6 +68,7 @@ public void testNodeParameterDefinitionDeprecated3Arg() { assertThat(nodeParameterDefinition.getDescription(), is(description)); assertThat(nodeParameterDefinition.getDefaultParameterValue().getLabel(), is(defaultValue)); assertThat(nodeParameterDefinition.getTriggerIfResult(), is("allCases")); + assertThat(nodeParameterDefinition.getNodeEligibility(), is(instanceOf(AllNodeEligibility.class))); assertFalse(nodeParameterDefinition.isAllNodesMatchingLabel()); } @@ -82,12 +87,14 @@ public void testNodeParameterDefinition() { assertThat(nodeParameterDefinition.getDescription(), is(description)); assertThat(nodeParameterDefinition.getDefaultParameterValue().getLabel(), is(defaultValue)); assertThat(nodeParameterDefinition.getTriggerIfResult(), is(triggerIfResult)); + assertThat(nodeParameterDefinition.getNodeEligibility(), is(instanceOf(AllNodeEligibility.class))); assertFalse(nodeParameterDefinition.isAllNodesMatchingLabel()); } @Test public void testDoListNodesForAgentLabel() throws Exception { LabelParameterDefinition.DescriptorImpl nodeParameterDefinition = new LabelParameterDefinition.DescriptorImpl(); + assertThat(nodeParameterDefinition.getDefaultNodeEligibility(), is(instanceOf(AllNodeEligibility.class))); FormValidation validation = nodeParameterDefinition.doListNodesForLabel(LABEL_NAME); String msg = validation.getMessage(); assertThat(msg, allOf(containsString("Matching nodes"), containsString(agent.getNodeName()))); @@ -97,6 +104,7 @@ public void testDoListNodesForAgentLabel() throws Exception { public void testDoListNodesForControllerLabel() throws Exception { String controllerLabel = "built-in"; LabelParameterDefinition.DescriptorImpl nodeParameterDefinition = new LabelParameterDefinition.DescriptorImpl(); + assertThat(nodeParameterDefinition.getDefaultNodeEligibility(), is(instanceOf(AllNodeEligibility.class))); FormValidation validation = nodeParameterDefinition.doListNodesForLabel(controllerLabel); String msg = validation.getMessage(); assertThat(msg, allOf(containsString("Matching nodes"), containsString(controllerLabel))); @@ -106,8 +114,33 @@ public void testDoListNodesForControllerLabel() throws Exception { public void testDoListNodesForNonExistentLabel() throws Exception { String badLabel = "this-label-does-not-exist"; LabelParameterDefinition.DescriptorImpl nodeParameterDefinition = new LabelParameterDefinition.DescriptorImpl(); + assertThat(nodeParameterDefinition.getDefaultNodeEligibility(), is(instanceOf(AllNodeEligibility.class))); FormValidation validation = nodeParameterDefinition.doListNodesForLabel(badLabel); String msg = validation.getMessage(); assertThat(msg, allOf(containsString("The label expression"), containsString(badLabel))); } + + @Test + public void testDoListNodesForBlankLabel() throws Exception { + String blankLabel = ""; + LabelParameterDefinition.DescriptorImpl nodeParameterDefinition = new LabelParameterDefinition.DescriptorImpl(); + FormValidation validation = nodeParameterDefinition.doListNodesForLabel(blankLabel); + String msg = validation.getMessage(); + assertThat(msg, containsString("a label is required")); + } + + @Test + public void testDoListNodesForInvalidLabelExpression() throws Exception { + String invalidLabel = "a||"; + LabelParameterDefinition.DescriptorImpl nodeParameterDefinition = new LabelParameterDefinition.DescriptorImpl(); + assertThat(nodeParameterDefinition.getDefaultNodeEligibility(), is(instanceOf(AllNodeEligibility.class))); + FormValidation validation = nodeParameterDefinition.doListNodesForLabel(invalidLabel); + String msg = validation.getMessage(); + assertThat( + msg, + allOf( + containsString("The label expression"), + containsString(invalidLabel), + containsString("is not valid"))); + } }