org.activiti.engine.runtime.ProcessInstance Java Examples

The following examples show how to use org.activiti.engine.runtime.ProcessInstance. 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: ExpressionManagerTest.java    From activiti6-boot2 with Apache License 2.0 7 votes vote down vote up
@Deployment
public void testAuthenticatedUserIdAvailable() {
  try {
    // Setup authentication
    Authentication.setAuthenticatedUserId("frederik");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testAuthenticatedUserIdAvailableProcess");
    
    // Check if the variable that has been set in service-task is the authenticated user
    String value = (String) runtimeService.getVariable(processInstance.getId(), "theUser");
    assertNotNull(value);
    assertEquals("frederik", value);
  } finally {
    // Cleanup
    Authentication.setAuthenticatedUserId(null);
  }
}
 
Example #2
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSimple() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task userTask = taskQuery.singleResult();
    assertEquals("userTask1", userTask.getName());

    taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));

    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(1, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("test456", historicVariable.getTextValue());

    assertEquals(5, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(3, historyService.createHistoricDetailQuery().count());
  }
}
 
Example #3
Source File: DynamicUserTaskTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/bpmn/usertask/DynamicUserTaskTest.assignment.bpmn20.xml"})
public void testChangeAssignee() {
  // first test without changing the form key
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  String processDefinitionId = processInstance.getProcessDefinitionId();
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test", task.getAssignee());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // now test with changing the form key
  ObjectNode infoNode = dynamicBpmnService.changeUserTaskAssignee("task1", "test2");
  dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
  
  processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals("test2", task.getAssignee());
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example #4
Source File: RuntimeServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testRemoveVariable() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("variable1", "value1");
  vars.put("variable2", "value2");

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  runtimeService.setVariables(processInstance.getId(), vars);

  runtimeService.removeVariable(processInstance.getId(), "variable1");

  assertNull(runtimeService.getVariable(processInstance.getId(), "variable1"));
  assertNull(runtimeService.getVariableLocal(processInstance.getId(), "variable1"));
  assertEquals("value2", runtimeService.getVariable(processInstance.getId(), "variable2"));

  checkHistoricVariableUpdateEntity("variable1", processInstance.getId());
}
 
Example #5
Source File: MessageEventsAndNewVersionDeploymentsWithTenantIdTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Verifying that the event subscriptions do get removed when removing a process instance.
 */
public void testBoundaryEventSubscrptionsDeletedOnProcessInstanceDelete() {
  String deploymentId1 = deployBoundaryMessageTestProcess();
  runtimeService.startProcessInstanceByKeyAndTenantId("messageTest", TENANT_ID);
  assertEquals("My Task", taskService.createTaskQuery().singleResult().getName());
  
  String deploymentId2 = deployBoundaryMessageTestProcess();
  ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKeyAndTenantId("messageTest", TENANT_ID);
  assertEquals(2, taskService.createTaskQuery().count());
  assertEquals(2, getAllEventSubscriptions().size());
  
  // Deleting PI of second deployment
  runtimeService.deleteProcessInstance(processInstance2.getId(), "testing");
  assertEquals("My Task", taskService.createTaskQuery().singleResult().getName());
  assertEquals(1, getAllEventSubscriptions().size());
  
  runtimeService.messageEventReceived("myMessage", getExecutionIdsForMessageEventSubscription("myMessage").get(0));
  assertEquals(0, getAllEventSubscriptions().size());
  assertEquals("Task after message", taskService.createTaskQuery().singleResult().getName());
  
  cleanup(deploymentId1, deploymentId2);
}
 
Example #6
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testAct901() {

  Date startTime = processEngineConfiguration.getClock().getCurrentTime();

  ProcessInstance pi = runtimeService.startProcessInstanceByKey("multiInstanceSubProcess");
  List<Task> tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc().list();

  processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + 61000L)); // timer is set to one minute
  List<Job> timers = managementService.createTimerJobQuery().list();
  assertEquals(5, timers.size());

  // Execute all timers one by one (single thread vs thread pool of job
  // executor, which leads to optimisticlockingexceptions!)
  for (Job timer : timers) {
    managementService.moveTimerToExecutableJob(timer.getId());
    managementService.executeJob(timer.getId());
  }

  // All tasks should be canceled
  tasks = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc().list();
  assertEquals(0, tasks.size());
}
 
