org.activiti.engine.runtime.Execution Java Examples

The following examples show how to use org.activiti.engine.runtime.Execution. 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: VariableEventsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Test create, update and delete variables locally on a child-execution of
 * the process instance.
 */
@Deployment
public void testProcessInstanceVariableEventsOnChildExecution() throws Exception {
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcess");
	assertNotNull(processInstance);

	Execution child = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
	assertNotNull(child);

	runtimeService.setVariableLocal(child.getId(), "test", 1234567);

	assertEquals(1, listener.getEventsReceived().size());
	ActivitiVariableEvent event = (ActivitiVariableEvent) listener.getEventsReceived().get(0);
	assertEquals(ActivitiEventType.VARIABLE_CREATED, event.getType());

	// Execution and process-id should differ
	assertEquals(child.getId(), event.getExecutionId());
	assertEquals(processInstance.getId(), event.getProcessInstanceId());
}
 
Example #2
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Test to validate fix for ACT-1399: Boundary-event and event-based auditing
 */
@Deployment
public void testEventBasedGateway() {
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("catchSignal");
	Execution waitingExecution = runtimeService.createExecutionQuery()
			.signalEventSubscriptionName("alert")
			.singleResult();
	assertNotNull(waitingExecution);
	runtimeService.signalEventReceived("alert", waitingExecution.getId());
	
	assertEquals(0L, runtimeService.createProcessInstanceQuery()
			.processInstanceId(processInstance.getId()).count());
	
	HistoricActivityInstance historicActivityInstance = historyService
			.createHistoricActivityInstanceQuery()
			.activityId("eventBasedgateway")
			.processInstanceId(processInstance.getId())
			.singleResult();
	
	assertNotNull(historicActivityInstance);
}
 
Example #3
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testParallelUserTasksExecutionAndTaskListeners() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("miParallelUserTasks");
  List<Task> tasks = taskService.createTaskQuery().list();
  for (Task task : tasks) {
    taskService.complete(task.getId());
  }

  Execution waitState = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
  assertNotNull(waitState);
  
  assertEquals(3, runtimeService.getVariable(processInstance.getId(), "taskListenerCounter"));
  assertEquals(3, runtimeService.getVariable(processInstance.getId(), "executionListenerCounter"));
  
  runtimeService.trigger(waitState.getId());
  assertProcessEnded(processInstance.getId());
}
 
Example #4
Source File: GetExecutionVariableInstanceCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public VariableInstance execute(CommandContext commandContext) {
    if (executionId == null) {
        throw new FlowableIllegalArgumentException("executionId is null");
    }
    if (variableName == null) {
        throw new FlowableIllegalArgumentException("variableName is null");
    }

    ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(executionId);

    if (execution == null) {
        throw new FlowableObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
    }

    VariableInstance variableEntity = null;
    if (isLocal) {
        variableEntity = execution.getVariableInstanceLocal(variableName, false);
    } else {
        variableEntity = execution.getVariableInstance(variableName, false);
    }

    return variableEntity;
}
 
Example #5
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSequentialScriptTasksCompletionCondition() {
  runtimeService.startProcessInstanceByKey("miSequentialScriptTaskCompletionCondition").getId();
  List<Execution> executions = runtimeService.createExecutionQuery().list();
  assertEquals(2, executions.size());
  Execution processInstanceExecution = null;
  Execution waitStateExecution = null;
  for (Execution execution : executions) {
    if (execution.getId().equals(execution.getProcessInstanceId())) {
      processInstanceExecution = execution;
    } else {
      waitStateExecution = execution;
    }
  }
  assertNotNull(processInstanceExecution);
  assertNotNull(waitStateExecution);
  int sum = (Integer) runtimeService.getVariable(waitStateExecution.getId(), "sum");
  assertEquals(5, sum);
}
 
Example #6
Source File: ExecutionQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testQueryBySignalSubscriptionName() {
  runtimeService.startProcessInstanceByKey("catchSignal");
  
  // it finds subscribed instances
  Execution execution = runtimeService.createExecutionQuery()
    .signalEventSubscriptionName("alert")
    .singleResult();
  assertNotNull(execution);

  // test query for nonexisting subscription
  execution = runtimeService.createExecutionQuery()
          .signalEventSubscriptionName("nonExisitng")
          .singleResult();
  assertNull(execution);
  
  // it finds more than one
  runtimeService.startProcessInstanceByKey("catchSignal");
  assertEquals(2, runtimeService.createExecutionQuery().signalEventSubscriptionName("alert").count());
}
 
Example #7
Source File: VariableScopeTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public List<String> execute(CommandContext commandContext) {
  if (executionId == null) {
    throw new ActivitiIllegalArgumentException("executionId is null");
  }

  ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(executionId);

  if (execution == null) {
    throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
  }

  List<String> executionVariables;
  if (isLocal) {
    executionVariables = new ArrayList<String>(execution.getVariableNamesLocal());
  } else {
    executionVariables = new ArrayList<String>(execution.getVariableNames());
  }

  return executionVariables;
}
 
Example #8
Source File: MessageIntermediateEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testAsyncTriggeredMessageEvent() {
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
	
	assertNotNull(processInstance);
	Execution execution = runtimeService.createExecutionQuery()
		      .processInstanceId(processInstance.getId())
		      .messageEventSubscriptionName("newMessage")
		      .singleResult();
	assertNotNull(execution);
	assertEquals(1, createEventSubscriptionQuery().count());
	assertEquals(2, runtimeService.createExecutionQuery().count());
	
	runtimeService.messageEventReceivedAsync("newMessage", execution.getId());
	
	assertEquals(1, managementService.createJobQuery().messages().count());
	
	waitForJobExecutorToProcessAllJobs(8000L, 200L);
	assertEquals(0, createEventSubscriptionQuery().count());    
	assertEquals(0, runtimeService.createProcessInstanceQuery().count());
	assertEquals(0, managementService.createJobQuery().count()); 
}
 
Example #9
Source File: RestResponseFactory.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public ExecutionResponse createExecutionResponse(Execution execution, RestUrlBuilder urlBuilder) {
  ExecutionResponse result = new ExecutionResponse();
  result.setActivityId(execution.getActivityId());
  result.setId(execution.getId());
  result.setUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION, execution.getId()));
  result.setSuspended(execution.isSuspended());
  result.setTenantId(execution.getTenantId());

  result.setParentId(execution.getParentId());
  if (execution.getParentId() != null) {
    result.setParentUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION, execution.getParentId()));
  }
  
  result.setSuperExecutionId(execution.getSuperExecutionId());
  if (execution.getSuperExecutionId() != null) {
    result.setSuperExecutionUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION, execution.getSuperExecutionId()));
  }

  result.setProcessInstanceId(execution.getProcessInstanceId());
  if (execution.getProcessInstanceId() != null) {
    result.setProcessInstanceUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE, execution.getProcessInstanceId()));
  }
  return result;
}
 
Example #10
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testMultiInstanceParalelReceiveTaskWithTimer() {
  Date startTime = new Date();
  processEngineConfiguration.getClock().setCurrentTime(startTime);

  runtimeService.startProcessInstanceByKey("multiInstanceReceiveWithTimer");
  List<Execution> executions = runtimeService.createExecutionQuery().activityId("theReceiveTask").list();
  assertEquals(3, executions.size());

  // Signal only one execution. Then the timer will fire
  runtimeService.trigger(executions.get(1).getId());
  processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + 60000L));
  waitForJobExecutorToProcessAllJobs(10000L, 1000L);

  // The process should now be in the task after the timer
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("Task after timer", task.getName());

  // Completing it should end the process
  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createExecutionQuery().count());
}
 
