PageRenderTime 4300ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/rest-api/src/test/java/com/cloudbees/workflow/rest/endpoints/UndefinedWorkflowTest.java

https://gitlab.com/CORP-RESELLER/pipeline-stage-view-plugin
Java | 72 lines | 35 code | 10 blank | 27 comment | 0 complexity | b56627056c22ef57e5db8405717eab14 MD5 | raw file
  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2013-2016, CloudBees, Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package com.cloudbees.workflow.rest.endpoints;
  25. import com.cloudbees.workflow.Util;
  26. import com.cloudbees.workflow.rest.external.RunExt;
  27. import com.cloudbees.workflow.rest.external.StatusExt;
  28. import hudson.model.queue.QueueTaskFuture;
  29. import org.jenkinsci.plugins.workflow.job.WorkflowJob;
  30. import org.jenkinsci.plugins.workflow.job.WorkflowRun;
  31. import org.junit.Assert;
  32. import org.junit.Rule;
  33. import org.junit.Test;
  34. import org.jvnet.hudson.test.JenkinsRule;
  35. /**
  36. * @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
  37. */
  38. public class UndefinedWorkflowTest {
  39. @Rule
  40. public JenkinsRule jenkinsRule = new JenkinsRule();
  41. @Test
  42. public void test_success_flow() throws Exception {
  43. WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Noddy Job");
  44. // Purposely not setting a workflow definition on the job
  45. QueueTaskFuture<WorkflowRun> build = job.scheduleBuild2(0);
  46. build.waitForStart();
  47. String jobRunsUrl = job.getUrl() + "wfapi/runs/";
  48. RunExt[] workflowRuns = Util.getJSON(jobRunsUrl, RunExt[].class, jenkinsRule);
  49. Assert.assertEquals(1, workflowRuns.length);
  50. Assert.assertNotNull(workflowRuns[0].getId());
  51. Assert.assertEquals(StatusExt.NOT_EXECUTED, workflowRuns[0].getStatus());
  52. assertRunOkay(workflowRuns[0]);
  53. RunExt runByDescribeLink = Util.getJSON(workflowRuns[0].get_links().self.href, RunExt.class, jenkinsRule);
  54. assertRunOkay(runByDescribeLink);
  55. }
  56. private void assertRunOkay(RunExt workflowRun) {
  57. Assert.assertEquals(0, workflowRun.getStages().size());
  58. Assert.assertEquals(0L, workflowRun.getEndTimeMillis());
  59. Assert.assertEquals(0L, workflowRun.getPauseDurationMillis());
  60. Assert.assertEquals(0L, workflowRun.getQueueDurationMillis());
  61. }
  62. }