Example #7
Source File: ActivitiProducer.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void copyResultToCamel(Exchange exchange, ProcessInstance pi) {
  exchange.setProperty(PROCESS_ID_PROPERTY, pi.getProcessInstanceId());

  Map<String, Object> returnVars = getActivitiEndpoint().getReturnVarMap();

  if (returnVars != null && returnVars.size() > 0) {

    Map<String, Object> processVariables = null;
    if (repositoryService.isActiviti5ProcessDefinition(pi.getProcessDefinitionId())) {
      Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); 
      processVariables = activiti5CompatibilityHandler.getVariables(pi);
    } else {
      processVariables = ((ExecutionEntity) pi).getVariables();
    }
    
    if (processVariables != null) {
      for (String variableName : returnVars.keySet()) {
        if (processVariables.containsKey(variableName)) {
          exchange.setProperty(variableName, processVariables.get(variableName));
        }
      }
    }
  }
}
 
Example #8
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti5/engine/test/bpmn/multiinstance/MultiInstanceTest.testNestedMultiInstanceTasks.bpmn20.xml"})
public void testNestedMultiInstanceTasks() {
  List<String> processes = Arrays.asList("process A", "process B");
  List<String> assignees = Arrays.asList("kermit", "gonzo");
  Map<String, Object> variableMap = new HashMap<String, Object>();
  variableMap.put("subProcesses", processes);
  variableMap.put("assignees", assignees);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("miNestedMultiInstanceTasks", variableMap);

  List<Task> tasks = taskService.createTaskQuery().list();
  assertEquals(processes.size() * assignees.size(), tasks.size());

  for (Task t : tasks) {
    taskService.complete(t.getId());
  }

  List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processDefinitionKey("miNestedMultiInstanceTasks").list();
  assertEquals(0, processInstances.size());
  assertProcessEnded(processInstance.getId());
}
 
Example #9
Source File: Activiti6Test.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Test
@org.activiti.engine.test.Deployment
public void testLongServiceTaskLoop() {
  int maxCount = 3210; // You can make this as big as you want (as long as
                       // it still fits within transaction timeouts). Go
                       // on, try it!
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("counter", new Integer(0));
  vars.put("maxCount", maxCount);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testLongServiceTaskLoop", vars);
  assertNotNull(processInstance);
  assertTrue(processInstance.isEnded());

  assertEquals(maxCount, CountingServiceTaskTestDelegate.CALL_COUNT.get());
  assertEquals(0, runtimeService.createExecutionQuery().count());

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    assertEquals(maxCount, historyService.createHistoricActivityInstanceQuery()
        .processInstanceId(processInstance.getId()).activityId("serviceTask").count());
  }
}
 
Example #10
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testTaskDueDateOr() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  // Set due-date on task
  Date dueDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/02/2003 01:12:13");
  task.setDueDate(dueDate);
  taskService.saveTask(task);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueDate(dueDate).count());

  Calendar otherDate = Calendar.getInstance();
  otherDate.add(Calendar.YEAR, 1);
  assertEquals(0, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueDate(otherDate.getTime()).count());

  Calendar priorDate = Calendar.getInstance();
  priorDate.setTime(dueDate);
  priorDate.roll(Calendar.YEAR, -1);

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(priorDate.getTime()).count());

  assertEquals(1, taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDueBefore(otherDate.getTime()).count());
}
 
Example #11
Source File: TerminateEndEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={
  "org/activiti5/engine/test/bpmn/event/end/TerminateEndEventTest.testTerminateInCallActivity.bpmn", 
  "org/activiti5/engine/test/bpmn/event/end/TerminateEndEventTest.subProcessTerminate.bpmn" 
})
public void testTerminateInCallActivity() throws Exception {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample");

  // should terminate the called process and continue the parent
  long executionEntities = runtimeService.createExecutionQuery().count();
  assertEquals(1, executionEntities);
  
  Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preNormalEnd").singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(pi.getId());
}
 
Example #12
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti5/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskAttachmentWithProcessInstanceId() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    
    String processInstanceId = processInstance.getId();
    taskService.createAttachment("web page", null, processInstanceId, "weatherforcast", "temperatures and more", "http://weather.com");
    Attachment attachment = taskService.getProcessInstanceAttachments(processInstanceId).get(0);
    assertEquals("weatherforcast", attachment.getName());
    assertEquals("temperatures and more", attachment.getDescription());
    assertEquals("web page", attachment.getType());
    assertEquals(processInstanceId, attachment.getProcessInstanceId());
    assertNull(attachment.getTaskId());
    assertEquals("http://weather.com", attachment.getUrl());
    assertNull(taskService.getAttachmentContent(attachment.getId()));
    
    // Finally, clean up
    taskService.deleteAttachment(attachment.getId());
    
    // TODO: Bad API design. Need to fix attachment/comment properly
    ((TaskServiceImpl) taskService).deleteComments(null, processInstanceId);
  }
}
 
Example #13
Source File: RuntimeServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={
"org/activiti5/engine/test/api/oneSubProcess.bpmn20.xml"})
public void testRemoveVariableInParentScope() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("variable1", "value1");
  vars.put("variable2", "value2");
  
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startSimpleSubProcess", vars);
  Task currentTask = taskService.createTaskQuery().singleResult();
  
  runtimeService.removeVariable(currentTask.getExecutionId(), "variable1");

  assertNull(runtimeService.getVariable(processInstance.getId(), "variable1"));
  assertEquals("value2", runtimeService.getVariable(processInstance.getId(), "variable2"));
  
  checkHistoricVariableUpdateEntity("variable1", processInstance.getId());
}
 
Example #14
Source File: TaskListenerOnTransactionTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testOnCompleteCommitted() {
  CurrentTaskTransactionDependentTaskListener.clear();

  Map<String, Object> variables = new HashMap<>();
  variables.put("serviceTask1", false);
  variables.put("serviceTask2", false);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskListenersOnCompleteCommitted", variables);

  // task 1 has committed listener
  Task task = taskService.createTaskQuery().singleResult();
  taskService.complete(task.getId());

  // task 2 has rolled-back listener
  task = taskService.createTaskQuery().singleResult();
  taskService.complete(task.getId());

  List<CurrentTaskTransactionDependentTaskListener.CurrentTask> currentTasks = CurrentTaskTransactionDependentTaskListener.getCurrentTasks();
  assertEquals(1, currentTasks.size());

  assertEquals("usertask1", currentTasks.get(0).getTaskId());
  assertEquals("User Task 1", currentTasks.get(0).getTaskName());
  assertEquals(processInstance.getId(), currentTasks.get(0).getProcessInstanceId());
  assertNotNull(currentTasks.get(0).getProcessInstanceId());
}
 
Example #15
Source File: CamelVariableBodyMapTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "process/HelloCamelBodyMap.bpmn20.xml" })
public void testCamelBody() throws Exception {
  Map<String, Object> varMap = new HashMap<String, Object>();
  varMap.put("camelBody", "hello world");
  service1.expectedBodiesReceived(varMap);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HelloCamel", varMap);
  // Ensure that the variable is equal to the expected value.
  assertEquals("hello world", runtimeService.getVariable(processInstance.getId(), "camelBody"));
  service1.assertIsSatisfied();

  Task task = taskService.createTaskQuery().singleResult();

  // Ensure that the name of the task is correct.
  assertEquals("Hello Task", task.getName());

  // Complete the task.
  taskService.complete(task.getId());
}
 
Example #16
Source File: ProcessInstanceQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryAllVariableTypes() throws Exception {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("nullVar", null);
  vars.put("stringVar", "string");
  vars.put("longVar", 10L);
  vars.put("doubleVar", 1.2);
  vars.put("integerVar", 1234);
  vars.put("booleanVar", true);
  vars.put("shortVar", (short) 123);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);

  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("nullVar", null).variableValueEquals("stringVar", "string").variableValueEquals("longVar", 10L)
      .variableValueEquals("doubleVar", 1.2).variableValueEquals("integerVar", 1234).variableValueEquals("booleanVar", true).variableValueEquals("shortVar", (short) 123);

  List<ProcessInstance> processInstances = query.list();
  assertNotNull(processInstances);
  assertEquals(1, processInstances.size());
  assertEquals(processInstance.getId(), processInstances.get(0).getId());

  runtimeService.deleteProcessInstance(processInstance.getId(), "test");
}
 
Example #17
Source File: ExecutionListenerTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/examples/bpmn/executionlistener/ExecutionListenersFieldInjectionProcess.bpmn20.xml" })
public void testExecutionListenerFieldInjection() {
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("myVar", "listening!");

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("executionListenersProcess", variables);

  Object varSetByListener = runtimeService.getVariable(processInstance.getId(), "var");
  assertNotNull(varSetByListener);
  assertTrue(varSetByListener instanceof String);

  // Result is a concatenation of fixed injected field and injected
  // expression
  assertEquals("Yes, I am listening!", varSetByListener);
}
 
Example #18
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testEmptyCollectionOnParallelUserTask() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("messages", Collections.EMPTY_LIST);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parallelUserTaskMi", vars);
    
    assertEquals(1L, historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).finished().count());
  }
}
 
