protected void verifySingleResultFails(HistoricJobLogQuery query) { try { query.singleResult(); fail(); } catch (ProcessEngineException e) {} }
@Before public void setUpRuntimeData() { mockQuery = mock(HistoricJobLogQuery.class); HistoricJobLog mockedHistoricJobLog = MockProvider.createMockHistoricJobLog(); when(mockQuery.singleResult()).thenReturn(mockedHistoricJobLog); when(mockQuery.logId(MockProvider.EXAMPLE_HISTORIC_JOB_LOG_ID)).thenReturn(mockQuery); mockHistoryService = mock(HistoryService.class); when(mockHistoryService.createHistoricJobLogQuery()).thenReturn(mockQuery); namedProcessEngine = getProcessEngine(MockProvider.EXAMPLE_PROCESS_ENGINE_NAME); when(namedProcessEngine.getHistoryService()).thenReturn(mockHistoryService); }
public HistoricJobLogDto getHistoricJobLog() { HistoryService historyService = engine.getHistoryService(); HistoricJobLog historicJobLog = historyService .createHistoricJobLogQuery() .logId(id) .singleResult(); if (historicJobLog == null) { throw new InvalidRequestException(Status.NOT_FOUND, "Historic job log with id " + id + " does not exist"); } return HistoricJobLogDto.fromHistoricJobLog(historicJobLog); }
public HistoricJobLogDto getHistoricJobLog() { HistoryService historyService = engine.getHistoryService(); HistoricJobLog historicJobLog = historyService .createHistoricJobLogQuery() .logId(id) .singleResult(); if (historicJobLog == null) { throw new InvalidRequestException(Status.NOT_FOUND, "Historic job log with id " + id + " does not exist"); } return HistoricJobLogDto.fromHistoricJobLog(historicJobLog); }
protected void verifyQueryResults(HistoricJobLogQuery query, int countExpected) { assertEquals(countExpected, query.list().size()); assertEquals(countExpected, query.count()); if (countExpected == 1) { assertNotNull(query.singleResult()); } else if (countExpected > 1){ verifySingleResultFails(query); } else if (countExpected == 0) { assertNull(query.singleResult()); } }
@Test public void testHistoricJobLogGetIdDoesntExist() { String id = "nonExistingId"; HistoricJobLogQuery invalidQueryNonExistingHistoricJobLog = mock(HistoricJobLogQuery.class); when(mockHistoryService.createHistoricJobLogQuery().logId(id)).thenReturn(invalidQueryNonExistingHistoricJobLog); when(invalidQueryNonExistingHistoricJobLog.singleResult()).thenReturn(null); given() .pathParam("id", id) .then() .expect() .statusCode(Status.NOT_FOUND.getStatusCode()) .contentType(ContentType.JSON) .body("type", equalTo(InvalidRequestException.class.getSimpleName())) .body("message", equalTo("Historic job log with id " + id + " does not exist")) .when() .get(SINGLE_HISTORIC_JOB_LOG_RESOURCE_URL); }
@Test public void shouldNotResolveJobLog() { // given testRule.deploy(CALLED_PROCESS); repositoryService.suspendProcessDefinitionByKey(CALLED_PROCESS_KEY, true, new Date()); // when HistoricJobLog jobLog = historyService.createHistoricJobLogQuery().singleResult(); // assume assertThat(jobLog, notNullValue()); // then assertThat(jobLog.getRootProcessInstanceId(), nullValue()); // cleanup managementService.deleteJob(jobLog.getJobId()); clearJobLog(jobLog.getJobId()); }
@Test public void shouldNotResolveJobLog() { // given ClockUtil.setCurrentTime(START_DATE); testRule.deploy(CALLED_PROCESS); repositoryService.suspendProcessDefinitionByKey(CALLED_PROCESS_KEY, true, new Date(1363608000000L)); // when HistoricJobLog jobLog = historyService.createHistoricJobLogQuery().singleResult(); // assume assertThat(jobLog, notNullValue()); // then assertThat(jobLog.getRemovalTime(), nullValue()); // cleanup managementService.deleteJob(jobLog.getJobId()); clearJobLog(jobLog.getJobId()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricJobLogTest.testAsyncContinuation.bpmn20.xml"}) public void testQueryByLogId() { runtimeService.startProcessInstanceByKey("process"); String logId = historyService.createHistoricJobLogQuery().singleResult().getId(); HistoricJobLogQuery query = historyService.createHistoricJobLogQuery().logId(logId); verifyQueryResults(query, 1); }
@Test public void failToGetHistoricJobLogExceptionStacktraceNoAuthenticatedTenants() { testRule.deployForTenant(TENANT_ONE, FAILING_BPMN_PROCESS); String processInstanceId = startProcessInstance(null); String historicJobLogId = historyService.createHistoricJobLogQuery() .processInstanceId(processInstanceId).singleResult().getId(); identityService.setAuthentication("user", null, null); thrown.expect(ProcessEngineException.class); thrown.expectMessage("Cannot get the historic job log"); historyService.getHistoricJobLogExceptionStacktrace(historicJobLogId); }
public void testGetHistoricStandaloneJobLogExceptionStacktrace() { // given disableAuthorization(); repositoryService.suspendProcessDefinitionByKey(TIMER_BOUNDARY_PROCESS_KEY, true, new Date()); enableAuthorization(); String jobLogId = historyService.createHistoricJobLogQuery().singleResult().getId(); // when String stacktrace = historyService.getHistoricJobLogExceptionStacktrace(jobLogId); // then assertNull(stacktrace); deleteDeployment(deploymentId); disableAuthorization(); String jobId = managementService.createJobQuery().singleResult().getId(); managementService.deleteJob(jobId); enableAuthorization(); }
public void testQueryAfterStandaloneJob() { // given disableAuthorization(); repositoryService.suspendProcessDefinitionByKey(TIMER_BOUNDARY_PROCESS_KEY, true, new Date()); enableAuthorization(); // when HistoricJobLogQuery query = historyService.createHistoricJobLogQuery(); // then verifyQueryResults(query, 1); HistoricJobLog jobLog = query.singleResult(); assertNull(jobLog.getProcessDefinitionKey()); deleteDeployment(deploymentId); disableAuthorization(); String jobId = managementService.createJobQuery().singleResult().getId(); managementService.deleteJob(jobId); enableAuthorization(); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricJobLogTest.testAsyncContinuationWithLongId.bpmn20.xml"}) public void testSuccessfulHistoricJobLogEntryStoredForLongActivityId() { runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValue("fail", false)); Job job = managementService .createJobQuery() .singleResult(); managementService.executeJob(job.getId()); HistoricJobLog historicJob = historyService .createHistoricJobLogQuery() .successLog() .singleResult(); assertNotNull(historicJob); assertEquals("serviceTaskIdIsReallyLongAndItShouldBeMoreThan64CharsSoItWill" + "BlowAnyActivityIdColumnWhereSizeIs64OrLessSoWeAlignItTo255LikeEverywhereElse", historicJob.getActivityId()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricJobLogTest.testAsyncContinuation.bpmn20.xml"}) public void testExceptionStacktrace() { // given runtimeService.startProcessInstanceByKey("process"); String jobId = managementService.createJobQuery().singleResult().getId(); // when try { managementService.executeJob(jobId); fail(); } catch (Exception e) { // expected } // then String failedHistoricJobLogId = historyService .createHistoricJobLogQuery() .failureLog() .singleResult() .getId(); String stacktrace = historyService.getHistoricJobLogExceptionStacktrace(failedHistoricJobLogId); assertNotNull(stacktrace); assertTextPresent(FailingDelegate.EXCEPTION_MESSAGE, stacktrace); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricJobLogTest.testAsyncContinuation.bpmn20.xml"}) public void testAsyncBeforeJobHandlerType() { processEngineConfiguration.setEnsureJobDueDateNotNull(false); runtimeService.startProcessInstanceByKey("process"); Job job = managementService .createJobQuery() .singleResult(); HistoricJobLog historicJob = historyService .createHistoricJobLogQuery() .jobId(job.getId()) .singleResult(); assertNotNull(historicJob); assertNull(historicJob.getJobDueDate()); assertEquals(job.getJobDefinitionId(), historicJob.getJobDefinitionId()); assertEquals("serviceTask", historicJob.getActivityId()); assertEquals(AsyncContinuationJobHandler.TYPE, historicJob.getJobDefinitionType()); assertEquals(MessageJobDeclaration.ASYNC_BEFORE, historicJob.getJobDefinitionConfiguration()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricJobLogTest.testStartTimerEvent.bpmn20.xml"}) public void testStartTimerEventJobHandlerType() { Job job = managementService .createJobQuery() .singleResult(); HistoricJobLog historicJob = historyService .createHistoricJobLogQuery() .jobId(job.getId()) .singleResult(); assertNotNull(historicJob); assertEquals(job.getId(), historicJob.getJobId()); assertEquals(job.getJobDefinitionId(), historicJob.getJobDefinitionId()); assertEquals("theStart", historicJob.getActivityId()); assertEquals(TimerStartEventJobHandler.TYPE, historicJob.getJobDefinitionType()); assertEquals("CYCLE: 0 0/5 * * * ?", historicJob.getJobDefinitionConfiguration()); assertEquals(job.getDuedate(), historicJob.getJobDueDate()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricJobLogTest.testAsyncContinuation.bpmn20.xml"}) public void testAsyncBeforeJobHandlerTypeDueDateSet() { processEngineConfiguration.setEnsureJobDueDateNotNull(true); Date testDate = ClockTestUtil.setClockToDateWithoutMilliseconds(); runtimeService.startProcessInstanceByKey("process"); Job job = managementService .createJobQuery() .singleResult(); HistoricJobLog historicJob = historyService .createHistoricJobLogQuery() .jobId(job.getId()) .singleResult(); assertNotNull(historicJob); assertEquals(testDate, historicJob.getJobDueDate()); assertEquals(job.getJobDefinitionId(), historicJob.getJobDefinitionId()); assertEquals("serviceTask", historicJob.getActivityId()); assertEquals(AsyncContinuationJobHandler.TYPE, historicJob.getJobDefinitionType()); assertEquals(MessageJobDeclaration.ASYNC_BEFORE, historicJob.getJobDefinitionConfiguration()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricJobLogTest.testIntermediateTimerEvent.bpmn20.xml"}) public void testIntermediateTimerEventJobHandlerType() { runtimeService.startProcessInstanceByKey("process"); Job job = managementService .createJobQuery() .singleResult(); HistoricJobLog historicJob = historyService .createHistoricJobLogQuery() .jobId(job.getId()) .singleResult(); assertNotNull(historicJob); assertEquals(job.getId(), historicJob.getJobId()); assertEquals(job.getJobDefinitionId(), historicJob.getJobDefinitionId()); assertEquals("timer", historicJob.getActivityId()); assertEquals(TimerCatchIntermediateEventJobHandler.TYPE, historicJob.getJobDefinitionType()); assertEquals("DURATION: PT1M", historicJob.getJobDefinitionConfiguration()); assertEquals(job.getDuedate(), historicJob.getJobDueDate()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricJobLogTest.testBoundaryTimerEvent.bpmn20.xml"}) public void testBoundaryTimerEventJobHandlerType() { runtimeService.startProcessInstanceByKey("process"); Job job = managementService .createJobQuery() .singleResult(); HistoricJobLog historicJob = historyService .createHistoricJobLogQuery() .jobId(job.getId()) .singleResult(); assertNotNull(historicJob); assertEquals(job.getId(), historicJob.getJobId()); assertEquals(job.getJobDefinitionId(), historicJob.getJobDefinitionId()); assertEquals("timer", historicJob.getActivityId()); assertEquals(TimerExecuteNestedActivityJobHandler.TYPE, historicJob.getJobDefinitionType()); assertEquals("DURATION: PT5M", historicJob.getJobDefinitionConfiguration()); assertEquals(job.getDuedate(), historicJob.getJobDueDate()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/history/HistoricJobLogTest.testStartTimerEventInsideEventSubProcess.bpmn20.xml"}) public void testStartTimerEventInsideEventSubProcessJobHandlerType() { runtimeService.startProcessInstanceByKey("process"); Job job = managementService .createJobQuery() .singleResult(); HistoricJobLog historicJob = historyService .createHistoricJobLogQuery() .jobId(job.getId()) .singleResult(); assertNotNull(historicJob); assertEquals(job.getId(), historicJob.getJobId()); assertEquals(job.getJobDefinitionId(), historicJob.getJobDefinitionId()); assertEquals("subprocessStartEvent", historicJob.getActivityId()); assertEquals(TimerStartEventSubprocessJobHandler.TYPE, historicJob.getJobDefinitionType()); assertEquals("DURATION: PT1M", historicJob.getJobDefinitionConfiguration()); assertEquals(job.getDuedate(), historicJob.getJobDueDate()); }