org.camunda.bpm.engine.TaskService Java Examples

The following examples show how to use org.camunda.bpm.engine.TaskService. 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: ShipmentBoundaryServiceImpl.java    From Showcase with Apache License 2.0 6 votes vote down vote up
@Autowired
public ShipmentBoundaryServiceImpl(CompleteShipmentOrderTask completeShipmentOrderTask,
                                   OrganizeFlightTask organizeFlightTask,
                                   CreateInvoiceTask createInvoiceTask,
                                   ShipmentRepository shipmentRepository,
                                   InvoiceRepository invoiceRepository,
                                   FlightDepartedSentry flightDepartedSentry,
                                   FlightDeparted flightDeparted,
                                   ShipmentCaseControlService shipmentCaseControlService,
                                   ShipmentCaseEvaluator shipmentCaseEvaluator,
                                   ProcessEngine processEngine,
                                   CaseService caseService,
                                   TaskService taskService) {
    this.completeShipmentOrderTask = completeShipmentOrderTask;
    this.organizeFlightTask = organizeFlightTask;
    this.createInvoiceTask = createInvoiceTask;
    this.shipmentRepository = shipmentRepository;
    this.invoiceRepository = invoiceRepository;
    this.flightDepartedSentry = flightDepartedSentry;
    this.flightDeparted = flightDeparted;
    this.shipmentCaseControlService = shipmentCaseControlService;
    this.shipmentCaseEvaluator = shipmentCaseEvaluator;
    this.caseService = caseService;
    this.taskService = taskService;
}
 
Example #2
Source File: CompleteProcessWithUserTaskTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@ScenarioUnderTest("init.1")
public void testCompleteProcessWithUserTask() {
  //given an already started process instance
  ProcessInstance oldInstance = rule.processInstance();
  Assert.assertNotNull(oldInstance);

  //which waits on an user task
  TaskService taskService = rule.getTaskService();
  Task userTask = taskService.createTaskQuery().processInstanceId(oldInstance.getId()).singleResult();
  Assert.assertNotNull(userTask);

  //when completing the user task
  taskService.complete(userTask.getId());

  //then there exists no more tasks
  //and the process instance is also completed
  Assert.assertEquals(0, rule.taskQuery().count());
  rule.assertScenarioEnded();
}
 
Example #3
Source File: HistoricInstancePermissionsWithoutProcDefKeyScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("createProcInstancesAndOpLogs")
public static ScenarioSetup createProcInstancesAndOpLogs() {
  return (engine, scenarioName) -> {
    IdentityService identityService = engine.getIdentityService();
    for (int i = 0; i < 5; i++) {
      String processInstanceId = engine.getRuntimeService()
          .startProcessInstanceByKey("oneTaskProcess",
              "HistPermsWithoutProcDefKeyScenarioBusinessKey" + i)
          .getId();

      identityService.setAuthentication("mary02", null);

      TaskService taskService = engine.getTaskService();

      String taskId = taskService.createTaskQuery()
          .processInstanceId(processInstanceId)
          .singleResult()
          .getId();

      taskService.setAssignee(taskId, "john");

      identityService.clearAuthentication();
    }
  };
}
 
Example #4
Source File: CreateStandaloneTaskDeleteScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("createUserOperationLogEntriesForDelete")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      IdentityService identityService = engine.getIdentityService();
      identityService.setAuthentication("mary01", null);

      TaskService taskService = engine.getTaskService();

      String taskId = "myTaskForUserOperationLogDel";
      Task task = taskService.newTask(taskId);
      taskService.saveTask(task);

      identityService.clearAuthentication();
    }
  };
}
 
Example #5
Source File: SetAssigneeProcessInstanceTaskScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("createUserOperationLogEntries")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      IdentityService identityService = engine.getIdentityService();
      String processInstanceBusinessKey = "SetAssigneeProcessInstanceTaskScenario";
      engine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess_userOpLog", processInstanceBusinessKey);

      identityService.setAuthentication("mary02", null);

      TaskService taskService = engine.getTaskService();
      List<Task> list = taskService.createTaskQuery().processInstanceBusinessKey(processInstanceBusinessKey).list();
      Task task = list.get(0);
      taskService.setAssignee(task.getId(), "john");

      identityService.clearAuthentication();
    }
  };
}
 
Example #6
Source File: CreateStandaloneTaskScenario.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@DescribesScenario("createUserOperationLogEntries")
public static ScenarioSetup createUserOperationLogEntries() {
  return new ScenarioSetup() {
    public void execute(ProcessEngine engine, String scenarioName) {
      IdentityService identityService = engine.getIdentityService();
      identityService.setAuthentication("jane02", null);

      TaskService taskService = engine.getTaskService();

      String taskId = "myTaskForUserOperationLog";
      Task task = taskService.newTask(taskId);
      taskService.saveTask(task);

      identityService.clearAuthentication();
    }
  };
}
 
Example #7
Source File: BusinessProcessBeanTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testGetVariableLocal()
{
  BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
  ProcessInstance processInstance = businessProcess.startProcessByKey("businessProcessBeanTest");

  TaskService taskService = getBeanInstance(TaskService.class);
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  assertNotNull(task);

  businessProcess.startTask(task.getId());

  businessProcess.setVariableLocal("aVariableName", "aVariableValue");

  // Flushing and re-getting should retain the value (CAM-1806):
  businessProcess.flushVariableCache();
  assertTrue(businessProcess.getCachedLocalVariableMap().isEmpty());
  assertEquals("aVariableValue", businessProcess.getVariableLocal("aVariableName"));
}
 
