@Override protected void applyFilters(CleanableHistoricDecisionInstanceReport query) { if (decisionDefinitionIdIn != null && decisionDefinitionIdIn.length > 0) { query.decisionDefinitionIdIn(decisionDefinitionIdIn); } if (decisionDefinitionKeyIn != null && decisionDefinitionKeyIn.length > 0) { query.decisionDefinitionKeyIn(decisionDefinitionKeyIn); } if (Boolean.TRUE.equals(withoutTenantId)) { query.withoutTenantId(); } if (tenantIdIn != null && tenantIdIn.length > 0) { query.tenantIdIn(tenantIdIn); } if (Boolean.TRUE.equals(compact)) { query.compact(); } }
private void setupHistoryReportMock() { CleanableHistoricDecisionInstanceReport report = mock(CleanableHistoricDecisionInstanceReport.class); when(report.decisionDefinitionIdIn(anyString())).thenReturn(report); when(report.decisionDefinitionKeyIn(anyString())).thenReturn(report); CleanableHistoricDecisionInstanceReportResult reportResult = mock(CleanableHistoricDecisionInstanceReportResult.class); when(reportResult.getDecisionDefinitionId()).thenReturn(EXAMPLE_DD_ID); when(reportResult.getDecisionDefinitionKey()).thenReturn(EXAMPLE_DD_KEY); when(reportResult.getDecisionDefinitionName()).thenReturn(EXAMPLE_DD_NAME); when(reportResult.getDecisionDefinitionVersion()).thenReturn(EXAMPLE_DD_VERSION); when(reportResult.getHistoryTimeToLive()).thenReturn(EXAMPLE_TTL); when(reportResult.getFinishedDecisionInstanceCount()).thenReturn(EXAMPLE_FINISHED_DI_COUNT); when(reportResult.getCleanableDecisionInstanceCount()).thenReturn(EXAMPLE_CLEANABLE_DI_COUNT); when(reportResult.getTenantId()).thenReturn(EXAMPLE_TENANT_ID); CleanableHistoricDecisionInstanceReportResult anotherReportResult = mock(CleanableHistoricDecisionInstanceReportResult.class); when(anotherReportResult.getDecisionDefinitionId()).thenReturn(ANOTHER_EXAMPLE_DD_ID); when(anotherReportResult.getDecisionDefinitionKey()).thenReturn(ANOTHER_EXAMPLE_DD_KEY); when(anotherReportResult.getDecisionDefinitionName()).thenReturn("dpName"); when(anotherReportResult.getDecisionDefinitionVersion()).thenReturn(33); when(anotherReportResult.getHistoryTimeToLive()).thenReturn(5); when(anotherReportResult.getFinishedDecisionInstanceCount()).thenReturn(10l); when(anotherReportResult.getCleanableDecisionInstanceCount()).thenReturn(0l); when(anotherReportResult.getTenantId()).thenReturn(ANOTHER_EXAMPLE_TENANT_ID); List<CleanableHistoricDecisionInstanceReportResult> mocks = new ArrayList<CleanableHistoricDecisionInstanceReportResult>(); mocks.add(reportResult); mocks.add(anotherReportResult); when(report.list()).thenReturn(mocks); when(report.count()).thenReturn((long) mocks.size()); historicDecisionInstanceReport = report; when(processEngine.getHistoryService().createCleanableHistoricDecisionInstanceReport()).thenReturn(historicDecisionInstanceReport); }
@Test public void testOrderByFinishedDecisionInstanceAsc() { given() .queryParam("sortBy", "finished") .queryParam("sortOrder", "asc") .then().expect() .statusCode(Status.OK.getStatusCode()) .when() .get(HISTORIC_REPORT_URL); verify(historicDecisionInstanceReport).orderByFinished(); verify(historicDecisionInstanceReport).asc(); verify(historicDecisionInstanceReport).list(); verifyNoMoreInteractions(historicDecisionInstanceReport); }
@Test public void testOrderByFinishedDecisionInstanceDesc() { given() .queryParam("sortBy", "finished") .queryParam("sortOrder", "desc") .then().expect() .statusCode(Status.OK.getStatusCode()) .when() .get(HISTORIC_REPORT_URL); verify(historicDecisionInstanceReport).orderByFinished(); verify(historicDecisionInstanceReport).desc(); verify(historicDecisionInstanceReport).list(); verifyNoMoreInteractions(historicDecisionInstanceReport); }
@Test public void testReportTenantIdInNoAuthenticatedTenants() { // given testRule.deployForTenant(TENANT_ONE, DMN_MODEL); testRule.deployForTenant(TENANT_TWO, DMN_MODEL); prepareDecisionInstances(DECISION_DEFINITION_KEY, -6, 5, 10, TENANT_ONE); prepareDecisionInstances(DECISION_DEFINITION_KEY, -6, 5, 10, TENANT_TWO); identityService.setAuthentication("user", null, null); // when List<CleanableHistoricDecisionInstanceReportResult> reportResultsOne = historyService.createCleanableHistoricDecisionInstanceReport().tenantIdIn(TENANT_ONE).list(); List<CleanableHistoricDecisionInstanceReportResult> reportResultsTwo = historyService.createCleanableHistoricDecisionInstanceReport().tenantIdIn(TENANT_TWO).list(); // then assertEquals(0, reportResultsOne.size()); assertEquals(0, reportResultsTwo.size()); }
@Override public List<CleanableHistoricDecisionInstanceReportResultDto> getCleanableHistoricDecisionInstanceReport(UriInfo uriInfo, Integer firstResult, Integer maxResults) { CleanableHistoricDecisionInstanceReportDto queryDto = new CleanableHistoricDecisionInstanceReportDto(objectMapper, uriInfo.getQueryParameters()); CleanableHistoricDecisionInstanceReport query = queryDto.toQuery(processEngine); List<CleanableHistoricDecisionInstanceReportResult> reportResult; if (firstResult != null || maxResults != null) { reportResult = executePaginatedQuery(query, firstResult, maxResults); } else { reportResult = query.list(); } return CleanableHistoricDecisionInstanceReportResultDto.convert(reportResult); }
@Test public void testReportComplex() { // given testRule.deploy("org/camunda/bpm/engine/test/repository/two.dmn", "org/camunda/bpm/engine/test/api/dmn/Another_Example.dmn", "org/camunda/bpm/engine/test/api/dmn/Example.dmn"); prepareDecisionInstances(DECISION_DEFINITION_KEY, 0, 5, 10); prepareDecisionInstances(DECISION_DEFINITION_KEY, -6, 5, 10); prepareDecisionInstances(SECOND_DECISION_DEFINITION_KEY, -6, null, 10); prepareDecisionInstances(THIRD_DECISION_DEFINITION_KEY, -6, 5, 10); // when List<CleanableHistoricDecisionInstanceReportResult> reportResults = historyService.createCleanableHistoricDecisionInstanceReport().list(); String secondDecisionDefinitionId = repositoryService.createDecisionDefinitionQuery().decisionDefinitionKey(SECOND_DECISION_DEFINITION_KEY).singleResult().getId(); CleanableHistoricDecisionInstanceReportResult secondReportResult = historyService.createCleanableHistoricDecisionInstanceReport().decisionDefinitionIdIn(secondDecisionDefinitionId).singleResult(); CleanableHistoricDecisionInstanceReportResult thirdReportResult = historyService.createCleanableHistoricDecisionInstanceReport().decisionDefinitionKeyIn(THIRD_DECISION_DEFINITION_KEY).singleResult(); // then assertEquals(4, reportResults.size()); for (CleanableHistoricDecisionInstanceReportResult result : reportResults) { if (result.getDecisionDefinitionKey().equals(DECISION_DEFINITION_KEY)) { checkResultNumbers(result, 10, 20); } else if (result.getDecisionDefinitionKey().equals(SECOND_DECISION_DEFINITION_KEY)) { checkResultNumbers(result, 0, 10); } else if (result.getDecisionDefinitionKey().equals(THIRD_DECISION_DEFINITION_KEY)) { checkResultNumbers(result, 10, 10); } else if (result.getDecisionDefinitionKey().equals(FOURTH_DECISION_DEFINITION_KEY)) { checkResultNumbers(result, 0, 0); } } checkResultNumbers(secondReportResult, 0, 10); checkResultNumbers(thirdReportResult, 10, 10); }
@Test @Deployment(resources = { "org/camunda/bpm/engine/test/dmn/deployment/drdDish.dmn11.xml" }) public void shouldNotSeeCleanableDecisionInstancesInReport() { // given engineConfiguration .setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_END) .initHistoryRemovalTime(); testRule.deploy(CALLING_PROCESS_CALLS_DMN); ClockUtil.setCurrentTime(END_DATE); for (int i = 0; i < 5; i++) { runtimeService.startProcessInstanceByKey(CALLING_PROCESS_CALLS_DMN_KEY, Variables.createVariables() .putValue("temperature", 32) .putValue("dayType", "Weekend")); } ClockUtil.setCurrentTime(addDays(END_DATE, 5)); // when CleanableHistoricDecisionInstanceReportResult report = historyService.createCleanableHistoricDecisionInstanceReport() .decisionDefinitionKeyIn("dish-decision") .compact() .singleResult(); // then assertThat(report.getCleanableDecisionInstanceCount(), is(0L)); assertThat(report.getFinishedDecisionInstanceCount(), is(5L)); }
@Test public void testReportCompact() { // given List<DecisionDefinition> decisionDefinitions = repositoryService.createDecisionDefinitionQuery().decisionDefinitionKey(DECISION_DEFINITION_KEY).list(); assertEquals(1, decisionDefinitions.size()); // assume List<CleanableHistoricDecisionInstanceReportResult> resultWithZeros = historyService.createCleanableHistoricDecisionInstanceReport().list(); assertEquals(1, resultWithZeros.size()); assertEquals(0, resultWithZeros.get(0).getFinishedDecisionInstanceCount()); // when long resultCountWithoutZeros = historyService.createCleanableHistoricDecisionInstanceReport().compact().count(); // then assertEquals(0, resultCountWithoutZeros); }
@Test public void testReportTenantIdInWithoutTenantId() { // given testRule.deploy(DMN_MODEL); testRule.deployForTenant(TENANT_ONE, DMN_MODEL); prepareDecisionInstances(DECISION_DEFINITION_KEY, -6, 5, 10, null); prepareDecisionInstances(DECISION_DEFINITION_KEY, -6, 5, 10, TENANT_ONE); // when List<CleanableHistoricDecisionInstanceReportResult> reportResults = historyService.createCleanableHistoricDecisionInstanceReport().withoutTenantId().list(); List<CleanableHistoricDecisionInstanceReportResult> reportResultsOne = historyService.createCleanableHistoricDecisionInstanceReport().tenantIdIn(TENANT_ONE).list(); // then assertEquals(1, reportResults.size()); assertEquals(null, reportResults.get(0).getTenantId()); assertEquals(1, reportResultsOne.size()); assertEquals(TENANT_ONE, reportResultsOne.get(0).getTenantId()); }
@Test public void testReportWithoutTenantId() { // given testRule.deploy(DMN_MODEL); prepareDecisionInstances(DECISION_DEFINITION_KEY, -6, 5, 10, null); // when List<CleanableHistoricDecisionInstanceReportResult> reportResults = historyService.createCleanableHistoricDecisionInstanceReport().withoutTenantId().list(); // then assertEquals(1, reportResults.size()); assertEquals(null, reportResults.get(0).getTenantId()); }
@Test public void testReportWithAllCleanableInstances() { // given prepareDecisionInstances(DECISION_DEFINITION_KEY, -6, 5, 10); // when List<CleanableHistoricDecisionInstanceReportResult> reportResults = historyService.createCleanableHistoricDecisionInstanceReport().list(); long count = historyService.createCleanableHistoricDecisionInstanceReport().count(); // then assertEquals(1, reportResults.size()); assertEquals(1, count); checkResultNumbers(reportResults.get(0), 10, 10); }
@Test public void testQueryCompact() { given() .queryParam("compact", true) .then() .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .get(HISTORIC_REPORT_URL); verify(historicDecisionInstanceReport).compact(); verify(historicDecisionInstanceReport).list(); verifyNoMoreInteractions(historicDecisionInstanceReport); }
@Test public void testQueryByDefinitionId() { given() .queryParam("decisionDefinitionIdIn", EXAMPLE_DD_ID + "," + ANOTHER_EXAMPLE_DD_ID) .then() .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .get(HISTORIC_REPORT_URL); verify(historicDecisionInstanceReport).decisionDefinitionIdIn(EXAMPLE_DD_ID, ANOTHER_EXAMPLE_DD_ID); verify(historicDecisionInstanceReport).list(); verifyNoMoreInteractions(historicDecisionInstanceReport); }
@Test public void testQueryByDefinitionKey() { given() .queryParam("decisionDefinitionKeyIn", EXAMPLE_DD_KEY + "," + ANOTHER_EXAMPLE_DD_KEY) .then() .expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when() .get(HISTORIC_REPORT_URL); verify(historicDecisionInstanceReport).decisionDefinitionKeyIn(EXAMPLE_DD_KEY, ANOTHER_EXAMPLE_DD_KEY); verify(historicDecisionInstanceReport).list(); verifyNoMoreInteractions(historicDecisionInstanceReport); }
@Override public CountResultDto getCleanableHistoricDecisionInstanceReportCount(UriInfo uriInfo) { CleanableHistoricDecisionInstanceReportDto queryDto = new CleanableHistoricDecisionInstanceReportDto(objectMapper, uriInfo.getQueryParameters()); queryDto.setObjectMapper(objectMapper); CleanableHistoricDecisionInstanceReport query = queryDto.toQuery(processEngine); long count = query.count(); CountResultDto result = new CountResultDto(); result.setCount(count); return result; } }
@Override protected void applySortBy(CleanableHistoricDecisionInstanceReport query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) { if (sortBy.equals(SORT_BY_FINISHED_VALUE)) { query.orderByFinished(); } } }
@Test public void testReportByInvalidDecisionDefinitionId() { CleanableHistoricDecisionInstanceReport report = historyService.createCleanableHistoricDecisionInstanceReport(); try { report.decisionDefinitionIdIn(null); fail("Expected NotValidException"); } catch (NotValidException e) { // expected } try { report.decisionDefinitionIdIn("abc", null, "def"); fail("Expected NotValidException"); } catch (NotValidException e) { // expected } }
@Test public void testReportByInvalidDecisionDefinitionKey() { CleanableHistoricDecisionInstanceReport report = historyService.createCleanableHistoricDecisionInstanceReport(); try { report.decisionDefinitionKeyIn(null); fail("Expected NotValidException"); } catch (NotValidException e) { // expected } try { report.decisionDefinitionKeyIn("abc", null, "def"); fail("Expected NotValidException"); } catch (NotValidException e) { // expected } }
@Test public void testReportTenantIdInWithAuthenticatedTenants() { // given testRule.deployForTenant(TENANT_ONE, DMN_MODEL); testRule.deployForTenant(TENANT_TWO, DMN_MODEL); prepareDecisionInstances(DECISION_DEFINITION_KEY, -6, 5, 10, TENANT_ONE); prepareDecisionInstances(DECISION_DEFINITION_KEY, -6, 5, 10, TENANT_TWO); identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); // when List<CleanableHistoricDecisionInstanceReportResult> reportResultsOne = historyService.createCleanableHistoricDecisionInstanceReport().tenantIdIn(TENANT_ONE).list(); List<CleanableHistoricDecisionInstanceReportResult> reportResultsTwo = historyService.createCleanableHistoricDecisionInstanceReport().tenantIdIn(TENANT_TWO).list(); // then assertEquals(1, reportResultsOne.size()); assertEquals(TENANT_ONE, reportResultsOne.get(0).getTenantId()); assertEquals(0, reportResultsTwo.size()); }