Java Code Examples for org.camunda.bpm.engine.TaskService#complete()

The following examples show how to use org.camunda.bpm.engine.TaskService#complete() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: CoverageRatioTest.java    From camunda-bpm-process-test-coverage with Apache License 2.0 4 votes vote down vote up
public void completeTask() {
    TaskService taskService = rule.getProcessEngine().getTaskService();
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
}
 
Example 8
Source File: TestDataGenerator.java    From camunda-bpm-elasticsearch with Apache License 2.0 4 votes vote down vote up
public static HashMap<String, ProcessDataContainer> startInvoiceProcess(ProcessEngine processEngine, final int numberOfInstances, boolean addRandomTimeInterval) {
  RepositoryService repositoryService = processEngine.getRepositoryService();
  RuntimeService runtimeService = processEngine.getRuntimeService();
  TaskService taskService = processEngine.getTaskService();

  Deployment deployment = repositoryService.createDeployment().addClasspathResource("invoice.bpmn").deploy();
  Assert.assertNotNull(repositoryService.createDeploymentQuery().deploymentId(deployment.getId()).singleResult());

  LOGGER.info("Creating " + numberOfInstances + " instances of 'invoice.bpmn' process.");


  HashMap<String, ProcessDataContainer> variablesByProcessIds = new HashMap<String, ProcessDataContainer>(numberOfInstances);

  for (int i = 0; i < numberOfInstances; i++) {
    if (addRandomTimeInterval) {
      ClockUtil.setCurrentTime(new Date(ClockUtil.getCurrentTime().getTime() + getRandomLong()));
    }

    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put(TestDataGenerator.getRandomString(), TestDataGenerator.getRandomString());
    variables.put("long", TestDataGenerator.getRandomLong());
    variables.put("double", TestDataGenerator.getRandomDouble());

    ProcessInstance pi = runtimeService.startProcessInstanceByKey("invoice", variables);
    Assert.assertNotNull(pi);

    List<Task> tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).list();

    assertEquals(1, tasks.size());
    assertEquals("assignApprover", tasks.get(0).getTaskDefinitionKey());

    variables.clear();
    String approver = TestDataGenerator.getRandomString();
    variables.put("approver", approver);
    taskService.complete(tasks.get(0).getId(), variables);

    tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).list();

    assertEquals(1, tasks.size());
    assertEquals("approveInvoice", tasks.get(0).getTaskDefinitionKey());
    assertEquals(approver, tasks.get(0).getAssignee());

    variables.clear();
    variables.put("approved", Boolean.TRUE);
    taskService.complete(tasks.get(0).getId(), variables);

    tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).list();

    // retrieve all variables
    List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().processInstanceIdIn(pi.getProcessInstanceId()).list();
    variablesByProcessIds.put(pi.getProcessInstanceId(), new ProcessDataContainer(pi.getProcessInstanceId(), pi.getBusinessKey(), variableInstances));

    assertEquals(1, tasks.size());
    assertEquals("prepareBankTransfer", tasks.get(0).getTaskDefinitionKey());
    taskService.complete(tasks.get(0).getId());

    ProcessEngineAssert.assertProcessEnded(processEngine, pi.getId());
  }

  LOGGER.info("Created " + numberOfInstances + " instances of 'invoice.bpmn' process.");

  return variablesByProcessIds;
}
 
Example 9
Source File: RuntimeServiceTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testStartProcessInstanceByIdAfterReboot() {

  // In case this test is run in a test suite, previous engines might
  // have been initialized and cached.  First we close the
  // existing process engines to make sure that the db is clean
  // and that there are no existing process engines involved.
  ProcessEngines.destroy();

  // Creating the DB schema (without building a process engine)
  ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
  processEngineConfiguration.setProcessEngineName("reboot-test-schema");
  processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
  ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

  // Create process engine and deploy test process
  ProcessEngine processEngine = new StandaloneProcessEngineConfiguration()
    .setProcessEngineName("reboot-test")
    .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
    .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000")
    .setJobExecutorActivate(false)
    .buildProcessEngine();

  processEngine.getRepositoryService()
    .createDeployment()
    .addClasspathResource("org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml")
    .deploy();
    // verify existence of process definition
  List<ProcessDefinition> processDefinitions = processEngine
    .getRepositoryService()
    .createProcessDefinitionQuery()
    .list();

  assertEquals(1, processDefinitions.size());

  // Start a new Process instance
  ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
  String processInstanceId = processInstance.getId();
  assertNotNull(processInstance);

  // Close the process engine
  processEngine.close();
  assertNotNull(processEngine.getRuntimeService());

  // Reboot the process engine
  processEngine = new StandaloneProcessEngineConfiguration()
    .setProcessEngineName("reboot-test")
    .setDatabaseSchemaUpdate(org.camunda.bpm.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
    .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000")
    .setJobExecutorActivate(false)
    .buildProcessEngine();

  // Check if the existing process instance is still alive
  processInstance = processEngine
    .getRuntimeService()
    .createProcessInstanceQuery()
    .processInstanceId(processInstanceId)
    .singleResult();

  assertNotNull(processInstance);

  // Complete the task.  That will end the process instance
  TaskService taskService = processEngine.getTaskService();
  Task task = taskService
    .createTaskQuery()
    .list()
    .get(0);
  taskService.complete(task.getId());

  // Check if the process instance has really ended.  This means that the process definition has
  // re-loaded into the process definition cache
  processInstance = processEngine
    .getRuntimeService()
    .createProcessInstanceQuery()
    .processInstanceId(processInstanceId)
    .singleResult();
  assertNull(processInstance);

  // Extra check to see if a new process instance can be started as well
  processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
  assertNotNull(processInstance);

  // close the process engine
  processEngine.close();

  // Cleanup schema
  schemaProcessEngine.close();
}
 
Example 10
Source File: ProcessEngineTestRule.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void completeTask(String taskKey) {
  TaskService taskService = processEngine.getTaskService();
  Task task = taskService.createTaskQuery().taskDefinitionKey(taskKey).singleResult();
  assertNotNull("Expected a task with key '" + taskKey + "' to exist", task);
  taskService.complete(task.getId());
}
 
Example 11
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());
}