Example #8
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 #9
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 #10
Source File: ProcessEngineRuleJunit4Test.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void ruleUsageExample() {
  RuntimeService runtimeService = engineRule.getRuntimeService();
  runtimeService.startProcessInstanceByKey("ruleUsage");

  TaskService taskService = engineRule.getTaskService();
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("My Task", task.getName());

  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example #11
Source File: ProcessEngineRuleParameterizedJunit4Test.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/test/standalone/testing/ProcessEngineRuleParameterizedJunit4Test.ruleUsageExample.bpmn20.xml")
public void ruleUsageExampleWithNamedAnnotation() {
  RuntimeService runtimeService = engineRule.getRuntimeService();
  runtimeService.startProcessInstanceByKey("ruleUsage");

  TaskService taskService = engineRule.getTaskService();
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("My Task", task.getName());

  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example #12
Source File: ProcessEngineRuleParameterizedJunit4Test.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Unnamed @Deployment annotations don't work with parameterized Unit tests
 */
@Ignore
@Test
@Deployment
public void ruleUsageExample() {
  RuntimeService runtimeService = engineRule.getRuntimeService();
  runtimeService.startProcessInstanceByKey("ruleUsage");

  TaskService taskService = engineRule.getTaskService();
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("My Task", task.getName());

  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example #13
Source File: RuntimeServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) throws Exception {
  RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
  TaskService taskService = execution.getProcessEngineServices().getTaskService();

  String instanceToDelete = (String) execution.getVariable("instanceToComplete");
  Task taskToTrigger = taskService.createTaskQuery().processInstanceId(instanceToDelete).singleResult();
  taskService.complete(taskToTrigger.getId());

  ActivityInstance activityInstance = runtimeService.getActivityInstance(instanceToDelete);
  execution.setVariable("activityInstanceNull", activityInstance == null);
}
 
Example #14
Source File: TaskResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteTask(String id) {
  TaskService taskService = engine.getTaskService();

  try {
    taskService.deleteTask(id);
  }
  catch (NotValidException e) {
    throw new InvalidRequestException(Status.BAD_REQUEST, e, "Could not delete task: " + e.getMessage());
  }
}
 
Example #15
Source File: TaskRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void createTask(TaskDto taskDto) {
  ProcessEngine engine = getProcessEngine();
  TaskService taskService = engine.getTaskService();

  Task newTask = taskService.newTask(taskDto.getId());
  taskDto.updateTask(newTask);

  try {
    taskService.saveTask(newTask);

  } catch (NotValidException e) {
    throw new InvalidRequestException(Status.BAD_REQUEST, e, "Could not save task: " + e.getMessage());
  }

}
 
Example #16
Source File: TaskResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void updateTask(TaskDto taskDto) {
  TaskService taskService = engine.getTaskService();

  Task task = getTaskById(taskId);

  if (task == null) {
    throw new InvalidRequestException(Status.NOT_FOUND, "No matching task with id " + taskId);
  }

  taskDto.updateTask(task);
  taskService.saveTask(task);
}
 
Example #17
Source File: TaskResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteIdentityLink(IdentityLinkDto identityLink) {
  TaskService taskService = engine.getTaskService();

  identityLink.validate();

  if (identityLink.getUserId() != null) {
    taskService.deleteUserIdentityLink(taskId, identityLink.getUserId(), identityLink.getType());
  } else if (identityLink.getGroupId() != null) {
    taskService.deleteGroupIdentityLink(taskId, identityLink.getGroupId(), identityLink.getType());
  }

}
 
Example #18
Source File: HalIdentityLinkResolver.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected List<HalResource<?>> resolveNotCachedLinks(String[] linkedIds, ProcessEngine processEngine) {
  TaskService taskService = processEngine.getTaskService();

  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(linkedIds[0]);

  List<HalResource<?>> resolvedIdentityLinks = new ArrayList<HalResource<?>>();
  for (IdentityLink identityLink : identityLinks) {
    resolvedIdentityLinks.add(HalIdentityLink.fromIdentityLink(identityLink));
  }

  return resolvedIdentityLinks;
}
 
Example #19
Source File: TaskResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void addIdentityLink(IdentityLinkDto identityLink) {
  TaskService taskService = engine.getTaskService();

  identityLink.validate();

  if (identityLink.getUserId() != null) {
    taskService.addUserIdentityLink(taskId, identityLink.getUserId(), identityLink.getType());
  } else if (identityLink.getGroupId() != null) {
    taskService.addGroupIdentityLink(taskId, identityLink.getGroupId(), identityLink.getType());
  }

}
 
Example #20
Source File: TaskFormWidget.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
protected FormKey obtainFormKey() {
	               ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
	               TaskService taskService = processEngine.getTaskService();
	               Task task = taskService.createTaskQuery()
                                          .taskId((String)getModelObject().field("id"))
                                          .initializeFormKeys()
                                          .singleResult();
	               return FormKey.parse(task.getFormKey());
}
 
Example #21
Source File: CompleteTaskCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(Optional<AjaxRequestTarget> targetOptional) {
	super.onClick(targetOptional);
	ODocument doc = getModelObject();
	ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
	TaskService taskService = processEngine.getTaskService();
	String taskId = taskModel.getObject().field("id");
	String var = formKey.getVariableName();
	taskService.complete(taskId, CommonUtils.<String, Object>toMap(var, doc.getIdentity().toString()));
	setResponsePage(new ODocumentPage(doc));
	sendActionPerformed();
}
 
Example #22
Source File: TaskResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void resolve(CompleteTaskDto dto) {
  TaskService taskService = engine.getTaskService();

  try {
    VariableMap variables = VariableValueDto.toMap(dto.getVariables(), engine, objectMapper);
    taskService.resolveTask(taskId, variables);

  } catch (RestException e) {
    String errorMessage = String.format("Cannot resolve task %s: %s", taskId, e.getMessage());
    throw new InvalidRequestException(e.getStatus(), e, errorMessage);

  }

}
 
Example #23
Source File: TaskResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public List<IdentityLinkDto> getIdentityLinks(String type) {
  TaskService taskService = engine.getTaskService();
  List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);

  List<IdentityLinkDto> result = new ArrayList<>();
  for (IdentityLink link : identityLinks) {
    if (type == null || type.equals(link.getType())) {
      result.add(IdentityLinkDto.fromIdentityLink(link));
    }
  }

  return result;
}
 
Example #24
Source File: TaskVariableRestResourceInteractionTest.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);
}
 
Example #25
Source File: TaskVariableLocalRestResourceInteractionTest.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);
}
 