Example #11
Source File: ProcessInstanceVariableCollectionResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Create variables or new binary variable on a process instance", tags = { "Process Instances" }, nickname = "createProcessInstanceVariable",
    notes="## Update multiples variables\n\n"
        + " ```JSON\n" + "[\n" + "   {\n" + "      \"name\":\"intProcVar\"\n" + "      \"type\":\"integer\"\n" + "      \"value\":123\n" + "   },\n"
        + "\n" + "   ...\n" + "] ```"
        + "\n\n\n"
        +" Any number of variables can be passed into the request body array. More information about the variable format can be found in the REST variables section. Note that scope is ignored, only local variables can be set in a process instance."
        + "\n\n\n"
        + "The request should be of type multipart/form-data. There should be a single file-part included with the binary value of the variable. On top of that, the following additional form-fields can be present:\n"
        + "\n" + "name: Required name of the variable.\n" + "\n"
        + "type: Type of variable that is created. If omitted, binary is assumed and the binary data in the request will be stored as an array of bytes."
    )
@ApiResponses(value = {
    @ApiResponse(code = 201, message = "Indicates the process instance was found and variable is created."),
    @ApiResponse(code = 400, message = "Indicates the request body is incomplete or contains illegal values. The status description contains additional information about the error."),
    @ApiResponse(code = 404, message = "Indicates the requested process instance was not found."),
    @ApiResponse(code = 409, message = "Indicates the process instance was found but already contains a variable with the given name (only thrown when POST method is used). Use the update-method instead."),

})
@RequestMapping(value = "/runtime/process-instances/{processInstanceId}/variables", method = RequestMethod.POST, produces = "application/json")
public Object createExecutionVariable(@ApiParam(name = "processInstanceId", value="The id of the process instance to create the new variable for") @PathVariable String processInstanceId, HttpServletRequest request, HttpServletResponse response) {

  Execution execution = getProcessInstanceFromRequest(processInstanceId);
  return createExecutionVariable(execution, false, RestResponseFactory.VARIABLE_PROCESS, request, response);
}
 
Example #12
Source File: ExecutionQueryTest.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 testQueryStartedAfter() throws Exception {
  Calendar calendar = new GregorianCalendar();
  calendar.set(Calendar.YEAR, 2030);
  calendar.set(Calendar.MONTH, 8);
  calendar.set(Calendar.DAY_OF_MONTH, 30);
  calendar.set(Calendar.HOUR_OF_DAY, 12);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
  calendar.set(Calendar.MILLISECOND, 0);
  Date noon = calendar.getTime();

  processEngineConfiguration.getClock().setCurrentTime(noon);

  calendar.add(Calendar.HOUR_OF_DAY, -1);
  Date hourEarlier = calendar.getTime();

  runtimeService.startProcessInstanceByKey("oneTaskProcess");

  List<Execution> executions = runtimeService.createExecutionQuery().startedAfter(hourEarlier).list();

  assertEquals(2, executions.size());
}
 
Example #13
Source File: ExecutionQueryTest.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 testQueryStartedBefore() throws Exception {
  Calendar calendar = new GregorianCalendar();
  calendar.set(Calendar.YEAR, 2010);
  calendar.set(Calendar.MONTH, 8);
  calendar.set(Calendar.DAY_OF_MONTH, 30);
  calendar.set(Calendar.HOUR_OF_DAY, 12);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
  calendar.set(Calendar.MILLISECOND, 0);
  Date noon = calendar.getTime();

  processEngineConfiguration.getClock().setCurrentTime(noon);

  calendar.add(Calendar.HOUR_OF_DAY, 1);
  Date hourLater = calendar.getTime();

  runtimeService.startProcessInstanceByKey("oneTaskProcess");

  List<Execution> executions = runtimeService.createExecutionQuery().startedBefore(hourLater).list();

  assertEquals(2, executions.size());
}
 
Example #14
Source File: ExecutionVariableResourceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Test getting execution variable data.
 */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutionVariableData() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");
  runtimeService.setVariableLocal(processInstance.getId(), "var", "This is a binary piece of text".getBytes());

  Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
  assertNotNull(childExecution);
  runtimeService.setVariableLocal(childExecution.getId(), "var", "This is a binary piece of text in the child execution".getBytes());

  CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, childExecution.getId(), "var")),
      HttpStatus.SC_OK);
  String actualResponseBytesAsText = IOUtils.toString(response.getEntity().getContent());
  closeResponse(response);
  assertEquals("This is a binary piece of text in the child execution", actualResponseBytesAsText);
  assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());

  // Test global scope
  response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, childExecution.getId(), "var") + "?scope=global"),
      HttpStatus.SC_OK);
  actualResponseBytesAsText = IOUtils.toString(response.getEntity().getContent());
  closeResponse(response);
  assertEquals("This is a binary piece of text", actualResponseBytesAsText);
  assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
}
 
