-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Test Coverage of NodeLabelParameter
- Loading branch information
1 parent
e98e630
commit f3064b9
Showing
6 changed files
with
302 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...va/org/jvnet/jenkins/plugins/nodelabelparameter/IgnoreTempOfflineNodeEligibilityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.jvnet.jenkins.plugins.nodelabelparameter; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import hudson.DescriptorExtensionList; | ||
import hudson.model.Node; | ||
import hudson.model.labels.LabelAtom; | ||
import hudson.slaves.DumbSlave; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.jenkins.plugins.nodelabelparameter.node.IgnoreTempOfflineNodeEligibility; | ||
import org.jvnet.jenkins.plugins.nodelabelparameter.node.NodeEligibility; | ||
import org.jvnet.jenkins.plugins.nodelabelparameter.node.NodeEligibility.NodeEligibilityDescriptor; | ||
|
||
public class IgnoreTempOfflineNodeEligibilityTest { | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
private DumbSlave onlineNode1; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
onlineNode1 = j.createOnlineSlave(new LabelAtom("label")); | ||
} | ||
|
||
IgnoreTempOfflineNodeEligibility ignoreTempOfflineNodeEligibility = new IgnoreTempOfflineNodeEligibility(); | ||
|
||
@Test | ||
public void testGetComputer() throws Exception { | ||
Node node = null; | ||
// Node is null | ||
assertFalse(ignoreTempOfflineNodeEligibility.isEligible(node)); | ||
// Node is not null | ||
assertFalse(ignoreTempOfflineNodeEligibility.isEligible(onlineNode1.getLabelString())); | ||
// Node is null and nodeName is empty | ||
assertTrue(ignoreTempOfflineNodeEligibility.isEligible("")); | ||
} | ||
|
||
@Test | ||
public void testGetDescriptor() { | ||
NodeEligibilityDescriptor descriptor = ignoreTempOfflineNodeEligibility.getDescriptor(); | ||
// Check if descriptor is not null | ||
assertNotNull(descriptor); | ||
// Check if descriptor is an instance of NodeEligibilityDescriptor | ||
assertTrue(descriptor instanceof NodeEligibilityDescriptor); | ||
} | ||
|
||
@Test | ||
public void testAll() { | ||
DescriptorExtensionList<NodeEligibility, NodeEligibilityDescriptor> descriptors = NodeEligibility.all(); | ||
// Check if descriptors is not empty | ||
assertTrue(!descriptors.isEmpty()); | ||
// Check if descriptors is not null | ||
assertNotNull(descriptors); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/LabelParameterDefinitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.jvnet.jenkins.plugins.nodelabelparameter; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import hudson.model.labels.LabelAtom; | ||
import hudson.slaves.DumbSlave; | ||
import hudson.util.FormValidation; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class LabelParameterDefinitionTest { | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
final DumbSlave node = j.createOnlineSlave(new LabelAtom("node")); | ||
} | ||
|
||
@Test | ||
public void testNodeParameterDefinition() { | ||
String name = "name"; | ||
String description = "description"; | ||
String defaultValue = "defaultValue"; | ||
List<String> defaultSlaves = new ArrayList<>(); | ||
List<String> allowedSlaves = new ArrayList<>(); | ||
allowedSlaves.add("defaultValue"); | ||
String triggerIfResult = "triggerIfResult"; | ||
|
||
LabelParameterDefinition nodeParameterDefinition1 = | ||
new LabelParameterDefinition(name, description, defaultValue, true, true, triggerIfResult); | ||
|
||
assertEquals(nodeParameterDefinition1.defaultValue, defaultValue); | ||
|
||
LabelParameterDefinition nodeParameterDefinition2 = | ||
new LabelParameterDefinition(name, description, defaultValue, true, null, triggerIfResult); | ||
|
||
assertEquals(nodeParameterDefinition1.defaultValue, defaultValue); | ||
} | ||
|
||
@Test | ||
public void testDoListNodesForLabel() throws Exception { | ||
LabelParameterDefinition.DescriptorImpl nodeParameterDefinition = new LabelParameterDefinition.DescriptorImpl(); | ||
|
||
String label = "node"; | ||
|
||
FormValidation validation = nodeParameterDefinition.doListNodesForLabel(label); | ||
|
||
assertNotNull(validation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/NextLabelCauseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// package org.jvnet.jenkins.plugins.nodelabelparameter; | ||
// | ||
// import nl.jqno.equalsverifier.EqualsVerifier; | ||
// import nl.jqno.equalsverifier.Warning; | ||
// import org.junit.Test; | ||
// | ||
// public class NextLabelCauseTest { | ||
// @Test | ||
// public void equalsContract() { | ||
// EqualsVerifier.forClass(NextLabelCause.class) | ||
// .usingGetClass() | ||
// .suppress(Warning.NONFINAL_FIELDS) | ||
// .withIgnoredFields() | ||
// .verify(); | ||
// } | ||
// } |
152 changes: 152 additions & 0 deletions
152
src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/NodeParameterDefinitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package org.jvnet.jenkins.plugins.nodelabelparameter; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import hudson.model.labels.LabelAtom; | ||
import hudson.slaves.DumbSlave; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.jenkins.plugins.nodelabelparameter.node.AllNodeEligibility; | ||
|
||
public class NodeParameterDefinitionTest { | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
final DumbSlave node = j.createOnlineSlave(new LabelAtom("node")); | ||
} | ||
|
||
@Test | ||
public void testReadResolve_DefaultValueIsNotNull() { | ||
String name = "name"; | ||
String description = "description"; | ||
List<String> defaultSlaves1 = new ArrayList<>(); | ||
List<String> allowedSlaves = new ArrayList<>(); | ||
String triggerIfResult = "triggerIfResult"; | ||
|
||
// deaultValue is not null and defaultSlaves is not null | ||
|
||
NodeParameterDefinition nodeParameterDefinition1 = new NodeParameterDefinition( | ||
name, description, defaultSlaves1, allowedSlaves, triggerIfResult, new AllNodeEligibility()); | ||
|
||
nodeParameterDefinition1.defaultValue = "defaultValue"; | ||
|
||
assertNotNull(nodeParameterDefinition1.readResolve()); | ||
assertEquals( | ||
nodeParameterDefinition1.getClass(), | ||
nodeParameterDefinition1.readResolve().getClass()); | ||
|
||
// deaultValue is not null and defaultSlaves is null | ||
|
||
List<String> defaultSlaves2 = null; | ||
NodeParameterDefinition nodeParameterDefinition2 = new NodeParameterDefinition( | ||
name, description, defaultSlaves2, allowedSlaves, triggerIfResult, new AllNodeEligibility()); | ||
|
||
nodeParameterDefinition2.defaultValue = "defaultValue"; | ||
|
||
assertNotNull(nodeParameterDefinition2.readResolve()); | ||
assertEquals( | ||
nodeParameterDefinition2.getClass(), | ||
nodeParameterDefinition2.readResolve().getClass()); | ||
} | ||
|
||
@Test | ||
public void testReadResolve_NodeEligibilityIsNull() { | ||
String name = "name"; | ||
String description = "description"; | ||
List<String> defaultSlaves = null; | ||
List<String> allowedSlaves = new ArrayList<>(); | ||
String triggerIfResult = "triggerIfResult"; | ||
|
||
NodeParameterDefinition nodeParameterDefinition1 = | ||
new NodeParameterDefinition(name, description, defaultSlaves, allowedSlaves, triggerIfResult, true); | ||
|
||
nodeParameterDefinition1.defaultValue = null; | ||
|
||
assertNotNull(nodeParameterDefinition1.readResolve()); | ||
|
||
NodeParameterDefinition nodeParameterDefinition2 = | ||
new NodeParameterDefinition(name, description, defaultSlaves, allowedSlaves, triggerIfResult, false); | ||
|
||
nodeParameterDefinition2.defaultValue = null; | ||
|
||
assertNotNull(nodeParameterDefinition2.readResolve()); | ||
} | ||
|
||
@Test | ||
public void testNodeParameterDefinition() { | ||
String name = "name"; | ||
String description = "description"; | ||
List<String> defaultSlaves = new ArrayList<>(); | ||
List<String> allowedSlaves = new ArrayList<>(); | ||
allowedSlaves.add("defaultValue"); | ||
String triggerIfResult = "triggerIfResult"; | ||
|
||
NodeParameterDefinition nodeParameterDefinition1 = | ||
new NodeParameterDefinition(name, description, "defaultValue", allowedSlaves, triggerIfResult); | ||
|
||
assertTrue(allowedSlaves.contains("defaultValue")); | ||
|
||
NodeParameterDefinition nodeParameterDefinition2 = new NodeParameterDefinition( | ||
name, description, defaultSlaves, allowedSlaves, triggerIfResult, new AllNodeEligibility()); | ||
|
||
assertNotNull(nodeParameterDefinition2); | ||
} | ||
|
||
@Test | ||
public void testCreateValue_String() { | ||
String name = "name"; | ||
String description = "description"; | ||
List<String> defaultSlaves = new ArrayList<>(); | ||
List<String> allowedSlaves = new ArrayList<>(); | ||
allowedSlaves.add("defaultValue"); | ||
String triggerIfResult = "triggerIfResult"; | ||
|
||
NodeParameterDefinition nodeParameterDefinition = new NodeParameterDefinition( | ||
name, description, defaultSlaves, allowedSlaves, triggerIfResult, new AllNodeEligibility()); | ||
|
||
assertNotNull(nodeParameterDefinition.createValue("value")); | ||
} | ||
|
||
@Test | ||
public void testGetAllowedNodesOrAll() { | ||
String name = "name"; | ||
String description = "description"; | ||
List<String> defaultSlaves = new ArrayList<>(); | ||
List<String> allowedSlaves = new ArrayList<>(); | ||
allowedSlaves.add("node"); | ||
String triggerIfResult = "triggerIfResult"; | ||
|
||
NodeParameterDefinition nodeParameterDefinition1 = new NodeParameterDefinition( | ||
name, description, defaultSlaves, allowedSlaves, triggerIfResult, new AllNodeEligibility()); | ||
|
||
assertEquals(allowedSlaves, nodeParameterDefinition1.getAllowedNodesOrAll()); | ||
|
||
allowedSlaves = new ArrayList<>(); | ||
allowedSlaves.add("master"); | ||
|
||
NodeParameterDefinition nodeParameterDefinition2 = new NodeParameterDefinition( | ||
name, description, defaultSlaves, allowedSlaves, triggerIfResult, new AllNodeEligibility()); | ||
|
||
assertEquals(allowedSlaves, nodeParameterDefinition2.getAllowedNodesOrAll()); | ||
} | ||
|
||
@Test | ||
public void testGetHelpFile() { | ||
NodeParameterDefinition.DescriptorImpl descriptorImpl = new NodeParameterDefinition.DescriptorImpl(); | ||
|
||
assertEquals(descriptorImpl.getHelpFile(), "/plugin/nodelabelparameter/nodeparam.html"); | ||
} | ||
|
||
@Test | ||
public void testGetDefaultNodeEligibility() { | ||
NodeParameterDefinition.DescriptorImpl descriptorImpl = new NodeParameterDefinition.DescriptorImpl(); | ||
|
||
assertNotNull(descriptorImpl.getDefaultNodeEligibility()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters