org.camunda.bpm.engine.ManagementService Java Examples

The following examples show how to use org.camunda.bpm.engine.ManagementService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockedProcessEngineProvider.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void mockServices(ProcessEngine engine) {
  RepositoryService repoService = mock(RepositoryService.class);
  IdentityService identityService = mock(IdentityService.class);
  TaskService taskService = mock(TaskService.class);
  RuntimeService runtimeService = mock(RuntimeService.class);
  FormService formService = mock(FormService.class);
  HistoryService historyService = mock(HistoryService.class);
  ManagementService managementService = mock(ManagementService.class);
  CaseService caseService = mock(CaseService.class);
  FilterService filterService = mock(FilterService.class);
  ExternalTaskService externalTaskService = mock(ExternalTaskService.class);

  when(engine.getRepositoryService()).thenReturn(repoService);
  when(engine.getIdentityService()).thenReturn(identityService);
  when(engine.getTaskService()).thenReturn(taskService);
  when(engine.getRuntimeService()).thenReturn(runtimeService);
  when(engine.getFormService()).thenReturn(formService);
  when(engine.getHistoryService()).thenReturn(historyService);
  when(engine.getManagementService()).thenReturn(managementService);
  when(engine.getCaseService()).thenReturn(caseService);
  when(engine.getFilterService()).thenReturn(filterService);
  when(engine.getExternalTaskService()).thenReturn(externalTaskService);
}
 
Example #2
Source File: MockedProcessEngineProvider.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void mockServices(ProcessEngine engine) {
  RepositoryService repoService = mock(RepositoryService.class);
  IdentityService identityService = mock(IdentityService.class);
  TaskService taskService = mock(TaskService.class);
  RuntimeService runtimeService = mock(RuntimeService.class);
  FormService formService = mock(FormService.class);
  HistoryService historyService = mock(HistoryService.class);
  ManagementService managementService = mock(ManagementService.class);
  CaseService caseService = mock(CaseService.class);
  FilterService filterService = mock(FilterService.class);
  ExternalTaskService externalTaskService = mock(ExternalTaskService.class);

  when(engine.getRepositoryService()).thenReturn(repoService);
  when(engine.getIdentityService()).thenReturn(identityService);
  when(engine.getTaskService()).thenReturn(taskService);
  when(engine.getRuntimeService()).thenReturn(runtimeService);
  when(engine.getFormService()).thenReturn(formService);
  when(engine.getHistoryService()).thenReturn(historyService);
  when(engine.getManagementService()).thenReturn(managementService);
  when(engine.getCaseService()).thenReturn(caseService);
  when(engine.getFilterService()).thenReturn(filterService);
  when(engine.getExternalTaskService()).thenReturn(externalTaskService);
}
 
Example #3
Source File: ProcessInstanceRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public BatchDto setRetriesByProcessHistoricQueryBased(SetJobRetriesByProcessDto setJobRetriesDto) {
  HistoricProcessInstanceQueryDto queryDto = setJobRetriesDto.getHistoricProcessInstanceQuery();
  HistoricProcessInstanceQuery query = null;
  if (queryDto != null) {
    query = queryDto.toQuery(getProcessEngine());
  }

  try {
    ManagementService managementService = getProcessEngine().getManagementService();
    Batch batch = managementService.setJobRetriesAsync(
      setJobRetriesDto.getProcessInstances(),
      null,
      query,
      setJobRetriesDto.getRetries());

    return BatchDto.fromBatch(batch);
  } catch (BadUserRequestException e) {
    throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
  }
}
 
