PageRenderTime 28ms CodeModel.GetById 23ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/vectorci/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 */
24package com.cloudbees.workflow.rest.endpoints;
25
26import com.cloudbees.workflow.Util;
27import com.cloudbees.workflow.rest.external.RunExt;
28import com.cloudbees.workflow.rest.external.StatusExt;
29import hudson.model.queue.QueueTaskFuture;
30import org.jenkinsci.plugins.workflow.job.WorkflowJob;
31import org.jenkinsci.plugins.workflow.job.WorkflowRun;
32import org.junit.Assert;
33import org.junit.Rule;
34import org.junit.Test;
35import org.jvnet.hudson.test.JenkinsRule;
36
37/**
38 * @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
39 */
40public class UndefinedWorkflowTest {
41
42    @Rule
43    public JenkinsRule jenkinsRule = new JenkinsRule();
44
45    @Test
46    public void test_success_flow() throws Exception {
47        WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Noddy Job");
48
49        // Purposely not setting a workflow definition on the job
50
51        QueueTaskFuture<WorkflowRun> build = job.scheduleBuild2(0);
52        build.waitForStart();
53
54        String jobRunsUrl = job.getUrl() + "wfapi/runs/";
55        RunExt[] workflowRuns = Util.getJSON(jobRunsUrl, RunExt[].class, jenkinsRule);
56
57        Assert.assertEquals(1, workflowRuns.length);
58        Assert.assertNotNull(workflowRuns[0].getId());
59        Assert.assertEquals(StatusExt.NOT_EXECUTED, workflowRuns[0].getStatus());
60        assertRunOkay(workflowRuns[0]);
61
62        RunExt runByDescribeLink = Util.getJSON(workflowRuns[0].get_links().self.href, RunExt.class, jenkinsRule);
63        assertRunOkay(runByDescribeLink);
64    }
65
66    private void assertRunOkay(RunExt workflowRun) {
67        Assert.assertEquals(0, workflowRun.getStages().size());
68        Assert.assertEquals(0L, workflowRun.getEndTimeMillis());
69        Assert.assertEquals(0L, workflowRun.getPauseDurationMillis());
70        Assert.assertEquals(0L, workflowRun.getQueueDurationMillis());
71    }
72}