Example #19
Source File: MessageEventSubprocessTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private void testInterruptingUnderProcessDefinition(int expectedNumberOfEventSubscriptions) {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
  
  // the process instance must have a message event subscription:
  Execution execution = runtimeService.createExecutionQuery()
    .executionId(processInstance.getId())
    .messageEventSubscriptionName("newMessage")
    .singleResult();
  assertNotNull(execution);
  assertEquals(expectedNumberOfEventSubscriptions, createEventSubscriptionQuery().count());
  assertEquals(1, runtimeService.createExecutionQuery().count());
  
  // if we trigger the usertask, the process terminates and the event subscription is removed:
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("task", task.getTaskDefinitionKey());
  taskService.complete(task.getId());    
  assertProcessEnded(processInstance.getId());
  assertEquals(0, createEventSubscriptionQuery().count());
  assertEquals(0, runtimeService.createExecutionQuery().count());
  
  // now we start a new instance but this time we trigger the event subprocess:
  processInstance = runtimeService.startProcessInstanceByKey("process");
  runtimeService.messageEventReceived("newMessage", processInstance.getId());
  
  task = taskService.createTaskQuery().singleResult();
  assertEquals("eventSubProcessTask", task.getTaskDefinitionKey());
  taskService.complete(task.getId());
  assertProcessEnded(processInstance.getId());
  assertEquals(0, createEventSubscriptionQuery().count());
  assertEquals(0, runtimeService.createExecutionQuery().count());
}
 
Example #20
Source File: SubProcessTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Same test case as before, but now with all automatic steps
 */
@Deployment
public void testSimpleAutomaticSubProcess() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("simpleSubProcessAutomatic");
  assertTrue(pi.isEnded());
  assertProcessEnded(pi.getId());
}
 
Example #21
Source File: LeaveWorkFlowServiceImpl.java    From maven-framework-project with MIT License 5 votes vote down vote up
/**
 * 根据用户Id查询待办任务列表
 * @param userid 用户id
 * @param processDefinitionKey 流程定义的key
 * @return
 */
@Transactional(propagation=Propagation.REQUIRED)
public List<Leave> findTask(String userid,String processDefinitionKey){

	//存放当前用户的所有任务
	List<Task> tasks=new ArrayList<Task>();
	
	
	List<Leave> leaves=new ArrayList<Leave>();
	
	
	//根据当前用户的id查询代办任务列表(已经签收)
	List<Task> taskAssignees = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskAssignee(userid).orderByTaskPriority().desc().orderByTaskCreateTime().desc().list();
	//根据当前用户id查询未签收的任务列表
	List<Task> taskCandidates = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskCandidateUser(userid).orderByTaskPriority().desc().orderByTaskCreateTime().desc().list();
	
	tasks.addAll(taskAssignees);//添加已签收准备执行的任务(已经分配到任务的人)
	tasks.addAll(taskCandidates);//添加还未签收的任务(任务的候选者)
	
	
	//遍历所有的任务列表,关联实体
	for (Task task : tasks) {
		String processInstanceId = task.getProcessInstanceId();
		//根据流程实例id查询流程实例
		ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
		//获取业务id
		String businessKey=processInstance.getBusinessKey();
		//查询请假实体
		Leave leave = leaveService.findById(businessKey);
		//设置属性
		leave.setTask(task);
		leave.setProcessInstance(processInstance);
		leave.setProcessInstanceId(processInstance.getId());
		leave.setProcessDefinition(getProcessDefinition(processInstance.getProcessDefinitionId()));
		
		leaves.add(leave);
	}
	
	return leaves;
}
 
Example #22
Source File: ParallelGatewayTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Case where there is a parallel gateway that splits into 3 paths of
 * execution, that are immediately joined, without any wait states in between.
 * In the end, no executions should be in the database.
 */
@Deployment
public void testSplitMergeNoWaitstates() {
  ProcessInstance processInstance = 
    runtimeService.startProcessInstanceByKey("forkJoinNoWaitStates");
  assertTrue(processInstance.isEnded());
}
 
Example #23
Source File: ProcessInstanceQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByDeploymentIdIn() {
  List<String> deploymentIds = new ArrayList<String>();
  deploymentIds.add(deployment.getId());
  List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().deploymentIdIn(deploymentIds).list();
  assertEquals(PROCESS_DEPLOY_COUNT, instances.size());

  ProcessInstance processInstance = instances.get(0);
  assertEquals(deployment.getId(), processInstance.getDeploymentId());
  assertEquals(new Integer(1), processInstance.getProcessDefinitionVersion());
  assertEquals(PROCESS_DEFINITION_KEY, processInstance.getProcessDefinitionKey());
  assertEquals("oneTaskProcessName", processInstance.getProcessDefinitionName());

  assertEquals(PROCESS_DEPLOY_COUNT, runtimeService.createProcessInstanceQuery().deploymentIdIn(deploymentIds).count());
}
 