Example #4
Source File: SequentialJobAcquisitionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait, long intervalMillis, JobExecutor jobExecutor, ManagementService managementService, boolean shutdown) {

    try {
      Timer timer = new Timer();
      InteruptTask task = new InteruptTask(Thread.currentThread());
      timer.schedule(task, maxMillisToWait);
      boolean areJobsAvailable = true;
      try {
        while (areJobsAvailable && !task.isTimeLimitExceeded()) {
          Thread.sleep(intervalMillis);
          areJobsAvailable = areJobsAvailable(managementService);
        }
      } catch (InterruptedException e) {
      } finally {
        timer.cancel();
      }
      if (areJobsAvailable) {
        throw new ProcessEngineException("time limit of " + maxMillisToWait + " was exceeded");
      }

    } finally {
      if (shutdown) {
        jobExecutor.shutdown();
      }
    }
  }
 
Example #5
Source File: JobDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Before
public void setUpRuntimeData() {
  mockManagementService = mock(ManagementService.class);

  namedProcessEngine = getProcessEngine(MockProvider.EXAMPLE_PROCESS_ENGINE_NAME);
  when(namedProcessEngine.getManagementService()).thenReturn(mockManagementService);

  List<JobDefinition> mockJobDefinitions = Collections.singletonList(MockProvider.createMockJobDefinition());
  mockQuery = setUpMockJobDefinitionQuery(mockJobDefinitions);

  mockSuspensionStateSelectBuilder = mock(UpdateJobDefinitionSuspensionStateSelectBuilder.class);
  when(mockManagementService.updateJobDefinitionSuspensionState()).thenReturn(mockSuspensionStateSelectBuilder);

  mockSuspensionStateBuilder = mock(UpdateJobDefinitionSuspensionStateTenantBuilder.class);
  when(mockSuspensionStateSelectBuilder.byJobDefinitionId(anyString())).thenReturn(mockSuspensionStateBuilder);
  when(mockSuspensionStateSelectBuilder.byProcessDefinitionId(anyString())).thenReturn(mockSuspensionStateBuilder);
  when(mockSuspensionStateSelectBuilder.byProcessDefinitionKey(anyString())).thenReturn(mockSuspensionStateBuilder);
}
 
Example #6
Source File: ExternalTaskUserOperationLogTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@After
public void removeAllRunningAndHistoricBatches() {
  HistoryService historyService = rule.getHistoryService();
  ManagementService managementService = rule.getManagementService();
  for (Batch batch : managementService.createBatchQuery().list()) {
    managementService.deleteBatch(batch.getId(), true);
  }
  // remove history of completed batches
  for (HistoricBatch historicBatch : historyService.createHistoricBatchQuery().list()) {
    historyService.deleteHistoricBatch(historicBatch.getId());
  }
}
 
Example #7
Source File: BatchHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void setRetries(Batch batch, int count, int retries) {
  List<Job> jobs = getExecutionJobs(batch);
  assertTrue(jobs.size() >= count);

  ManagementService managementService = getManagementService();
  for (int i = 0; i < count; i++) {
    managementService.setJobRetries(jobs.get(i).getId(), retries);
  }

}
 
Example #8
Source File: MigrationHistoricVariablesTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void executeJob(Job job) {
  ManagementService managementService = rule.getManagementService();

  while (job != null && job.getRetries() > 0) {
    try {
      managementService.executeJob(job.getId());
    }
    catch (Exception e) {
      // ignore
    }

    job = managementService.createJobQuery().jobId(job.getId()).singleResult();
  }
}
 
Example #9
Source File: JobDefinitionResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public JobDefinitionDto getJobDefinition() {
  ManagementService managementService = engine.getManagementService();
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().jobDefinitionId(jobDefinitionId).singleResult();

  if (jobDefinition == null) {
    throw new InvalidRequestException(Status.NOT_FOUND, "Job Definition with id " + jobDefinitionId + " does not exist");
  }

  return JobDefinitionDto.fromJobDefinition(jobDefinition);
}
 