Example #26
Source File: ProcessEngineTestRule.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void completeAnyTask(String taskKey) {
  TaskService taskService = processEngine.getTaskService();
  List<Task> tasks = taskService.createTaskQuery().taskDefinitionKey(taskKey).list();
  assertTrue(!tasks.isEmpty());
  taskService.complete(tasks.get(0).getId());
}
 
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: FilterRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUpRuntimeData() {
  filterServiceMock = mock(FilterService.class);

  when(processEngine.getFilterService()).thenReturn(filterServiceMock);

  FilterQuery filterQuery = MockProvider.createMockFilterQuery();

  when(filterServiceMock.createFilterQuery()).thenReturn(filterQuery);

  filterMock = MockProvider.createMockFilter();

  when(filterServiceMock.newTaskFilter()).thenReturn(filterMock);
  when(filterServiceMock.saveFilter(eq(filterMock))).thenReturn(filterMock);
  when(filterServiceMock.getFilter(eq(EXAMPLE_FILTER_ID))).thenReturn(filterMock);
  when(filterServiceMock.getFilter(eq(MockProvider.NON_EXISTING_ID))).thenReturn(null);

  List<Object> mockTasks = Collections.<Object>singletonList(new TaskEntity());

  when(filterServiceMock.singleResult(eq(EXAMPLE_FILTER_ID)))
    .thenReturn(mockTasks.get(0));
  when(filterServiceMock.singleResult(eq(EXAMPLE_FILTER_ID), any(Query.class)))
    .thenReturn(mockTasks.get(0));
  when(filterServiceMock.list(eq(EXAMPLE_FILTER_ID)))
    .thenReturn(mockTasks);
  when(filterServiceMock.list(eq(EXAMPLE_FILTER_ID), any(Query.class)))
    .thenReturn(mockTasks);
  when(filterServiceMock.listPage(eq(EXAMPLE_FILTER_ID), anyInt(), anyInt()))
    .thenReturn(mockTasks);
  when(filterServiceMock.listPage(eq(EXAMPLE_FILTER_ID), any(Query.class), anyInt(), anyInt()))
    .thenReturn(mockTasks);
  when(filterServiceMock.count(eq(EXAMPLE_FILTER_ID)))
    .thenReturn((long) 1);
  when(filterServiceMock.count(eq(EXAMPLE_FILTER_ID), any(Query.class)))
    .thenReturn((long) 1);

  doThrow(new NullValueException("No filter found with given id"))
    .when(filterServiceMock).singleResult(eq(MockProvider.NON_EXISTING_ID));
  doThrow(new NullValueException("No filter found with given id"))
    .when(filterServiceMock).singleResult(eq(MockProvider.NON_EXISTING_ID), any(Query.class));
  doThrow(new NullValueException("No filter found with given id"))
    .when(filterServiceMock).list(eq(MockProvider.NON_EXISTING_ID));
  doThrow(new NullValueException("No filter found with given id"))
    .when(filterServiceMock).list(eq(MockProvider.NON_EXISTING_ID), any(Query.class));
  doThrow(new NullValueException("No filter found with given id"))
    .when(filterServiceMock).listPage(eq(MockProvider.NON_EXISTING_ID), anyInt(), anyInt());
  doThrow(new NullValueException("No filter found with given id"))
    .when(filterServiceMock).listPage(eq(MockProvider.NON_EXISTING_ID), any(Query.class), anyInt(), anyInt());
  doThrow(new NullValueException("No filter found with given id"))
    .when(filterServiceMock).count(eq(MockProvider.NON_EXISTING_ID));
  doThrow(new NullValueException("No filter found with given id"))
    .when(filterServiceMock).count(eq(MockProvider.NON_EXISTING_ID), any(Query.class));
  doThrow(new NullValueException("No filter found with given id"))
    .when(filterServiceMock).deleteFilter(eq(MockProvider.NON_EXISTING_ID));

  authorizationServiceMock = mock(AuthorizationServiceImpl.class);
  identityServiceMock = mock(IdentityServiceImpl.class);
  processEngineConfigurationMock = mock(ProcessEngineConfiguration.class);

  when(processEngine.getAuthorizationService()).thenReturn(authorizationServiceMock);
  when(processEngine.getIdentityService()).thenReturn(identityServiceMock);
  when(processEngine.getProcessEngineConfiguration()).thenReturn(processEngineConfigurationMock);

  TaskService taskService = processEngine.getTaskService();
  when(taskService.createTaskQuery()).thenReturn(new TaskQueryImpl());

  variableInstanceQueryMock = mock(VariableInstanceQueryImpl.class);
  when(processEngine.getRuntimeService().createVariableInstanceQuery())
    .thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.variableScopeIdIn((String) anyVararg()))
    .thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.variableNameIn((String) anyVararg()))
    .thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.disableBinaryFetching()).thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock);
}
 
Example #30
Source File: SpringProcessEngineServicesConfiguration.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Bean(name = "taskService")
@Override
public TaskService getTaskService() {
  return processEngine.getTaskService();
}