Search in sources :

Example 1 with JobAnalytics

use of io.jenkins.blueocean.service.embedded.analytics.JobAnalytics in project blueocean-plugin by jenkinsci.

the class JobAnalyticsTest method testJobAnalytics.

@Test
public void testJobAnalytics() throws Exception {
    // Freestyle jobs
    j.createFreeStyleProject("freestyle1").save();
    j.createFreeStyleProject("freestyle2").save();
    // Matrix job
    j.createProject(MatrixProject.class, "bob");
    // Create single scripted pipeline
    WorkflowJob scriptedSingle = createWorkflowJobWithJenkinsfile(getClass(), "JobAnalyticsTest-scripted.jenkinsfile");
    WorkflowRun scriptedSingleRun = scriptedSingle.scheduleBuild2(0, new CauseAction()).waitForStart();
    j.waitForCompletion(scriptedSingleRun);
    // Create single declarative pipeline
    WorkflowJob declarativeSingle = createWorkflowJobWithJenkinsfile(getClass(), "JobAnalyticsTest-declarative.jenkinsfile");
    WorkflowRun declarativeSingleRun = declarativeSingle.scheduleBuild2(0, new CauseAction()).waitForStart();
    j.waitForCompletion(declarativeSingleRun);
    // Create Scripted MultiBranch
    createMultiBranch(sampleRepo);
    // Create Declarative MultiBranch
    createMultiBranch(sampleRepo2);
    AnalyticsImpl analytics = (AnalyticsImpl) Analytics.get();
    Assert.assertNotNull(analytics);
    JobAnalytics jobAnalytics = new JobAnalytics();
    jobAnalytics.calculateAndSend();
    Assert.assertNotNull(analytics.lastReq);
    Assert.assertEquals("job_stats", analytics.lastReq.name);
    Map<String, Object> properties = analytics.lastReq.properties;
    Assert.assertEquals("singlePipelineDeclarative", 1, properties.get("singlePipelineDeclarative"));
    Assert.assertEquals("singlePipelineScripted", 1, properties.get("singlePipelineScripted"));
    Assert.assertEquals("pipelineDeclarative", 1, properties.get("pipelineDeclarative"));
    Assert.assertEquals("pipelineScripted", 1, properties.get("pipelineScripted"));
    Assert.assertEquals("freestyle", 2, properties.get("freestyle"));
    Assert.assertEquals("matrix", 1, properties.get("matrix"));
    Assert.assertEquals("other", 0, properties.get("other"));
}
Also used : JobAnalytics(io.jenkins.blueocean.service.embedded.analytics.JobAnalytics) CauseAction(hudson.model.CauseAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Aggregations

CauseAction (hudson.model.CauseAction)1 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)1 JobAnalytics (io.jenkins.blueocean.service.embedded.analytics.JobAnalytics)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 Test (org.junit.Test)1