Example #10
Source File: TimerEventFactory.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void trigger(String processInstanceId) {
  ManagementService managementService = engine.getManagementService();
  Job timerJob = managementService.createJobQuery().processInstanceId(processInstanceId).activityId(activityId).singleResult();

  if (timerJob == null) {
    throw new ProcessEngineException("No job for this event found in context of process instance " + processInstanceId);
  }

  managementService.executeJob(timerJob.getId());
}
 
Example #11
Source File: BatchHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Remove all batches and historic batches. Usually called in {@link org.junit.After} method.
 */
public void removeAllRunningAndHistoricBatches() {
  HistoryService historyService = getHistoryService();
  ManagementService managementService = getManagementService();

  for (Batch batch : managementService.createBatchQuery().list()) {
    managementService.deleteBatch(batch.getId(), true);
  }

  // remove history of completed batches
  for (HistoricBatch historicBatch : historyService.createHistoricBatchQuery().list()) {
    historyService.deleteHistoricBatch(historicBatch.getId());
  }

}
 
Example #12
Source File: MigrationBoundaryEventsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void executeJob(Job job) {
  ManagementService managementService = rule.getManagementService();

  while (job != null && job.getRetries() > 0) {
    try {
      managementService.executeJob(job.getId());
    }
    catch (Exception e) {
      // ignore
    }

    job = managementService.createJobQuery().jobId(job.getId()).singleResult();
  }
}
 
Example #13
Source File: MigrationRemoveBoundaryEventsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void executeJob(Job job) {
  ManagementService managementService = rule.getManagementService();

  while (job != null && job.getRetries() > 0) {
    try {
      managementService.executeJob(job.getId());
    }
    catch (Exception e) {
      // ignore
    }

    job = managementService.createJobQuery().jobId(job.getId()).singleResult();
  }
}
 
Example #14
Source File: BatchHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected ManagementService getManagementService() {
  if (engineRule != null) {
    return engineRule.getManagementService();
  }
  else {
    return testCase.getProcessEngine().getManagementService();
  }
}
 
Example #15
Source File: HistoricBatchQueryAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void removeAllRunningAndHistoricBatches() {
  HistoryService historyService = engineRule.getHistoryService();
  ManagementService managementService = engineRule.getManagementService();

  for (Batch batch : managementService.createBatchQuery().list()) {
    managementService.deleteBatch(batch.getId(), true);
  }

  // remove history of completed batches
  for (HistoricBatch historicBatch : historyService.createHistoricBatchQuery().list()) {
    historyService.deleteHistoricBatch(historicBatch.getId());
  }
}
 
Example #16
Source File: SequentialJobAcquisitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public boolean areJobsAvailable(ManagementService managementService) {
  return !managementService
    .createJobQuery()
    .executable()
    .list()
    .isEmpty();
}
 
Example #17
Source File: HistoryCleanupOnEngineBootstrapTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecreaseNumberOfHistoryCleanupJobs() {
  // given
  // create history cleanup job
  ProcessEngine engine = ProcessEngineConfiguration
    .createProcessEngineConfigurationFromResource("org/camunda/bpm/engine/test/history/history-cleanup-parallelism-default.camunda.cfg.xml")
    .buildProcessEngine();

  // assume
  ManagementService managementService = engine.getManagementService();
  assertEquals(4, managementService.createJobQuery().list().size());

  engine.close();

  // when
  engine = ProcessEngineConfiguration
  .createProcessEngineConfigurationFromResource("org/camunda/bpm/engine/test/history/history-cleanup-parallelism-less.camunda.cfg.xml")
    .buildProcessEngine();

  // then
  // reconfigure history cleanup job
  managementService = engine.getManagementService();
  assertEquals(1, managementService.createJobQuery().list().size());

  Job job = managementService.createJobQuery().singleResult();
  assertEquals(0, getHistoryCleanupJobHandlerConfiguration(job).getMinuteFrom());
  assertEquals(59, getHistoryCleanupJobHandlerConfiguration(job).getMinuteTo());

  closeProcessEngine(engine);
}
 
