|
| 1 | +package org.jvnet.hudson.plugins.port_allocator; |
| 2 | + |
| 3 | +import hudson.model.Label; |
| 4 | +import hudson.model.Node; |
| 5 | +import hudson.model.Result; |
| 6 | +import hudson.model.queue.QueueTaskFuture; |
| 7 | +import hudson.slaves.DumbSlave; |
| 8 | +import hudson.slaves.NodeProperty; |
| 9 | +import hudson.slaves.RetentionStrategy; |
| 10 | +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; |
| 11 | +import org.jenkinsci.plugins.workflow.job.WorkflowJob; |
| 12 | +import org.jenkinsci.plugins.workflow.job.WorkflowRun; |
| 13 | +import org.junit.Before; |
| 14 | +import org.junit.FixMethodOrder; |
| 15 | +import org.junit.Rule; |
| 16 | +import org.junit.Test; |
| 17 | +import org.junit.rules.TemporaryFolder; |
| 18 | +import org.junit.runners.MethodSorters; |
| 19 | +import org.jvnet.hudson.test.JenkinsRule; |
| 20 | +import org.jvnet.hudson.test.RestartableJenkinsRule; |
| 21 | + |
| 22 | +import java.util.Collections; |
| 23 | +import java.util.List; |
| 24 | + |
| 25 | +@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 26 | +public class PortAllocationWorkflowTest { |
| 27 | + |
| 28 | + @Rule |
| 29 | + public JenkinsRule j = new JenkinsRule(); |
| 30 | + |
| 31 | + @Rule |
| 32 | + public TemporaryFolder tmp = new TemporaryFolder(); |
| 33 | + |
| 34 | + @Test |
| 35 | + public void wrap_01_WithNonExistingPool() throws Exception { |
| 36 | + j.jenkins.addNode(new DumbSlave("slave", "dummy", |
| 37 | + tmp.newFolder("remoteFS").getPath(), "1", Node.Mode.NORMAL, "", |
| 38 | + j.createComputerLauncher(null), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList())); |
| 39 | + WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); |
| 40 | + p.setDefinition(new CpsFlowDefinition( |
| 41 | + "node('slave') {\n" |
| 42 | + + " wrap([$class: 'PortAllocator', pool: 'WEBLOGIC']) {\n" |
| 43 | + + " }\n" |
| 44 | + + "}" |
| 45 | + )); |
| 46 | + j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void wrap_02_WithExistingPool() throws Exception { |
| 51 | + j.jenkins.addNode(new DumbSlave("slave", "dummy", |
| 52 | + tmp.newFolder("remoteFS").getPath(), "1", Node.Mode.NORMAL, "", |
| 53 | + j.createComputerLauncher(null), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList())); |
| 54 | + PortAllocator.DescriptorImpl desc = j.jenkins.getDescriptorByType(PortAllocator.DescriptorImpl.class); |
| 55 | + Pool weblogic = new Pool(); |
| 56 | + weblogic.name = "WEBLOGIC"; |
| 57 | + weblogic.ports = "7001,8001"; |
| 58 | + desc.getPools().add(weblogic); |
| 59 | + WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); |
| 60 | + p.setDefinition(new CpsFlowDefinition( |
| 61 | + "node('slave') {\n" |
| 62 | + + " wrap([$class: 'PortAllocator', pool: 'WEBLOGIC']) {\n" |
| 63 | + + " }\n" |
| 64 | + + "}" |
| 65 | + )); |
| 66 | + j.assertBuildStatusSuccess(p.scheduleBuild2(0)); |
| 67 | + } |
| 68 | +} |
0 commit comments