@Test public void testAdditionalIncidentsAndFailedJobsOption() { given().queryParam("incidents", "true").queryParam("failedJobs", "true") .then().expect() .statusCode(Status.OK.getStatusCode()) .when().get(PROCESS_DEFINITION_STATISTICS_URL); InOrder inOrder = Mockito.inOrder(processDefinitionStatisticsQueryMock); inOrder.verify(processDefinitionStatisticsQueryMock).includeFailedJobs(); inOrder.verify(processDefinitionStatisticsQueryMock).includeIncidents(); inOrder.verify(processDefinitionStatisticsQueryMock).list(); }
query.includeFailedJobs(); query.includeIncidents(); } else if (includeIncidentsForType != null) { query.includeIncidentsForType(includeIncidentsForType); } else if (includeRootIncidents != null && includeRootIncidents) { query.includeRootIncidents(); List<ProcessDefinitionStatistics> queryResults = query.list();
public void testQueryNoAuthenticatedTenantsForProcessDefinitionStatistics() { identityService.setAuthentication("user", null, null); ProcessDefinitionStatisticsQuery query = managementService.createProcessDefinitionStatisticsQuery(); assertThat(query.count(), is(1L)); Set<String> tenantIds = collectDefinitionTenantIds(query.list()); assertThat(tenantIds.size(), is(1)); assertThat(tenantIds.iterator().next(), is(nullValue())); }
@Test public void testAdditionalIncidentsForTypeAndFailedJobsOption() { given().queryParam("incidentsForType", "failedJob").queryParam("failedJobs", "true") .then().expect() .statusCode(Status.OK.getStatusCode()) .when().get(PROCESS_DEFINITION_STATISTICS_URL); InOrder inOrder = Mockito.inOrder(processDefinitionStatisticsQueryMock); inOrder.verify(processDefinitionStatisticsQueryMock).includeFailedJobs(); inOrder.verify(processDefinitionStatisticsQueryMock).includeIncidentsForType("failedJob"); inOrder.verify(processDefinitionStatisticsQueryMock).list(); }
@Test public void testAdditionalFailedJobsOption() { given().queryParam("failedJobs", "true") .then().expect() .statusCode(Status.OK.getStatusCode()) .when().get(PROCESS_DEFINITION_STATISTICS_URL); InOrder inOrder = Mockito.inOrder(processDefinitionStatisticsQueryMock); inOrder.verify(processDefinitionStatisticsQueryMock).includeFailedJobs(); inOrder.verify(processDefinitionStatisticsQueryMock).list(); }
@Test public void testAdditionalIncidentsOption() { given().queryParam("incidents", "true") .then().expect() .statusCode(Status.OK.getStatusCode()) .when().get(PROCESS_DEFINITION_STATISTICS_URL); InOrder inOrder = Mockito.inOrder(processDefinitionStatisticsQueryMock); inOrder.verify(processDefinitionStatisticsQueryMock).includeIncidents(); inOrder.verify(processDefinitionStatisticsQueryMock).list(); }
@Test public void testAdditionalIncidentsForTypeOption() { given().queryParam("incidentsForType", "failedJob") .then().expect() .statusCode(Status.OK.getStatusCode()) .when().get(PROCESS_DEFINITION_STATISTICS_URL); InOrder inOrder = Mockito.inOrder(processDefinitionStatisticsQueryMock); inOrder.verify(processDefinitionStatisticsQueryMock).includeIncidentsForType("failedJob"); inOrder.verify(processDefinitionStatisticsQueryMock).list(); }
private void setupProcessDefinitionStatisticsMock() { List<ProcessDefinitionStatistics> mocks = MockProvider.createMockProcessDefinitionStatistics(); processDefinitionStatisticsQueryMock = mock(ProcessDefinitionStatisticsQuery.class); when(processDefinitionStatisticsQueryMock.list()).thenReturn(mocks); when(processEngine.getManagementService().createProcessDefinitionStatisticsQuery()).thenReturn(processDefinitionStatisticsQueryMock); }
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testCallActivityWithIncidentsWithoutFailedJobs.bpmn20.xml") public void testIncludeRootIncidentsFails() { runtimeService.startProcessInstanceByKey("callExampleSubProcess"); executeAvailableJobs(); try { managementService .createProcessDefinitionStatisticsQuery() .includeIncidents() .includeRootIncidents() .list(); } catch (ProcessEngineException e) { Assert.assertThat(e.getMessage(), containsString("It is not possible to use includeIncident() and includeRootIncidents() to execute one query")); } }
@Test public void testProcessDefinitionStatisticsWithRootIncidents() { given().queryParam("rootIncidents", "true") .then().expect() .statusCode(Status.OK.getStatusCode()) .when().get(PROCESS_DEFINITION_STATISTICS_URL); InOrder inOrder = Mockito.inOrder(processDefinitionStatisticsQueryMock);; inOrder.verify(processDefinitionStatisticsQueryMock).includeRootIncidents(); inOrder.verify(processDefinitionStatisticsQueryMock).list(); } }
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testStatisticsQueryWithFailedJobs.bpmn20.xml") public void testProcessDefinitionStatisticsQueryCount() { runtimeService.startProcessInstanceByKey("ExampleProcess"); executeAvailableJobs(); long count = managementService .createProcessDefinitionStatisticsQuery() .includeFailedJobs() .includeIncidents() .count(); Assert.assertEquals(1, count); }
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testStatisticsQueryWithFailedJobs.bpmn20.xml") public void testProcessDefinitionStatisticsQueryPagination() { org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testStatisticsQuery.bpmn20.xml") .deploy(); List<ProcessDefinition> definitions = repositoryService .createProcessDefinitionQuery() .processDefinitionKey("ExampleProcess") .list(); for (ProcessDefinition definition : definitions) { runtimeService.startProcessInstanceById(definition.getId()); } List<ProcessDefinitionStatistics> statistics = managementService.createProcessDefinitionStatisticsQuery().includeFailedJobs().listPage(0, 1); Assert.assertEquals(1, statistics.size()); repositoryService.deleteDeployment(deployment.getId(), true); }
@Test public void failedJobsCountWithAuthenticatedTenant() { testRule.deploy(failingProcess); startProcessInstances(FAILED_JOBS_PROCESS_DEFINITION_KEY); testRule.executeAvailableJobs(); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); List<ProcessDefinitionStatistics> processDefinitionsStatistics = managementService .createProcessDefinitionStatisticsQuery() .includeFailedJobs() .list(); // then assertEquals(1, processDefinitionsStatistics.size()); assertEquals(2, processDefinitionsStatistics.get(0).getFailedJobs()); }
@Test public void incidentsCountWithAuthenticatedTenant() { testRule.deploy(failingProcess); startProcessInstances(FAILED_JOBS_PROCESS_DEFINITION_KEY); testRule.executeAvailableJobs(); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); List<ProcessDefinitionStatistics> processDefinitionsStatistics = managementService .createProcessDefinitionStatisticsQuery() .includeIncidents() .list(); // then assertEquals(1, processDefinitionsStatistics.size()); List<IncidentStatistics> incidentStatistics = processDefinitionsStatistics.get(0).getIncidentStatistics(); assertEquals(1, incidentStatistics.size()); assertEquals(2, incidentStatistics.get(0).getIncidentCount()); }
@Test public void incidentsCountWithIncidentTypeAndAuthenticatedTenant() { testRule.deploy(failingProcess); startProcessInstances(FAILED_JOBS_PROCESS_DEFINITION_KEY); testRule.executeAvailableJobs(); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); List<ProcessDefinitionStatistics> processDefinitionsStatistics = managementService .createProcessDefinitionStatisticsQuery() .includeIncidentsForType("failedJob") .list(); // then assertEquals(1, processDefinitionsStatistics.size()); List<IncidentStatistics> incidentStatistics = processDefinitionsStatistics.get(0).getIncidentStatistics(); assertEquals(1, incidentStatistics.size()); assertEquals(2, incidentStatistics.get(0).getIncidentCount()); }
managementService .createProcessDefinitionStatisticsQuery() .includeFailedJobs() .includeIncidentsForType("failedJob") .list();
public void testProcessDefinitionStatistics() { List<ProcessDefinitionStatistics> processDefinitionStatistics = managementService .createProcessDefinitionStatisticsQuery() .list(); assertThat(processDefinitionStatistics.size(), is(3)); Set<String> tenantIds = collectDefinitionTenantIds(processDefinitionStatistics); assertThat(tenantIds, hasItems(null, TENANT_ONE, TENANT_TWO)); }
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testCallActivityWithIncidentsWithoutFailedJobs.bpmn20.xml") public void testIncludeRootIncidentsFails() { runtimeService.startProcessInstanceByKey("callExampleSubProcess"); executeAvailableJobs(); try { managementService .createProcessDefinitionStatisticsQuery() .includeIncidents() .includeRootIncidents() .list(); } catch (ProcessEngineException e) { Assert.assertThat(e.getMessage(), containsString("It is not possible to use includeIncident() and includeRootIncidents() to execute one query")); } }
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testCallActivityWithIncidentsWithoutFailedJobs.bpmn20.xml") public void testIncludeRootIncidentsOnly() { runtimeService.startProcessInstanceByKey("callExampleSubProcess"); executeAvailableJobs(); List<ProcessDefinitionStatistics> statistics = managementService .createProcessDefinitionStatisticsQuery() .includeRootIncidents() .list(); // two process definitions assertEquals(2, statistics.size()); for (ProcessDefinitionStatistics definitionResult : statistics) { if (definitionResult.getKey().equals("callExampleSubProcess")) { // there is no root incidents assertTrue(definitionResult.getIncidentStatistics().isEmpty()); } else if (definitionResult.getKey().equals("ExampleProcess")) { // there is one root incident assertFalse(definitionResult.getIncidentStatistics().isEmpty()); assertEquals(1, definitionResult.getIncidentStatistics().size()); assertEquals(1, definitionResult.getIncidentStatistics().get(0).getIncidentCount()); } else { // fail if the process definition key does not match fail(); } } }
@Test @Deployment(resources = "org/camunda/bpm/engine/test/api/mgmt/StatisticsTest.testStatisticsQueryWithFailedJobs.bpmn20.xml") public void testProcessDefinitionStatisticsQueryCount() { runtimeService.startProcessInstanceByKey("ExampleProcess"); executeAvailableJobs(); long count = managementService .createProcessDefinitionStatisticsQuery() .includeFailedJobs() .includeIncidents() .count(); Assert.assertEquals(1, count); }