Example #18
Source File: ProcessDefinitionResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public List<StatisticsResultDto> getActivityStatistics(Boolean includeFailedJobs, Boolean includeIncidents, String includeIncidentsForType) {
  if (includeIncidents != null && includeIncidentsForType != null) {
    throw new InvalidRequestException(Status.BAD_REQUEST, "Only one of the query parameter includeIncidents or includeIncidentsForType can be set.");
  }

  ManagementService mgmtService = engine.getManagementService();
  ActivityStatisticsQuery query = mgmtService.createActivityStatisticsQuery(processDefinitionId);

  if (includeFailedJobs != null && includeFailedJobs) {
    query.includeFailedJobs();
  }

  if (includeIncidents != null && includeIncidents) {
    query.includeIncidents();
  } else if (includeIncidentsForType != null) {
    query.includeIncidentsForType(includeIncidentsForType);
  }

  List<ActivityStatistics> queryResults = query.unlimitedList();

  List<StatisticsResultDto> results = new ArrayList<>();
  for (ActivityStatistics queryResult : queryResults) {
    StatisticsResultDto dto = ActivityStatisticsResultDto.fromActivityStatistics(queryResult);
    results.add(dto);
  }

  return results;
}
 
Example #19
Source File: JobResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public JobDto getJob() {
  ManagementService managementService = engine.getManagementService();
  Job job = managementService.createJobQuery().jobId(jobId).singleResult();

  if (job == null) {
    throw new InvalidRequestException(Status.NOT_FOUND, "Job with id " + jobId + " does not exist");
  }

  return JobDto.fromJob(job);
}
 
Example #20
Source File: ProcessDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public List<StatisticsResultDto> getStatistics(Boolean includeFailedJobs, Boolean includeRootIncidents, Boolean includeIncidents, String includeIncidentsForType) {
  if (includeIncidents != null && includeIncidentsForType != null) {
    throw new InvalidRequestException(Status.BAD_REQUEST, "Only one of the query parameter includeIncidents or includeIncidentsForType can be set.");
  }

  if (includeIncidents != null && includeRootIncidents != null) {
    throw new InvalidRequestException(Status.BAD_REQUEST, "Only one of the query parameter includeIncidents or includeRootIncidents can be set.");
  }

  if (includeRootIncidents != null && includeIncidentsForType != null) {
    throw new InvalidRequestException(Status.BAD_REQUEST, "Only one of the query parameter includeRootIncidents or includeIncidentsForType can be set.");
  }

  ManagementService mgmtService = getProcessEngine().getManagementService();
  ProcessDefinitionStatisticsQuery query = mgmtService.createProcessDefinitionStatisticsQuery();

  if (includeFailedJobs != null && includeFailedJobs) {
    query.includeFailedJobs();
  }

  if (includeIncidents != null && includeIncidents) {
    query.includeIncidents();
  } else if (includeIncidentsForType != null) {
    query.includeIncidentsForType(includeIncidentsForType);
  } else if (includeRootIncidents != null && includeRootIncidents) {
    query.includeRootIncidents();
  }

  List<ProcessDefinitionStatistics> queryResults = query.unlimitedList();

  List<StatisticsResultDto> results = new ArrayList<StatisticsResultDto>();
  for (ProcessDefinitionStatistics queryResult : queryResults) {
    StatisticsResultDto dto = ProcessDefinitionStatisticsResultDto.fromProcessDefinitionStatistics(queryResult);
    results.add(dto);
  }

  return results;
}
 
Example #21
Source File: TelemetryRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void configureTelemetry(TelemetryConfigurationDto dto) {
  boolean enableTelemetry = dto.isEnableTelemetry();

  ManagementService managementService = processEngine.getManagementService();

  managementService.toggleTelemetry(enableTelemetry);
}
 