Example #15
Source File: ActivityEventsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testActivitySignalBoundaryEventsOnUserTask() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalOnUserTask");
  assertNotNull(processInstance);

  Execution executionWithSignal = runtimeService.createExecutionQuery().activityId("userTask").singleResult();
  assertNotNull(executionWithSignal);

  runtimeService.signalEventReceived("signalName");
  assertEquals(1, listener.getEventsReceived().size());

  // Next, an signal-event is expected, as a result of the message
  assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiActivityCancelledEvent);
  ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(0);
  assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
  assertEquals("userTask", signalEvent.getActivityId());
  assertEquals(executionWithSignal.getId(), signalEvent.getExecutionId());
  assertEquals(executionWithSignal.getProcessInstanceId(), signalEvent.getProcessInstanceId());
  assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
  assertNotNull(signalEvent.getCause());
  assertTrue(signalEvent.getCause() instanceof SignalEventSubscriptionEntity);
  SignalEventSubscriptionEntity cause = (SignalEventSubscriptionEntity) signalEvent.getCause();
  assertEquals("signalName", cause.getEventName());
}
 
Example #16
Source File: WorkflowController.java    From oneops with Apache License 2.0 5 votes vote down vote up
private void signalSubJoin(String processId) {
 Execution exSubJoin = runtimeService.createExecutionQuery()
     .processInstanceId(processId)
     .activityId("subJoined").singleResult();

 if (runtimeService.createExecutionQuery().processInstanceId(processId).count() > 0) {
 	runtimeService.setVariable(processId, SUB_PROC_END_VAR, new Boolean(false));
 }
 
 if (exSubJoin != null) {
 	runtimeService.signal(exSubJoin.getId());
 }
}
 
Example #17
Source File: ActivitiWorkflowComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testGetWorkflows() throws Exception 
{
    WorkflowDefinition def = deployTestAdhocDefinition();
    String activitiProcessDefinitionId = BPMEngineRegistry.getLocalId(def.getId());
    
    ProcessInstance activeInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    ProcessInstance completedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    ProcessInstance cancelledInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    ProcessInstance deletedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    
    // Complete completedProcessInstance.
    String completedId = completedInstance.getId();
    boolean isActive = true;
    while (isActive)
    {
        Execution execution = runtime.createExecutionQuery()
        .processInstanceId(completedId)
        .singleResult();
        runtime.signal(execution.getId());
        ProcessInstance instance = runtime.createProcessInstanceQuery()
        .processInstanceId(completedId)
        .singleResult();
        isActive = instance != null;
    }
    
    // Deleted and canceled instances shouldn't be returned
    workflowEngine.cancelWorkflow(workflowEngine.createGlobalId(cancelledInstance.getId()));
    workflowEngine.deleteWorkflow(workflowEngine.createGlobalId(deletedInstance.getId()));
    
    // Validate if a workflow exists
    List<WorkflowInstance> instances = workflowEngine.getWorkflows(def.getId());
    assertNotNull(instances);
    assertEquals(2, instances.size());
    String instanceId = instances.get(0).getId();
    assertEquals(activeInstance.getId(), BPMEngineRegistry.getLocalId(instanceId));
    instanceId = instances.get(1).getId();
    assertEquals(completedId, BPMEngineRegistry.getLocalId(instanceId));
}
 
Example #18
Source File: AsyncPingTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "process/asyncPing.bpmn20.xml" })
public void testRunProcess() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncPingProcess");

  List<Execution> executionList = runtimeService.createExecutionQuery().list();
  Assert.assertEquals(2, executionList.size());

  managementService.executeJob(managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult().getId());
  Thread.sleep(1500);

  executionList = runtimeService.createExecutionQuery().list();
  Assert.assertEquals(0, executionList.size());

  Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
}
 
