Search in sources :

Example 96 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.

the class BlueJUnitTestResultTest method createsTestResult.

@Test
public void createsTestResult() throws Exception {
    URL resource = getClass().getResource("BlueJUnitTestResultTest.jenkinsfile");
    String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
    WorkflowJob p = j.createProject(WorkflowJob.class, "project");
    p.setDefinition(new CpsFlowDefinition(jenkinsFile, false));
    p.save();
    Run r = p.scheduleBuild2(0).waitForStart();
    j.waitUntilNoActivity();
    BlueRun test = BlueRunFactory.getRun(r, () -> new Link("test"));
    Assert.assertEquals(3, IterableUtils.size(test.getTests()));
    BluePipelineNode node = mock(BluePipelineNode.class);
    when(node.getId()).thenReturn("6");
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Run(hudson.model.Run) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) URL(java.net.URL) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 97 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.

the class BlueTrendsApiTest method getJUnitTrends.

@Test
public void getJUnitTrends() throws Exception {
    URL resource = getClass().getResource("BlueJUnitTestResultTest.jenkinsfile");
    String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
    WorkflowJob p = j.createProject(WorkflowJob.class, "project");
    p.setDefinition(new CpsFlowDefinition(jenkinsFile, false));
    p.save();
    Run run;
    for (int i = 0; i < 10; i++) {
        run = p.scheduleBuild2(0).waitForStart();
        j.waitForCompletion(run);
    }
    Map trend = new RequestBuilder(baseUrl).get("/organizations/jenkins/pipelines/" + p.getName() + "/trends/junit/").build(Map.class);
    List rows;
    Map testRow;
    Assert.assertNotNull(trend);
    Map columns = (Map) trend.get("columns");
    Assert.assertNotNull(columns);
    Assert.assertEquals(7, columns.keySet().size());
    rows = new RequestBuilder(baseUrl).get("/organizations/jenkins/pipelines/" + p.getName() + "/trends/junit/rows").build(List.class);
    Assert.assertNotNull(rows);
    Assert.assertEquals(10, rows.size());
    testRow = (Map) rows.get(0);
    Assert.assertEquals("10", testRow.get(BlueTableRow.ID));
    Assert.assertEquals(3, testRow.get(BlueJUnitTrend.TOTAL));
    Assert.assertEquals(2, testRow.get(BlueJUnitTrend.PASSED));
    Assert.assertEquals(1, testRow.get(BlueJUnitTrend.FAILED));
    Assert.assertEquals(1, testRow.get(BlueJUnitTrend.EXISTING_FAILED));
    Assert.assertEquals(0, testRow.get(BlueJUnitTrend.FIXED));
    Assert.assertEquals(0, testRow.get(BlueJUnitTrend.REGRESSIONS));
    Assert.assertEquals(0, testRow.get(BlueJUnitTrend.SKIPPED));
    rows = new RequestBuilder(baseUrl).get("/organizations/jenkins/pipelines/" + p.getName() + "/trends/junit/rows?start=5&limit=5").build(List.class);
    Assert.assertNotNull(rows);
    Assert.assertEquals(5, rows.size());
    testRow = (Map) rows.get(0);
    Assert.assertEquals("5", testRow.get(BlueTableRow.ID));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Run(hudson.model.Run) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) URL(java.net.URL) Test(org.junit.Test) BaseTest(io.jenkins.blueocean.service.embedded.BaseTest)

Example 98 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.

the class RunMultiThreadLoadTest method load_runs_multi_threaded.

@Test
public void load_runs_multi_threaded() throws Exception {
    URL resource = getClass().getResource("RunMultiThreadLoadTest.jenkinsfile");
    String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
    WorkflowJob p = j.createProject(WorkflowJob.class, "project1");
    p.setDefinition(new CpsFlowDefinition(jenkinsFile, false));
    p.save();
    for (int i = 0; i < 10; i++) {
        j.waitForCompletion(p.scheduleBuild2(0).waitForStart());
    }
    Iterable<BlueRun> blueRuns = RunSearch.findRuns(p, null, 0, 20);
    List<BlueRun> runs = StreamSupport.stream(blueRuns.spliterator(), false).collect(Collectors.toList());
    Assert.assertFalse(runs.isEmpty());
    Assert.assertEquals(10, runs.size());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) URL(java.net.URL) Test(org.junit.Test)

Example 99 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.

the class RunMultiThreadLoadTest method load_runs_multi_threaded_no_runs.

@Test
@Issue("JENKINS-52101")
public void load_runs_multi_threaded_no_runs() throws Exception {
    URL resource = getClass().getResource("RunMultiThreadLoadTest.jenkinsfile");
    String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
    WorkflowJob p = j.createProject(WorkflowJob.class, "project2");
    p.setDefinition(new CpsFlowDefinition(jenkinsFile, false));
    p.save();
    Iterable<BlueRun> blueRuns = RunSearch.findRuns(p, null, 0, 0);
    List<BlueRun> runs = StreamSupport.stream(blueRuns.spliterator(), false).collect(Collectors.toList());
    Assert.assertTrue(runs.isEmpty());
    Assert.assertEquals(0, runs.size());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) URL(java.net.URL) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 100 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project htmlpublisher-plugin by jenkinsci.

the class PublishHTMLStepTest method setupAndRunProject.

private void setupAndRunProject(@NonNull HtmlPublisherTarget target) throws Exception {
    // Test node for the workflow
    r.jenkins.addNode(new DumbSlave("slave", "dummy", testWorkspace.getPath(), "1", Node.Mode.NORMAL, "", r.createComputerLauncher(null), RetentionStrategy.NOOP, // TODO JENKINS-26398 clumsy
    Collections.emptyList()));
    job = r.jenkins.createProject(WorkflowJob.class, TEST_PROJECT_NAME);
    job.setDefinition(new CpsFlowDefinition("" + "node('slave') {\n" + "  publishHTML(target: [allowMissing: " + target.getAllowMissing() + ", keepAll: " + target.getKeepAll() + ", reportDir: '" + target.getReportDir() + "', reportFiles: '" + target.getReportFiles() + "', reportName: '" + target.getReportName() + "']) \n" + "}", true));
    QueueTaskFuture<WorkflowRun> runFuture = job.scheduleBuild2(0);
    assertThat("build was actually scheduled", runFuture, Matchers.notNullValue());
    run = runFuture.get();
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) DumbSlave(hudson.slaves.DumbSlave) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Aggregations

CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)220 Test (org.junit.Test)210 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)182 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)124 Issue (org.jvnet.hudson.test.Issue)63 Map (java.util.Map)60 List (java.util.List)26 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RunList (hudson.util.RunList)20 ExtensionList (hudson.ExtensionList)19 Statement (org.junit.runners.model.Statement)19 Run (hudson.model.Run)17 URL (java.net.URL)16 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)12 TaskListener (hudson.model.TaskListener)11 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)10 NodeStepTypePredicate (org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate)9 DescribeChangeSetResult (com.amazonaws.services.cloudformation.model.DescribeChangeSetResult)7 Parameter (com.amazonaws.services.cloudformation.model.Parameter)6