public static HistoricExternalTaskLog createMockHistoricExternalTaskLog(String tenantId) { HistoricExternalTaskLog mock = mock(HistoricExternalTaskLog.class); when(mock.getId()).thenReturn(EXAMPLE_HISTORIC_EXTERNAL_TASK_LOG_ID); when(mock.getTimestamp()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HISTORIC_EXTERNAL_TASK_LOG_TIMESTAMP)); when(mock.getRemovalTime()).thenReturn(DateTimeUtil.parseDate(EXAMPLE_HISTORIC_EXTERNAL_TASK_LOG_REMOVAL_TIME));
@Test public void testQueryById() { // given startExternalTaskProcesses(2); String logId = retrieveFirstHistoricExternalTaskLog().getId(); // when HistoricExternalTaskLog log = historyService .createHistoricExternalTaskLogQuery() .logId(logId) .singleResult(); // then assertNotNull(log); assertThat(log.getId(), is(logId)); }
@Test public void testQueryByExecutionIds() { // given startExternalTaskProcesses(2); HistoricExternalTaskLog taskLog = retrieveFirstHistoricExternalTaskLog(); // when HistoricExternalTaskLog log = historyService .createHistoricExternalTaskLogQuery() .executionIdIn(taskLog.getExecutionId()) .singleResult(); // then assertNotNull(log); assertThat(log.getId(), is(taskLog.getId())); }
@Test public void testGetErrorDetailsAuthenticatedTenant() { // given identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); String failedHistoricExternalTaskLogId = historyService .createHistoricExternalTaskLogQuery() .failureLog() .tenantIdIn(TENANT_ONE) .singleResult() .getId(); // when String stacktrace = historyService.getHistoricExternalTaskLogErrorDetails(failedHistoricExternalTaskLogId); // then assertThat(stacktrace, is(notNullValue())); assertThat(stacktrace, is(ERROR_DETAILS)); }
@Test public void testGetErrorDetailsNoAuthenticatedTenants() { // given identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); String failedHistoricExternalTaskLogId = historyService .createHistoricExternalTaskLogQuery() .failureLog() .tenantIdIn(TENANT_ONE) .singleResult() .getId(); identityService.clearAuthentication(); identityService.setAuthentication("user", null, null); try { // when historyService.getHistoricExternalTaskLogErrorDetails(failedHistoricExternalTaskLogId); fail("Exception expected: It should not be possible to retrieve the error details"); } catch (ProcessEngineException e) { // then String errorMessage = e.getMessage(); assertThat(errorMessage.contains("Cannot get the historic external task log "), is(true)); assertThat(errorMessage.contains(failedHistoricExternalTaskLogId), is(true)); assertThat(errorMessage.contains("because it belongs to no authenticated tenant."), is(true)); } }
@Test public void testGetErrorDetailsAuthenticatedTenants() { // given identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE, TENANT_TWO)); String logIdTenant1 = historyService .createHistoricExternalTaskLogQuery() .failureLog() .tenantIdIn(TENANT_ONE) .singleResult() .getId(); String logIdTenant2 = historyService .createHistoricExternalTaskLogQuery() .failureLog() .tenantIdIn(TENANT_ONE) .singleResult() .getId(); // when String stacktrace1 = historyService.getHistoricExternalTaskLogErrorDetails(logIdTenant1); String stacktrace2 = historyService.getHistoricExternalTaskLogErrorDetails(logIdTenant2); // then assertThat(stacktrace1, is(notNullValue())); assertThat(stacktrace1, is(ERROR_DETAILS)); assertThat(stacktrace2, is(notNullValue())); assertThat(stacktrace2, is(ERROR_DETAILS)); }
public void testGetErrorDetailsWithHistoryReadPermissionOnProcessAnyDefinition() { // given startThreeProcessInstancesDeleteOneAndCompleteTwoWithFailure(); createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_HISTORY); String failedHistoricExternalTaskLogId = historyService .createHistoricExternalTaskLogQuery() .failureLog() .list() .get(0) .getId(); // when String stacktrace = historyService.getHistoricExternalTaskLogErrorDetails(failedHistoricExternalTaskLogId); // then assertNotNull(stacktrace); assertEquals(ERROR_DETAILS, stacktrace); }
public void testGetErrorDetailsWithHistoryReadPermissionOnProcessDefinition() { // given startThreeProcessInstancesDeleteOneAndCompleteTwoWithFailure(); createGrantAuthorization(PROCESS_DEFINITION, DEFAULT_PROCESS_KEY, userId, READ_HISTORY); String failedHistoricExternalTaskLogId = historyService .createHistoricExternalTaskLogQuery() .failureLog() .list() .get(0) .getId(); // when String stacktrace = historyService.getHistoricExternalTaskLogErrorDetails(failedHistoricExternalTaskLogId); // then assertNotNull(stacktrace); assertEquals(ERROR_DETAILS, stacktrace); }
@Test public void testErrorDetailsWithTwoDifferentErrorsThrown() { // given ExternalTask task = startExternalTaskProcess(); String firstErrorDetails = "Dummy error details!"; String secondErrorDetails = ERROR_DETAILS; reportExternalTaskFailure(task.getId(), ERROR_MESSAGE, firstErrorDetails); ensureEnoughTimePassedByForTimestampOrdering(); reportExternalTaskFailure(task.getId(), ERROR_MESSAGE, secondErrorDetails); // when List<HistoricExternalTaskLog> list = historyService .createHistoricExternalTaskLogQuery() .failureLog() .orderByTimestamp() .asc() .list(); String firstFailedLogId = list.get(0).getId(); String secondFailedLogId = list.get(1).getId(); // then String stacktrace1 = historyService.getHistoricExternalTaskLogErrorDetails(firstFailedLogId); String stacktrace2 = historyService.getHistoricExternalTaskLogErrorDetails(secondFailedLogId); assertNotNull(stacktrace1); assertNotNull(stacktrace2); assertEquals(firstErrorDetails, stacktrace1); assertEquals(secondErrorDetails, stacktrace2); }
@Test public void testErrorDetails() { // given ExternalTask task = startExternalTaskProcess(); reportExternalTaskFailure(task.getId()); // when String failedHistoricExternalTaskLogId = historyService .createHistoricExternalTaskLogQuery() .failureLog() .singleResult() .getId(); // then String stacktrace = historyService.getHistoricExternalTaskLogErrorDetails(failedHistoricExternalTaskLogId); assertNotNull(stacktrace); assertEquals(ERROR_DETAILS, stacktrace); }
public static HistoricExternalTaskLogDto fromHistoricExternalTaskLog(HistoricExternalTaskLog historicExternalTaskLog) { HistoricExternalTaskLogDto result = new HistoricExternalTaskLogDto(); result.id = historicExternalTaskLog.getId(); result.timestamp = historicExternalTaskLog.getTimestamp(); result.removalTime = historicExternalTaskLog.getRemovalTime();
public static HistoricExternalTaskLogDto fromHistoricExternalTaskLog(HistoricExternalTaskLog historicExternalTaskLog) { HistoricExternalTaskLogDto result = new HistoricExternalTaskLogDto(); result.id = historicExternalTaskLog.getId(); result.timestamp = historicExternalTaskLog.getTimestamp(); result.removalTime = historicExternalTaskLog.getRemovalTime();
public void testGetErrorDetailsWithoutAuthorization() { // given startThreeProcessInstancesDeleteOneAndCompleteTwoWithFailure(); disableAuthorization(); String failedHistoricExternalTaskLogId = historyService .createHistoricExternalTaskLogQuery() .failureLog() .list() .get(0) .getId(); enableAuthorization(); try { // when String stacktrace = historyService.getHistoricExternalTaskLogErrorDetails(failedHistoricExternalTaskLogId); fail("Exception expected: It should not be possible to retrieve the error details"); } catch (AuthorizationException e) { // then String exceptionMessage = e.getMessage(); assertTextPresent(userId, exceptionMessage); assertTextPresent(READ_HISTORY.getName(), exceptionMessage); assertTextPresent(DEFAULT_PROCESS_KEY, exceptionMessage); assertTextPresent(PROCESS_DEFINITION.resourceName(), exceptionMessage); } }
protected void assertHistoricLogPropertiesAreProperlySet(ExternalTask task, HistoricExternalTaskLog log) { assertNotNull(log); assertNotNull(log.getId()); assertNotNull(log.getTimestamp()); assertEquals(task.getId(), log.getExternalTaskId()); assertEquals(task.getActivityId(), log.getActivityId()); assertEquals(task.getActivityInstanceId(), log.getActivityInstanceId()); assertEquals(task.getTopicName(), log.getTopicName()); assertEquals(task.getRetries(), log.getRetries()); assertEquals(task.getExecutionId(), log.getExecutionId()); assertEquals(task.getProcessInstanceId(), log.getProcessInstanceId()); assertEquals(task.getProcessDefinitionId(), log.getProcessDefinitionId()); assertEquals(task.getProcessDefinitionKey(), log.getProcessDefinitionKey()); assertEquals(task.getPriority(), log.getPriority()); }
@Test public void testQueryById() { // given startExternalTaskProcesses(2); String logId = retrieveFirstHistoricExternalTaskLog().getId(); // when HistoricExternalTaskLog log = historyService .createHistoricExternalTaskLogQuery() .logId(logId) .singleResult(); // then assertNotNull(log); assertThat(log.getId(), is(logId)); }
@Test public void testGetErrorDetailsAuthenticatedTenant() { // given identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE)); String failedHistoricExternalTaskLogId = historyService .createHistoricExternalTaskLogQuery() .failureLog() .tenantIdIn(TENANT_ONE) .singleResult() .getId(); // when String stacktrace = historyService.getHistoricExternalTaskLogErrorDetails(failedHistoricExternalTaskLogId); // then assertThat(stacktrace, is(notNullValue())); assertThat(stacktrace, is(ERROR_DETAILS)); }
@Test public void testQueryByExecutionIds() { // given startExternalTaskProcesses(2); HistoricExternalTaskLog taskLog = retrieveFirstHistoricExternalTaskLog(); // when HistoricExternalTaskLog log = historyService .createHistoricExternalTaskLogQuery() .executionIdIn(taskLog.getExecutionId()) .singleResult(); // then assertNotNull(log); assertThat(log.getId(), is(taskLog.getId())); }
public void testGetErrorDetailsWithHistoryReadPermissionOnProcessDefinition() { // given startThreeProcessInstancesDeleteOneAndCompleteTwoWithFailure(); createGrantAuthorization(PROCESS_DEFINITION, DEFAULT_PROCESS_KEY, userId, READ_HISTORY); String failedHistoricExternalTaskLogId = historyService .createHistoricExternalTaskLogQuery() .failureLog() .list() .get(0) .getId(); // when String stacktrace = historyService.getHistoricExternalTaskLogErrorDetails(failedHistoricExternalTaskLogId); // then assertNotNull(stacktrace); assertEquals(ERROR_DETAILS, stacktrace); }
public void testGetErrorDetailsWithHistoryReadPermissionOnProcessAnyDefinition() { // given startThreeProcessInstancesDeleteOneAndCompleteTwoWithFailure(); createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_HISTORY); String failedHistoricExternalTaskLogId = historyService .createHistoricExternalTaskLogQuery() .failureLog() .list() .get(0) .getId(); // when String stacktrace = historyService.getHistoricExternalTaskLogErrorDetails(failedHistoricExternalTaskLogId); // then assertNotNull(stacktrace); assertEquals(ERROR_DETAILS, stacktrace); }
protected void assertHistoricLogPropertiesAreProperlySet(ExternalTask task, HistoricExternalTaskLog log) { assertNotNull(log); assertNotNull(log.getId()); assertNotNull(log.getTimestamp()); assertEquals(task.getId(), log.getExternalTaskId()); assertEquals(task.getActivityId(), log.getActivityId()); assertEquals(task.getActivityInstanceId(), log.getActivityInstanceId()); assertEquals(task.getTopicName(), log.getTopicName()); assertEquals(task.getRetries(), log.getRetries()); assertEquals(task.getExecutionId(), log.getExecutionId()); assertEquals(task.getProcessInstanceId(), log.getProcessInstanceId()); assertEquals(task.getProcessDefinitionId(), log.getProcessDefinitionId()); assertEquals(task.getProcessDefinitionKey(), log.getProcessDefinitionKey()); assertEquals(task.getPriority(), log.getPriority()); }