Example #19
Source File: RuntimeServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testSignalWithProcessVariables() {

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testSignalWithProcessVariables");
  Map<String, Object> processVariables = new HashMap<String, Object>();
  processVariables.put("variable", "value");

  // signal the execution while passing in the variables
  Execution execution = runtimeService.createExecutionQuery().activityId("receiveMessage").singleResult();
  runtimeService.trigger(execution.getId(), processVariables);

  Map<String, Object> variables = runtimeService.getVariables(processInstance.getId());
  assertEquals(variables, processVariables);

}
 
Example #20
Source File: ProcessInstanceQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryVariablesUpdatedToNullValue() {
  // Start process instance with different types of variables
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("longVar", 928374L);
  variables.put("shortVar", (short) 123);
  variables.put("integerVar", 1234);
  variables.put("stringVar", "coca-cola");
  variables.put("dateVar", new Date());
  variables.put("booleanVar", true);
  variables.put("nullVar", null);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);

  ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", null).variableValueEquals("shortVar", null).variableValueEquals("integerVar", null)
      .variableValueEquals("stringVar", null).variableValueEquals("booleanVar", null).variableValueEquals("dateVar", null);

  ProcessInstanceQuery notQuery = runtimeService.createProcessInstanceQuery().variableValueNotEquals("longVar", null).variableValueNotEquals("shortVar", null)
      .variableValueNotEquals("integerVar", null).variableValueNotEquals("stringVar", null).variableValueNotEquals("booleanVar", null).variableValueNotEquals("dateVar", null);

  assertNull(query.singleResult());
  assertNotNull(notQuery.singleResult());

  // Set all existing variables values to null
  runtimeService.setVariable(processInstance.getId(), "longVar", null);
  runtimeService.setVariable(processInstance.getId(), "shortVar", null);
  runtimeService.setVariable(processInstance.getId(), "integerVar", null);
  runtimeService.setVariable(processInstance.getId(), "stringVar", null);
  runtimeService.setVariable(processInstance.getId(), "dateVar", null);
  runtimeService.setVariable(processInstance.getId(), "nullVar", null);
  runtimeService.setVariable(processInstance.getId(), "booleanVar", null);

  Execution queryResult = query.singleResult();
  assertNotNull(queryResult);
  assertEquals(processInstance.getId(), queryResult.getId());
  assertNull(notQuery.singleResult());
}
 
Example #21
Source File: WorkflowController.java    From oneops with Apache License 2.0 5 votes vote down vote up
/**
 * Poke process.
 *
 * @param processId the process id
 */
public void pokeProcess(String processId){

    Execution execution = runtimeService.createExecutionQuery()
      .processInstanceId(processId)
      .singleResult();

    runtimeService
    .signal(execution.getId());    	
	
	logger.info("Poked process with id - " + processId);
}
 
Example #22
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testMultiInstanceParalelReceiveTaskWithTimer() {
  Clock clock = processEngineConfiguration.getClock();
  clock.reset();
  Date startTime = clock.getCurrentTime();
  processEngineConfiguration.setClock(clock);
  
  runtimeService.startProcessInstanceByKey("multiInstanceReceiveWithTimer");
  List<Execution> executions = runtimeService.createExecutionQuery().activityId("theReceiveTask").list();
  assertEquals(3, executions.size());
  
  // Signal only one execution. Then the timer will fire
  runtimeService.trigger(executions.get(1).getId());
  
  clock.setCurrentTime(new Date(startTime.getTime() + 60000L));
  processEngineConfiguration.setClock(clock);
  waitForJobExecutorToProcessAllJobs(10000L, 1000L);
  
  // The process should now be in the task after the timer
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("Task after timer", task.getName());
  
  // Completing it should end the process
  taskService.complete(task.getId());
  assertEquals(0, runtimeService.createExecutionQuery().count());
  
  processEngineConfiguration.resetClock();
}
 
Example #23
Source File: RuntimeServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testFindActiveActivityIdsUnexistingExecututionId() {
  try {
    runtimeService.getActiveActivityIds("unexistingExecutionId");      
    fail("ActivitiException expected");
  } catch (ActivitiObjectNotFoundException ae) {
    assertTextPresent("execution unexistingExecutionId doesn't exist", ae.getMessage());
    assertEquals(Execution.class, ae.getObjectClass());
  }
}
 