Example #24
Source File: CompensateEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testCompensateSubprocess() {

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensateProcess");

  assertEquals(5, runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));

  Execution execution = runtimeService.createExecutionQuery().activityId("beforeEnd").singleResult();
  runtimeService.trigger(execution.getId());
  assertProcessEnded(processInstance.getId());
}
 
Example #25
Source File: ExclusiveGatewayTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * The test process has an XOR gateway where, the 'input' variable is used to
 * select one of the outgoing sequence flow. Every one of those sequence flow
 * goes to another task, allowing us to test the decision very easily.
 */
@Deployment
public void testDecisionFunctionality() {

  Map<String, Object> variables = new HashMap<String, Object>();

  // Test with input == 1
  variables.put("input", 1);
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("exclusiveGateway", variables);
  Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
  assertEquals("Send e-mail for more information", task.getName());

  // Test with input == 2
  variables.put("input", 2);
  pi = runtimeService.startProcessInstanceByKey("exclusiveGateway", variables);
  task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
  assertEquals("Check account balance", task.getName());

  // Test with input == 3
  variables.put("input", 3);
  pi = runtimeService.startProcessInstanceByKey("exclusiveGateway", variables);
  task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
  assertEquals("Call customer", task.getName());

  // Test with input == 4
  variables.put("input", 4);
  try {
    runtimeService.startProcessInstanceByKey("exclusiveGateway", variables);
    fail();
  } catch (ActivitiException e) {
    // Exception is expected since no outgoing sequence flow matches
  }

}
 
Example #26
Source File: LeaveReportProcessor.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
/**
 * 销假完成后执行,保存实际开始和结束时间
 */
public void notify(DelegateTask delegateTask) {
	String processInstanceId = delegateTask.getProcessInstanceId();
	ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
	Leave leave = new Leave(processInstance.getBusinessKey());
	leave.setRealityStartTime((Date) delegateTask.getVariable("realityStartTime"));
	leave.setRealityEndTime((Date) delegateTask.getVariable("realityEndTime"));
	leave.preUpdate();
	leaveDao.updateRealityTime(leave);
}
 
Example #27
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testChangingCollection() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("multi_users", Arrays.asList("testuser"));
  ProcessInstance instance = runtimeService.startProcessInstanceByKey("test_multi", vars);
  assertNotNull(instance);
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("multi", task.getTaskDefinitionKey());
  vars.put("multi_users", new ArrayList<String>()); // <-- Problem here.
  taskService.complete(task.getId(), vars);
  List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().list();
  assertEquals(0, instances.size());
}
 
Example #28
Source File: ActivitiProducer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected String findProcessInstanceId(Exchange exchange) {
  String processInstanceId = exchange.getProperty(PROCESS_ID_PROPERTY, String.class);
  if (processInstanceId != null) {
    return processInstanceId;
  }
  String processInstanceKey = exchange.getProperty(PROCESS_KEY_PROPERTY, String.class);
  ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(processInstanceKey).singleResult();

  if (processInstance == null) {
    throw new ActivitiException("Could not find activiti with key " + processInstanceKey);
  }
  return processInstance.getId();
}
 
Example #29
Source File: ActivitiKit.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 查询 运行时 流程任务节点名
 *
 * @param businessKey
 * @return
 */
public static String getActivityName(String businessKey) {
    String activityName = "未知";
    ProcessInstance instance = ActivitiKit.getRuntimeService().createProcessInstanceQuery()
            .processInstanceBusinessKey(businessKey)
            .singleResult();
    if (instance != null) {
        ActivityImpl activity = ActivitiKit.getActivity(instance.getProcessDefinitionId(), instance.getActivityId());
        if (activity != null) {
            activityName = (String) activity.getProperty("name");
        }
    }
    return activityName;
}
 
Example #30
Source File: TaskQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml"})
public void testProcessDefinitionName() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  
  List<Task> tasks = taskService.createTaskQuery().processDefinitionName("The One Task Process").list();
  assertEquals(1, tasks.size());
  assertEquals(processInstance.getId(), tasks.get(0).getProcessInstanceId());
  
  assertEquals(0, taskService.createTaskQuery().processDefinitionName("unexisting").count());
}