Example #22
Source File: JobRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Before
public void setUpRuntimeData() {

  mockQuery = mock(JobQuery.class);
  Job mockedJob = new MockJobBuilder()
    .id(MockProvider.EXAMPLE_JOB_ID)
    .processInstanceId(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)
    .executionId(MockProvider.EXAMPLE_EXECUTION_ID)
    .retries(MockProvider.EXAMPLE_JOB_RETRIES)
    .exceptionMessage(MockProvider.EXAMPLE_JOB_NO_EXCEPTION_MESSAGE)
    .failedActivityId(MockProvider.EXAMPLE_JOB_FAILED_ACTIVITY_ID)
    .dueDate(new Date())
    .priority(MockProvider.EXAMPLE_JOB_PRIORITY)
    .jobDefinitionId(MockProvider.EXAMPLE_JOB_DEFINITION_ID)
    .tenantId(MockProvider.EXAMPLE_TENANT_ID)
    .createTime(DateTimeUtil.parseDate(MockProvider.EXAMPLE_JOB_CREATE_TIME))
    .build();

  when(mockQuery.singleResult()).thenReturn(mockedJob);
  when(mockQuery.jobId(MockProvider.EXAMPLE_JOB_ID)).thenReturn(mockQuery);

  mockManagementService = mock(ManagementService.class);
  when(mockManagementService.createJobQuery()).thenReturn(mockQuery);

  mockSuspensionStateSelectBuilder = mock(UpdateJobSuspensionStateSelectBuilder.class);
  when(mockManagementService.updateJobSuspensionState()).thenReturn(mockSuspensionStateSelectBuilder);

  mockSuspensionStateBuilder = mock(UpdateJobSuspensionStateTenantBuilder.class);
  when(mockSuspensionStateSelectBuilder.byJobId(anyString())).thenReturn(mockSuspensionStateBuilder);
  when(mockSuspensionStateSelectBuilder.byJobDefinitionId(anyString())).thenReturn(mockSuspensionStateBuilder);
  when(mockSuspensionStateSelectBuilder.byProcessInstanceId(anyString())).thenReturn(mockSuspensionStateBuilder);
  when(mockSuspensionStateSelectBuilder.byProcessDefinitionId(anyString())).thenReturn(mockSuspensionStateBuilder);
  when(mockSuspensionStateSelectBuilder.byProcessDefinitionKey(anyString())).thenReturn(mockSuspensionStateBuilder);

  namedProcessEngine = getProcessEngine(MockProvider.EXAMPLE_PROCESS_ENGINE_NAME);
  when(namedProcessEngine.getManagementService()).thenReturn(mockManagementService);
}
 
Example #23
Source File: BatchRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Before
public void setUpBatchQueryMock() {
  Batch batchMock = MockProvider.createMockBatch();

  queryMock = mock(BatchQuery.class);
  when(queryMock.batchId(eq(MockProvider.EXAMPLE_BATCH_ID))).thenReturn(queryMock);
  when(queryMock.singleResult()).thenReturn(batchMock);

  managementServiceMock = mock(ManagementService.class);
  when(managementServiceMock.createBatchQuery()).thenReturn(queryMock);

  when(processEngine.getManagementService()).thenReturn(managementServiceMock);
}
 
Example #24
Source File: SetVariablesScenario.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@DescribesScenario("setVariablesScenario")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    @Override
    public void execute(ProcessEngine engine, String scenarioName) {
      RuntimeService runtimeService = engine.getRuntimeService();
      ProcessInstance processInstanceWithInitialVariables = runtimeService.createProcessInstanceQuery()
          .processDefinitionKey("asyncBeforeStartProcess_712")
          .processInstanceBusinessKey("712_ProcessIntanceExecuted")
          .singleResult();
      ManagementService managementService = engine.getManagementService();
      Job firstJob = managementService.createJobQuery()
          .processDefinitionKey("asyncBeforeStartProcess_712")
          .processInstanceId(processInstanceWithInitialVariables.getId())
          .singleResult();
      try {
        managementService.executeJob(firstJob.getId());
      } catch (Exception e) {
        // ignore
      }

      ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
          .processDefinitionKey("asyncBeforeStartProcess_712")
          .processInstanceBusinessKey("7120_ProcessIntanceWithoutExecute")
          .singleResult();
      runtimeService.setVariable(processInstance.getId(), "foo", "value");
      runtimeService.setVariableLocal(processInstance.getId(), "local", "foo1");
    }
  };
}
 