Example #24
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testSequentialServiceTaskWithClassAndCollection() {
  Collection<Integer> items = Arrays.asList(1, 2, 3, 4, 5, 6);
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("result", 1);
  vars.put("items", items);

  ProcessInstance procInst = runtimeService.startProcessInstanceByKey("multiInstanceServiceTask", vars);
  Integer result = (Integer) runtimeService.getVariable(procInst.getId(), "result");
  assertEquals(720, result.intValue());

  Execution waitExecution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId("wait").singleResult();
  runtimeService.trigger(waitExecution.getId());
  assertProcessEnded(procInst.getId());
}
 
Example #25
Source File: RuntimeServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testMessageEventReceivedNonExistingExecution() {
  try {
    runtimeService.messageEventReceived("alert", "nonexistingExecution");
    fail("exception expected");
  } catch (ActivitiObjectNotFoundException ae) {
    assertEquals(Execution.class, ae.getObjectClass());
  }
}
 
Example #26
Source File: ProcessInstanceVariableCollectionResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "List of variables for a process instance", tags = { "Process Instances" },
    notes="In case the variable is a binary variable or serializable, the valueUrl points to an URL to fetch the raw value. If it’s a plain variable, the value is present in the response. Note that only local scoped variables are returned, as there is no global scope for process-instance variables.")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the process instance was found and variables are returned."),
    @ApiResponse(code = 400, message = "Indicates the requested process instance was not found.")
})
@RequestMapping(value = "/runtime/process-instances/{processInstanceId}/variables", method = RequestMethod.GET, produces = "application/json")
public List<RestVariable> getVariables(@ApiParam(name = "processInstanceId", value="The id of the process instance to the variables for.") @PathVariable String processInstanceId, @RequestParam(value = "scope", required = false) String scope, HttpServletRequest request) {

  Execution execution = getProcessInstanceFromRequest(processInstanceId);
  return processVariables(execution, scope, RestResponseFactory.VARIABLE_PROCESS);
}
 
Example #27
Source File: RuntimeServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testGetVariablesUnexistingExecutionId() {
  try {
    runtimeService.getVariables("unexistingExecutionId");
    fail("ActivitiException expected");
  } catch (ActivitiObjectNotFoundException ae) {
    assertTextPresent("execution unexistingExecutionId doesn't exist", ae.getMessage());
    assertEquals(Execution.class, ae.getObjectClass());
  }
}
 
Example #28
Source File: Activiti6ExecutionTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testSubProcessEvents() {
  SubProcessEventListener listener = new SubProcessEventListener();
  processEngineConfiguration.getEventDispatcher().addEventListener(listener);
  
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("subProcessEvents");
  
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  Execution subProcessExecution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("subProcess").singleResult();
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(processInstance.getId());
  
  // Verify Events
  List<ActivitiEvent> events = listener.getEventsReceived();
  assertEquals(2, events.size());
  
  ActivitiActivityEvent event = (ActivitiActivityEvent) events.get(0);
  assertEquals("subProcess", event.getActivityType());
  assertEquals(subProcessExecution.getId(), event.getExecutionId());
  
  event = (ActivitiActivityEvent) events.get(1);
  assertEquals("subProcess", event.getActivityType());
  assertEquals(subProcessExecution.getId(), event.getExecutionId());
  
  processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
}
 
Example #29
Source File: SignalEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testSignalWaitOnUserTaskBoundaryEvent() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signal-wait");
  Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).signalEventSubscriptionName("waitsig").singleResult();
  assertNotNull(execution);
  runtimeService.signalEventReceived("waitsig", execution.getId());
  execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).signalEventSubscriptionName("waitsig").singleResult();
  assertNull(execution);
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertNotNull(task);
  assertEquals("Wait2", task.getName());
}
 
Example #30
Source File: DefaultContextAssociationManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public Execution getExecution() {
  ExecutionEntity execution = getExecutionFromContext();
  if (execution != null) {
    return execution;
  } else {
    return getScopedAssociation().getExecution();
  }
}