@Test public void testDeploymentStatisticsQuery() { String deploymentName = "my deployment"; org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testMultiInstanceStatisticsQuery.bpmn20.xml") .addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testParallelGatewayStatisticsQuery.bpmn20.xml") .name(deploymentName) .deploy(); runtimeService.startProcessInstanceByKey("MIExampleProcess"); runtimeService.startProcessInstanceByKey("ParGatewayExampleProcess"); List<DeploymentStatistics> statistics = managementService.createDeploymentStatisticsQuery().includeFailedJobs().list(); Assert.assertEquals(1, statistics.size()); DeploymentStatistics result = statistics.get(0); Assert.assertEquals(2, result.getInstances()); Assert.assertEquals(0, result.getFailedJobs()); Assert.assertEquals(deployment.getId(), result.getId()); Assert.assertEquals(deploymentName, result.getName()); // only compare time on second level (i.e. drop milliseconds) Calendar cal1 = Calendar.getInstance(); cal1.setTime(deployment.getDeploymentTime()); cal1.set(Calendar.MILLISECOND, 0); Calendar cal2 = Calendar.getInstance(); cal2.setTime(result.getDeploymentTime()); cal2.set(Calendar.MILLISECOND, 0); Assert.assertTrue(cal1.equals(cal2)); repositoryService.deleteDeployment(deployment.getId(), true); }
protected void verifyStatisticsResult(DeploymentStatistics statistics, int instances, int failedJobs, int incidents) { assertEquals("Instances", instances, statistics.getInstances()); assertEquals("Failed Jobs", failedJobs, statistics.getFailedJobs()); List<IncidentStatistics> incidentStatistics = statistics.getIncidentStatistics(); if (incidents == 0) { assertTrue("Incidents supposed to be empty", incidentStatistics.isEmpty()); } else { // the test does have only one type of incidents assertEquals("Incidents", incidents, incidentStatistics.get(0).getIncidentCount()); } }
protected Set<String> collectDeploymentTenantIds(List<DeploymentStatistics> deploymentStatistics) { Set<String> tenantIds = new HashSet<String>(); for (DeploymentStatistics statistics : deploymentStatistics) { tenantIds.add(statistics.getTenantId()); } return tenantIds; }
@Test @Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testMultiInstanceStatisticsQuery.bpmn20.xml", "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testParallelGatewayStatisticsQuery.bpmn20.xml"}) public void testDeploymentStatisticsQueryWithoutRunningInstances() { List<DeploymentStatistics> statistics = managementService.createDeploymentStatisticsQuery().includeFailedJobs().list(); Assert.assertEquals(1, statistics.size()); DeploymentStatistics result = statistics.get(0); Assert.assertEquals(0, result.getInstances()); Assert.assertEquals(0, result.getFailedJobs()); }
public void testQueryWithReadInstancePermissionOnProcessDefinition() { // given createGrantAuthorization(DEPLOYMENT, ANY, userId, READ); startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY); startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY); startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY); startProcessInstanceByKey(TIMER_START_PROCESS_KEY); startProcessInstanceByKey(TIMER_START_PROCESS_KEY); startProcessInstanceByKey(TIMER_START_PROCESS_KEY); startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY); startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY); startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY); createGrantAuthorization(PROCESS_DEFINITION, TIMER_BOUNDARY_PROCESS_KEY, userId, READ_INSTANCE); // when DeploymentStatisticsQuery query = managementService.createDeploymentStatisticsQuery(); // then List<DeploymentStatistics> statistics = query.list(); for (DeploymentStatistics deploymentStatistics : statistics) { String id = deploymentStatistics.getId(); if (id.equals(firstDeploymentId)) { verifyStatisticsResult(deploymentStatistics, 0, 0, 0); } else if (id.equals(secondDeploymentId)) { verifyStatisticsResult(deploymentStatistics, 0, 0, 0); } else if (id.equals(thirdDeploymentId)) { verifyStatisticsResult(deploymentStatistics, 3, 0, 0); } else { fail("Unexpected deployment"); } } }
@Test @Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testMultiInstanceStatisticsQuery.bpmn20.xml", "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testStatisticsQueryWithFailedJobs.bpmn20.xml"}) public void testDeploymentStatisticsQueryWithInvalidIncidentType() { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("fail", true); runtimeService.startProcessInstanceByKey("MIExampleProcess"); runtimeService.startProcessInstanceByKey("ExampleProcess", parameters); executeAvailableJobs(); List<DeploymentStatistics> statistics = managementService .createDeploymentStatisticsQuery() .includeIncidentsForType("invalid") .list(); assertFalse(statistics.isEmpty()); assertEquals(1, statistics.size()); DeploymentStatistics result = statistics.get(0); List<IncidentStatistics> incidentStatistics = result.getIncidentStatistics(); assertTrue(incidentStatistics.isEmpty()); }
@Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testFailedTimerStartEvent.bpmn20.xml") public void testQueryByIncidentsWithFailedTimerStartEvent() { executeAvailableJobs(); List<DeploymentStatistics> statistics = managementService .createDeploymentStatisticsQuery() .includeIncidents() .list(); assertEquals(1, statistics.size()); DeploymentStatistics result = statistics.get(0); // there is no running instance assertEquals(0, result.getInstances()); List<IncidentStatistics> incidentStatistics = result.getIncidentStatistics(); // but there is one incident for the failed timer job assertEquals(1, incidentStatistics.size()); IncidentStatistics incidentStatistic = incidentStatistics.get(0); assertEquals(1, incidentStatistic.getIncidentCount()); assertEquals(Incident.FAILED_JOB_HANDLER_TYPE, incidentStatistic.getIncidentType()); }
@Test @Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testMultiInstanceStatisticsQuery.bpmn20.xml", "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testStatisticsQueryWithFailedJobs.bpmn20.xml"}) public void testDeploymentStatisticsQueryWithIncidentsAndFailedJobs() { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("fail", true); runtimeService.startProcessInstanceByKey("MIExampleProcess"); runtimeService.startProcessInstanceByKey("ExampleProcess", parameters); executeAvailableJobs(); List<DeploymentStatistics> statistics = managementService .createDeploymentStatisticsQuery() .includeIncidents() .includeFailedJobs() .list(); assertFalse(statistics.isEmpty()); assertEquals(1, statistics.size()); DeploymentStatistics result = statistics.get(0); Assert.assertEquals(1, result.getFailedJobs()); List<IncidentStatistics> incidentStatistics = result.getIncidentStatistics(); assertFalse(incidentStatistics.isEmpty()); assertEquals(1, incidentStatistics.size()); IncidentStatistics incident = incidentStatistics.get(0); assertEquals(Incident.FAILED_JOB_HANDLER_TYPE, incident.getIncidentType()); assertEquals(1, incident.getIncidentCount()); }
@Test @Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testMultiInstanceStatisticsQuery.bpmn20.xml", "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testStatisticsQueryWithFailedJobs.bpmn20.xml"}) public void testDeploymentStatisticsQueryWithFailedJobs() { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("fail", true); runtimeService.startProcessInstanceByKey("MIExampleProcess"); runtimeService.startProcessInstanceByKey("ExampleProcess", parameters); executeAvailableJobs(); List<DeploymentStatistics> statistics = managementService.createDeploymentStatisticsQuery().includeFailedJobs().list(); DeploymentStatistics result = statistics.get(0); Assert.assertEquals(1, result.getFailedJobs()); }
@Test public void activeProcessInstancesCountWithAuthenticatedTenant() { testRule.deploy(oneTaskProcess); startProcessInstances(ONE_TASK_PROCESS_DEFINITION_KEY); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); List<DeploymentStatistics> deploymentStatistics = managementService .createDeploymentStatisticsQuery() .list(); // then assertEquals(1, deploymentStatistics.size()); // user can see the process instances that belongs to tenant1 and instances that have no tenant assertEquals(2, deploymentStatistics.get(0).getInstances()); }
public void testQueryWithReadInstancePermissionOnAnyProcessDefinition() { // given createGrantAuthorization(DEPLOYMENT, ANY, userId, READ); startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY); startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY); startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY); startProcessInstanceByKey(TIMER_START_PROCESS_KEY); startProcessInstanceByKey(TIMER_START_PROCESS_KEY); startProcessInstanceByKey(TIMER_START_PROCESS_KEY); startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY); startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY); startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY); createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE); // when DeploymentStatisticsQuery query = managementService.createDeploymentStatisticsQuery(); // then List<DeploymentStatistics> statistics = query.list(); for (DeploymentStatistics deploymentStatistics : statistics) { String id = deploymentStatistics.getId(); if (id.equals(firstDeploymentId)) { verifyStatisticsResult(deploymentStatistics, 3, 0, 0); } else if (id.equals(secondDeploymentId)) { verifyStatisticsResult(deploymentStatistics, 3, 0, 0); } else if (id.equals(thirdDeploymentId)) { verifyStatisticsResult(deploymentStatistics, 3, 0, 0); } else { fail("Unexpected deployment"); } } }
@Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testFailedTimerStartEvent.bpmn20.xml") public void testQueryByFailedJobsWithFailedTimerStartEvent() { executeAvailableJobs(); List<DeploymentStatistics> statistics = managementService .createDeploymentStatisticsQuery() .includeFailedJobs() .list(); assertEquals(1, statistics.size()); DeploymentStatistics result = statistics.get(0); // there is no running instance assertEquals(0, result.getInstances()); // but there is one failed timer job assertEquals(1, result.getFailedJobs()); }
@Test public void incidentsCountWithIncidentTypeAndAuthenticatedTenant() { testRule.deploy(failingProcess); startProcessInstances(FAILED_JOBS_PROCESS_DEFINITION_KEY); testRule.executeAvailableJobs(); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); List<DeploymentStatistics> deploymentStatistics = managementService .createDeploymentStatisticsQuery() .includeIncidentsForType("failedJob") .list(); // then assertEquals(1, deploymentStatistics.size()); List<IncidentStatistics> incidentStatistics = deploymentStatistics.get(0).getIncidentStatistics(); assertEquals(1, incidentStatistics.size()); assertEquals(2, incidentStatistics.get(0).getIncidentCount()); }
@Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testFailedTimerStartEvent.bpmn20.xml") public void testQueryByIncidentTypeWithFailedTimerStartEvent() { executeAvailableJobs(); List<DeploymentStatistics> statistics = managementService .createDeploymentStatisticsQuery() .includeIncidentsForType(Incident.FAILED_JOB_HANDLER_TYPE) .list(); assertEquals(1, statistics.size()); DeploymentStatistics result = statistics.get(0); // there is no running instance assertEquals(0, result.getInstances()); List<IncidentStatistics> incidentStatistics = result.getIncidentStatistics(); // but there is one incident for the failed timer job assertEquals(1, incidentStatistics.size()); IncidentStatistics incidentStatistic = incidentStatistics.get(0); assertEquals(1, incidentStatistic.getIncidentCount()); assertEquals(Incident.FAILED_JOB_HANDLER_TYPE, incidentStatistic.getIncidentType()); }
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testCallActivityWithIncidentsWithoutFailedJobs.bpmn20.xml") public void testDeploymentStatisticsQueryWithTwoIncidentsAndOneFailedJobs() { runtimeService.startProcessInstanceByKey("callExampleSubProcess"); executeAvailableJobs(); List<DeploymentStatistics> statistics = managementService .createDeploymentStatisticsQuery() .includeIncidents() .includeFailedJobs() .list(); assertFalse(statistics.isEmpty()); assertEquals(1, statistics.size()); DeploymentStatistics result = statistics.get(0); // has one failed job Assert.assertEquals(1, result.getFailedJobs()); List<IncidentStatistics> incidentStatistics = result.getIncidentStatistics(); assertFalse(incidentStatistics.isEmpty()); assertEquals(1, incidentStatistics.size()); IncidentStatistics incident = incidentStatistics.get(0); assertEquals(Incident.FAILED_JOB_HANDLER_TYPE, incident.getIncidentType()); assertEquals(2, incident.getIncidentCount()); // ...but two incidents }
@Test public void failedJobsCountWithAuthenticatedTenant() { testRule.deploy(failingProcess); startProcessInstances(FAILED_JOBS_PROCESS_DEFINITION_KEY); testRule.executeAvailableJobs(); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); List<DeploymentStatistics> deploymentStatistics = managementService .createDeploymentStatisticsQuery() .includeFailedJobs() .list(); // then assertEquals(1, deploymentStatistics.size()); assertEquals(2, deploymentStatistics.get(0).getFailedJobs()); }
@Test public void activeProcessInstancesCountWithMultipleAuthenticatedTenants() { testRule.deploy(oneTaskProcess); startProcessInstances(ONE_TASK_PROCESS_DEFINITION_KEY); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE, TENANT_TWO)); List<DeploymentStatistics> deploymentStatistics = managementService .createDeploymentStatisticsQuery() .list(); // then assertEquals(1, deploymentStatistics.size()); // user can see all the active process instances assertEquals(3, deploymentStatistics.get(0).getInstances()); }
@Test public void instancesFailedJobsAndIncidentsCountWithAuthenticatedTenant() { testRule.deploy(failingProcess,anotherFailingProcess); startProcessInstances(FAILED_JOBS_PROCESS_DEFINITION_KEY); startProcessInstances(ANOTHER_FAILED_JOBS_PROCESS_DEFINITION_KEY); testRule.executeAvailableJobs(); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); List<DeploymentStatistics> deploymentStatistics = managementService .createDeploymentStatisticsQuery() .includeFailedJobs() .includeIncidents() .list(); // then assertEquals(1, deploymentStatistics.size()); DeploymentStatistics singleDeploymentStatistics = deploymentStatistics.get(0); assertEquals(4, singleDeploymentStatistics.getInstances()); assertEquals(4, singleDeploymentStatistics.getFailedJobs()); List<IncidentStatistics> incidentStatistics = singleDeploymentStatistics.getIncidentStatistics(); assertEquals(1, incidentStatistics.size()); assertEquals(4, incidentStatistics.get(0).getIncidentCount()); }
@Test public void testDeploymentStatisticsQuery() { String deploymentName = "my deployment"; org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testMultiInstanceStatisticsQuery.bpmn20.xml") .addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testParallelGatewayStatisticsQuery.bpmn20.xml") .name(deploymentName) .deploy(); runtimeService.startProcessInstanceByKey("MIExampleProcess"); runtimeService.startProcessInstanceByKey("ParGatewayExampleProcess"); List<DeploymentStatistics> statistics = managementService.createDeploymentStatisticsQuery().includeFailedJobs().list(); Assert.assertEquals(1, statistics.size()); DeploymentStatistics result = statistics.get(0); Assert.assertEquals(2, result.getInstances()); Assert.assertEquals(0, result.getFailedJobs()); Assert.assertEquals(deployment.getId(), result.getId()); Assert.assertEquals(deploymentName, result.getName()); // only compare time on second level (i.e. drop milliseconds) Calendar cal1 = Calendar.getInstance(); cal1.setTime(deployment.getDeploymentTime()); cal1.set(Calendar.MILLISECOND, 0); Calendar cal2 = Calendar.getInstance(); cal2.setTime(result.getDeploymentTime()); cal2.set(Calendar.MILLISECOND, 0); Assert.assertTrue(cal1.equals(cal2)); repositoryService.deleteDeployment(deployment.getId(), true); }
public void testQueryWithReadPermissionOnProcessInstance() { // given createGrantAuthorization(DEPLOYMENT, ANY, userId, READ); startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY); startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY); startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY); startProcessInstanceByKey(TIMER_START_PROCESS_KEY); startProcessInstanceByKey(TIMER_START_PROCESS_KEY); startProcessInstanceByKey(TIMER_START_PROCESS_KEY); startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY); startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY); String processInstanceId = startProcessInstanceByKey(TIMER_BOUNDARY_PROCESS_KEY).getId(); createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ); // when DeploymentStatisticsQuery query = managementService.createDeploymentStatisticsQuery(); // then List<DeploymentStatistics> statistics = query.list(); for (DeploymentStatistics deploymentStatistics : statistics) { String id = deploymentStatistics.getId(); if (id.equals(firstDeploymentId)) { verifyStatisticsResult(deploymentStatistics, 0, 0, 0); } else if (id.equals(secondDeploymentId)) { verifyStatisticsResult(deploymentStatistics, 0, 0, 0); } else if (id.equals(thirdDeploymentId)) { verifyStatisticsResult(deploymentStatistics, 1, 0, 0); } else { fail("Unexpected deployment"); } } }