Example #25
Source File: SpringProcessEngineServicesConfiguration.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Bean(name = "managementService")
@Override
public ManagementService getManagementService() {
  return processEngine.getManagementService();
}
 
Example #26
Source File: TelemetryRestServiceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Before
public void setupMocks() {
  managementServiceMock = mock(ManagementService.class);
  when(processEngine.getManagementService()).thenReturn(managementServiceMock);
}
 
Example #27
Source File: ProcessEngineRestServiceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpRuntimeData() {
  namedProcessEngine = getProcessEngine(EXAMPLE_ENGINE_NAME);
  mockRepoService = mock(RepositoryService.class);
  mockRuntimeService = mock(RuntimeService.class);
  mockTaskService = mock(TaskService.class);
  mockIdentityService = mock(IdentityService.class);
  mockManagementService = mock(ManagementService.class);
  mockHistoryService = mock(HistoryService.class);
  mockCaseService = mock(CaseService.class);
  mockFilterService = mock(FilterService.class);
  mockExternalTaskService = mock(ExternalTaskService.class);

  when(namedProcessEngine.getRepositoryService()).thenReturn(mockRepoService);
  when(namedProcessEngine.getRuntimeService()).thenReturn(mockRuntimeService);
  when(namedProcessEngine.getTaskService()).thenReturn(mockTaskService);
  when(namedProcessEngine.getIdentityService()).thenReturn(mockIdentityService);
  when(namedProcessEngine.getManagementService()).thenReturn(mockManagementService);
  when(namedProcessEngine.getHistoryService()).thenReturn(mockHistoryService);
  when(namedProcessEngine.getCaseService()).thenReturn(mockCaseService);
  when(namedProcessEngine.getFilterService()).thenReturn(mockFilterService);
  when(namedProcessEngine.getExternalTaskService()).thenReturn(mockExternalTaskService);

  createProcessDefinitionMock();
  createProcessInstanceMock();
  createTaskMock();
  createIdentityMocks();
  createExecutionMock();
  createVariableInstanceMock();
  createJobDefinitionMock();
  createIncidentMock();
  createDeploymentMock();
  createMessageCorrelationBuilderMock();
  createCaseDefinitionMock();
  createCaseInstanceMock();
  createCaseExecutionMock();
  createFilterMock();
  createExternalTaskMock();

  createHistoricActivityInstanceMock();
  createHistoricProcessInstanceMock();
  createHistoricVariableInstanceMock();
  createHistoricActivityStatisticsMock();
  createHistoricDetailMock();
  createHistoricTaskInstanceMock();
  createHistoricIncidentMock();
  createHistoricJobLogMock();
  createHistoricExternalTaskLogMock();
}
 
