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"));
}
Aggregations