Example #28
Source File: TaskRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpRuntimeData() {
  taskServiceMock = mock(TaskService.class);
  when(processEngine.getTaskService()).thenReturn(taskServiceMock);

  mockTask = MockProvider.createMockTask();
  mockQuery = mock(TaskQuery.class);
  when(mockQuery.initializeFormKeys()).thenReturn(mockQuery);
  when(mockQuery.taskId(anyString())).thenReturn(mockQuery);
  when(mockQuery.singleResult()).thenReturn(mockTask);
  when(taskServiceMock.createTaskQuery()).thenReturn(mockQuery);

  List<IdentityLink> identityLinks = new ArrayList<>();
  mockAssigneeIdentityLink = MockProvider.createMockUserAssigneeIdentityLink();
  identityLinks.add(mockAssigneeIdentityLink);
  mockOwnerIdentityLink = MockProvider.createMockUserOwnerIdentityLink();
  identityLinks.add(mockOwnerIdentityLink);
  mockCandidateGroupIdentityLink = MockProvider.createMockCandidateGroupIdentityLink();
  identityLinks.add(mockCandidateGroupIdentityLink);
  mockCandidateGroup2IdentityLink = MockProvider.createAnotherMockCandidateGroupIdentityLink();
  identityLinks.add(mockCandidateGroup2IdentityLink);
  when(taskServiceMock.getIdentityLinksForTask(EXAMPLE_TASK_ID)).thenReturn(identityLinks);

  mockTaskComment = MockProvider.createMockTaskComment();
  when(taskServiceMock.getTaskComment(EXAMPLE_TASK_ID, EXAMPLE_TASK_COMMENT_ID)).thenReturn(mockTaskComment);
  mockTaskComments = MockProvider.createMockTaskComments();
  when(taskServiceMock.getTaskComments(EXAMPLE_TASK_ID)).thenReturn(mockTaskComments);
  when(taskServiceMock.createComment(EXAMPLE_TASK_ID, null, EXAMPLE_TASK_COMMENT_FULL_MESSAGE)).thenReturn(mockTaskComment);

  mockTaskAttachment = MockProvider.createMockTaskAttachment();
  when(taskServiceMock.getTaskAttachment(EXAMPLE_TASK_ID, EXAMPLE_TASK_ATTACHMENT_ID)).thenReturn(mockTaskAttachment);
  mockTaskAttachments = MockProvider.createMockTaskAttachments();
  when(taskServiceMock.getTaskAttachments(EXAMPLE_TASK_ID)).thenReturn(mockTaskAttachments);
  when(taskServiceMock.createAttachment(anyString(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(mockTaskAttachment);
  when(taskServiceMock.createAttachment(anyString(), anyString(), anyString(), anyString(), anyString(), any(InputStream.class))).thenReturn(mockTaskAttachment);
  when(taskServiceMock.getTaskAttachmentContent(EXAMPLE_TASK_ID, EXAMPLE_TASK_ATTACHMENT_ID)).thenReturn(new ByteArrayInputStream(createMockByteData()));

  formServiceMock = mock(FormService.class);
  when(processEngine.getFormService()).thenReturn(formServiceMock);
  TaskFormData mockFormData = MockProvider.createMockTaskFormData();
  when(formServiceMock.getTaskFormData(anyString())).thenReturn(mockFormData);

  VariableMap variablesMock = MockProvider.createMockFormVariables();
  when(formServiceMock.getTaskFormVariables(eq(EXAMPLE_TASK_ID), Matchers.<Collection<String>>any(), anyBoolean())).thenReturn(variablesMock);

  repositoryServiceMock = mock(RepositoryService.class);
  when(processEngine.getRepositoryService()).thenReturn(repositoryServiceMock);
  ProcessDefinition mockDefinition = MockProvider.createMockDefinition();
  when(repositoryServiceMock.getProcessDefinition(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).thenReturn(mockDefinition);

  managementServiceMock = mock(ManagementService.class);
  when(processEngine.getManagementService()).thenReturn(managementServiceMock);
  when(managementServiceMock.getProcessApplicationForDeployment(MockProvider.EXAMPLE_DEPLOYMENT_ID)).thenReturn(MockProvider.EXAMPLE_PROCESS_APPLICATION_NAME);
  when(managementServiceMock.getHistoryLevel()).thenReturn(ProcessEngineConfigurationImpl.HISTORYLEVEL_FULL);

  HistoryService historyServiceMock = mock(HistoryService.class);
  when(processEngine.getHistoryService()).thenReturn(historyServiceMock);
  historicTaskInstanceQueryMock = mock(HistoricTaskInstanceQuery.class);
  when(historyServiceMock.createHistoricTaskInstanceQuery()).thenReturn(historicTaskInstanceQueryMock);
  when(historicTaskInstanceQueryMock.taskId(eq(EXAMPLE_TASK_ID))).thenReturn(historicTaskInstanceQueryMock);
  HistoricTaskInstance historicTaskInstanceMock = createMockHistoricTaskInstance();
  when(historicTaskInstanceQueryMock.singleResult()).thenReturn(historicTaskInstanceMock);

  // replace the runtime container delegate & process application service with a mock

  ProcessApplicationService processApplicationService = mock(ProcessApplicationService.class);
  ProcessApplicationInfo appMock = MockProvider.createMockProcessApplicationInfo();
  when(processApplicationService.getProcessApplicationInfo(MockProvider.EXAMPLE_PROCESS_APPLICATION_NAME)).thenReturn(appMock);

  RuntimeContainerDelegate delegate = mock(RuntimeContainerDelegate.class);
  when(delegate.getProcessApplicationService()).thenReturn(processApplicationService);
  RuntimeContainerDelegate.INSTANCE.set(delegate);
}
 
Example #29
Source File: RestartProcessIntanceWithInitialVariablesTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldRestartWithInitialVariablesJobExecutedAndSetVariablesIn713() {
  // given
  String businessKey = "7120_ProcessIntanceWithoutExecuteAndSetVariables";
  ProcessInstance processInstanceWithInitialVariables = runtimeService.createProcessInstanceQuery()
      .processInstanceBusinessKey(businessKey)
      .active()
      .singleResult();

  runtimeService.setVariable(processInstanceWithInitialVariables.getId(), "varIn713", "value");

  ManagementService managementService = engineRule.getManagementService();
  Job asyncJob = managementService.createJobQuery()
      .processDefinitionKey("asyncBeforeStartProcess_712")
      .processInstanceId(processInstanceWithInitialVariables.getId())
      .singleResult();
  try {
    managementService.executeJob(asyncJob.getId());
  } catch (Exception e) {
    // ignore
  }

  // assume
  HistoricVariableUpdateEventEntity detail = (HistoricVariableUpdateEventEntity) historyService
      .createHistoricDetailQuery()
      .processInstanceId(processInstanceWithInitialVariables.getId())
      .activityInstanceId(processInstanceWithInitialVariables.getId())
      .singleResult();

  assertTrue(detail.isInitial());

  runtimeService.deleteProcessInstance(processInstanceWithInitialVariables.getId(), "test");

  // when
  runtimeService.restartProcessInstances(processInstanceWithInitialVariables.getProcessDefinitionId())
    .startBeforeActivity("theTask")
    .processInstanceIds(processInstanceWithInitialVariables.getId())
    .initialSetOfVariables()
    .execute();

  ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery()
      .processInstanceBusinessKey(businessKey)
      .active()
      .singleResult();

  // then
  VariableInstance variableInstance = runtimeService.createVariableInstanceQuery()
      .processInstanceIdIn(restartedProcessInstance.getId()).singleResult();
  assertNotNull(variableInstance);
  assertEquals("initial3", variableInstance.getName());
  assertEquals("value1", variableInstance.getValue());

  HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery()
      .processInstanceId(restartedProcessInstance.getId())
      .singleResult();
  assertNotNull(historicVariable);
  assertEquals(restartedProcessInstance.getId(), historicVariable.getActivityInstanceId());

  detail = (HistoricVariableUpdateEventEntity) historyService.createHistoricDetailQuery()
      .processInstanceId(restartedProcessInstance.getId())
      .singleResult();

  assertFalse(detail.isInitial());
}
 
Example #30
Source File: AbstractProcessEngineServicesDelegate.java    From camunda-bpm-assert-scenario with Apache License 2.0 4 votes vote down vote up
public ManagementService getManagementService() {
  return processEngine.getManagementService();
}