org.flowable.engine.runtime.Execution Java Examples

The following examples show how to use org.flowable.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: HistoricActivityInstanceTest.java    From flowable-engine 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 #2
Source File: BaseExecutionVariableResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void setVariable(Execution execution, String name, Object value, RestVariableScope scope, boolean isNew) {
    // Create can only be done on new variables. Existing variables should
    // be updated using PUT
    boolean hasVariable = hasVariableOnScope(execution, name, scope);
    if (isNew && hasVariable) {
        throw new FlowableException("Variable '" + name + "' is already present on execution '" + execution.getId() + "'.");
    }

    if (!isNew && !hasVariable) {
        throw new FlowableObjectNotFoundException("Execution '" + execution.getId() + "' does not have a variable with name: '" + name + "'.", null);
    }

    if (scope == RestVariableScope.LOCAL) {
        runtimeService.setVariableLocal(execution.getId(), name, value);
    } else {
        if (execution.getParentId() != null) {
            runtimeService.setVariable(execution.getParentId(), name, value);
        } else {
            runtimeService.setVariable(execution.getId(), name, value);
        }
    }
}
 
Example #3
Source File: CdiAsyncPingTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "process/asyncPing.bpmn20.xml" })
public void testRunProcess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncPingProcess");

    List<Execution> executionList = runtimeService.createExecutionQuery().list();
    assertThat(executionList).hasSize(2);

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

    executionList = runtimeService.createExecutionQuery().list();
    assertThat(executionList).isEmpty();

    assertThat(runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count()).isZero();
}
 
Example #4
Source File: HasExecutionVariableCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean execute(CommandContext commandContext) {
    if (executionId == null) {
        throw new FlowableIllegalArgumentException("executionId is null");
    }
    if (variableName == null) {
        throw new FlowableIllegalArgumentException("variableName is null");
    }

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

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

    boolean hasVariable = false;

    if (isLocal) {
        hasVariable = execution.hasVariableLocal(variableName);
    } else {
        hasVariable = execution.hasVariable(variableName);
    }

    return hasVariable;
}
 
Example #5
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@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
    org.flowable.task.api.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 #6
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@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 #7
Source File: DeleteReasonTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testInterruptingBoundaryEvent2() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("deleteReasonReceiveTask");
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("A").singleResult();
    assertNotNull(execution);
    runtimeService.trigger(execution.getId());

    // Timer firing should delete all tasks
    Job timerJob = managementService.createTimerJobQuery().singleResult();
    managementService.moveTimerToExecutableJob(timerJob.getId());
    managementService.executeJob(timerJob.getId());
    
    waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

    assertHistoricActivitiesDeleteReason(processInstance, null, "A");
    assertHistoricActivitiesDeleteReason(processInstance, DeleteReason.BOUNDARY_EVENT_INTERRUPTING, "B", "C", "theSubprocess");
}
 
Example #8
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testMultiInstanceSequentialReceiveTask() {
    runtimeService.startProcessInstanceByKey("multi-instance-receive");
    Execution execution = runtimeService.createExecutionQuery().activityId("theReceiveTask").singleResult();
    assertNotNull(execution);

    // Complete all four of the executions
    while (execution != null) {
        runtimeService.trigger(execution.getId());
        execution = runtimeService.createExecutionQuery().activityId("theReceiveTask").singleResult();
    }

    // There is one task after the task
    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    taskService.complete(task.getId());

    assertEquals(0, runtimeService.createExecutionQuery().count());
}
 
Example #9
Source File: EventSubscriptionQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testQueryByExecutionId() {

    // starting two instances:
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("catchSignal");
    runtimeService.startProcessInstanceByKey("catchSignal");

    // test query by process instance id
    EventSubscription subscription = newEventSubscriptionQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(subscription);

    Execution executionWaitingForSignal = runtimeService.createExecutionQuery().activityId("signalEvent").processInstanceId(processInstance.getId()).singleResult();

    // test query by execution id
    EventSubscription signalSubscription = newEventSubscriptionQuery().executionId(executionWaitingForSignal.getId()).singleResult();
    assertNotNull(signalSubscription);

    assertEquals(signalSubscription, subscription);

    cleanDb();

}
 
Example #10
Source File: AsyncPingTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "process/asyncPing.bpmn20.xml" })
public void testRunProcess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncPingProcess");

    List<Execution> executionList = runtimeService.createExecutionQuery().list();
    assertThat(executionList).hasSize(2);

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

    executionList = runtimeService.createExecutionQuery().list();
    assertThat(executionList).isEmpty();

    assertThat(runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count()).isZero();
}
 
Example #11
Source File: BoundaryConditionalEventTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/engine/test/bpmn/event/conditional/BoundaryConditionalEventTest.testCatchNonInterruptingConditionalOnEmbeddedSubprocess.bpmn20.xml")
public void testCatchNonInterruptingConditionalOnEmbeddedSubprocessWithoutTrigger() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("boundaryConditionalOnEmbeddedSubprocess", 
                    Collections.singletonMap("myVar", "empty"));

    // After process start, usertask in subprocess should exist
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getName()).isEqualTo("subprocessTask");
    
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("catchConditional").singleResult();
    assertThat(execution).isNotNull();
    
    taskService.complete(task.getId());
    
    assertProcessEnded(processInstance.getId());
}
 
Example #12
Source File: ExecutionQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testQueryByTenantIdLike() {
    Execution execution = runtimeService.createExecutionQuery().executionTenantIdLike("%|%%").singleResult();
    assertNotNull(execution);

    execution = runtimeService.createExecutionQuery().executionTenantIdLike("%|_%").singleResult();
    assertNotNull(execution);
}
 
Example #13
Source File: SignalEventSubprocessTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private void testInterruptingUnderProcessDefinition(int expectedNumberOfEventSubscriptions, int numberOfExecutions) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

    // the process instance must have a message event subscription:
    Execution execution = runtimeService.createExecutionQuery().signalEventSubscriptionName("newSignal").singleResult();
    assertThat(execution).isNotNull();
    assertThat(createEventSubscriptionQuery().count()).isEqualTo(expectedNumberOfEventSubscriptions);
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(numberOfExecutions);

    // if we trigger the usertask, the process terminates and the event subscription is removed:
    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();
    assertThat(task.getTaskDefinitionKey()).isEqualTo("task");
    taskService.complete(task.getId());
    assertThat(createEventSubscriptionQuery().count()).isZero();
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isZero();
    assertProcessEnded(processInstance.getId());

    // now we start a new instance but this time we trigger the event subprocess:
    processInstance = runtimeService.startProcessInstanceByKey("process");
    execution = runtimeService.createExecutionQuery().signalEventSubscriptionName("newSignal").singleResult();
    assertThat(execution).isNotNull();
    runtimeService.signalEventReceived("newSignal");

    task = taskService.createTaskQuery().singleResult();
    assertThat(task.getTaskDefinitionKey()).isEqualTo("eventSubProcessTask");
    taskService.complete(task.getId());
    assertProcessEnded(processInstance.getId());
    assertThat(createEventSubscriptionQuery().count()).isZero();
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isZero();
}
 
Example #14
Source File: JavaServiceTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testExpressionFieldInjection() {
    Map<String, Object> vars = new HashMap<>();
    vars.put("name", "kermit");
    vars.put("gender", "male");
    vars.put("genderBean", new GenderBean());

    ProcessInstance pi = runtimeService.startProcessInstanceByKey("expressionFieldInjection", vars);
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).activityId("waitState").singleResult();

    assertThat(runtimeService.getVariable(execution.getId(), "var2")).isEqualTo("timrek .rM olleH");
    assertThat(runtimeService.getVariable(execution.getId(), "var1")).isEqualTo("elam :si redneg ruoY");
}
 
Example #15
Source File: JavaServiceTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testExpressionFieldInjectionWithSkipExpression() {
    Map<String, Object> vars = new HashMap<>();
    vars.put("name", "kermit");
    vars.put("gender", "male");
    vars.put("genderBean", new GenderBean());
    vars.put("_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);
    vars.put("skip", false);

    ProcessInstance pi = runtimeService.startProcessInstanceByKey("expressionFieldInjectionWithSkipExpression", vars);
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).activityId("waitState").singleResult();

    assertThat(execution).isNotNull();

    assertThat(runtimeService.getVariable(execution.getId(), "var2")).isEqualTo("timrek .rM olleH");
    assertThat(runtimeService.getVariable(execution.getId(), "var1")).isEqualTo("elam :si redneg ruoY");

    Map<String, Object> vars2 = new HashMap<>();
    vars2.put("name", "kermit");
    vars2.put("gender", "male");
    vars2.put("genderBean", new GenderBean());
    vars2.put("_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);
    vars2.put("skip", true);

    ProcessInstance pi2 = runtimeService.startProcessInstanceByKey("expressionFieldInjectionWithSkipExpression", vars2);
    Execution execution2 = runtimeService.createExecutionQuery().processInstanceId(pi2.getId()).activityId("waitState").singleResult();

    assertThat(execution2).isNotNull();

    Map<String, Object> pi2VarMap = runtimeService.getVariables(pi2.getProcessInstanceId());
    assertThat(pi2VarMap)
            .doesNotContainKey("var1")
            .doesNotContainKey("var2");
}
 
Example #16
Source File: ExecutionVariableCollectionResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Delete all variables for an execution", tags = { "Executions" })
@ApiResponses(value = {
        @ApiResponse(code = 204, message = "Indicates the execution was found and variables have been deleted."),
        @ApiResponse(code = 404, message = "Indicates the requested execution was not found.")
})
@DeleteMapping(value = "/runtime/executions/{executionId}/variables")
public void deleteLocalVariables(@ApiParam(name = "executionId") @PathVariable String executionId, HttpServletResponse response) {
    Execution execution = getExecutionFromRequest(executionId);
    deleteAllLocalVariables(execution, response);
}
 
Example #17
Source File: RuntimeServiceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testSignalWithProcessVariables() {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testSignalWithProcessVariables");
    Map<String, Object> processVariables = new HashMap<>();
    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());
    assertThat(variables).isEqualTo(processVariables);
}
 
Example #18
Source File: ChangeStateTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/oneTaskSubProcess.bpmn20.xml" })
public void testSetCurrentActivityInUnstartedSubProcessWithModeledDataObject() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("startSimpleSubProcess");

    runtimeService.createChangeActivityStateBuilder()
            .processInstanceId(processInstance.getId())
            .moveActivityIdTo("taskBefore", "subTask")
            .changeState();

    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getTaskDefinitionKey()).isEqualTo("subTask");

    List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
    assertThat(executions).hasSize(3);

    Execution subProcessExecution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("subProcess")
            .singleResult();
    assertThat(runtimeService.getVariableLocal(subProcessExecution.getId(), "name", String.class)).isNotNull();

    DataObject nameDataObject = runtimeService.getDataObjectLocal(subProcessExecution.getId(), "name");
    assertThat(nameDataObject).isNotNull();
    assertThat(nameDataObject.getValue()).isEqualTo("John");

    taskService.complete(task.getId());

    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getTaskDefinitionKey()).isEqualTo("taskAfter");
    taskService.complete(task.getId());

    assertProcessEnded(processInstance.getId());
}
 
Example #19
Source File: RuntimeServiceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testFindActiveActivityIdsUnexistingExecututionId() {
    try {
        runtimeService.getActiveActivityIds("unexistingExecutionId");
        fail("ActivitiException expected");
    } catch (FlowableObjectNotFoundException ae) {
        assertTextPresent("execution unexistingExecutionId doesn't exist", ae.getMessage());
        assertEquals(Execution.class, ae.getObjectClass());
    }
}
 
Example #20
Source File: ConditionalIntermediateCatchEventTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/engine/test/bpmn/event/conditional/ConditionalIntermediateCatchEventTest.testConditionalIntermediateCatchEvent.bpmn20.xml")
public void testConditionalIntermediateCatchEventWithEvaluation() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("conditionalCatchEvent", 
                    Collections.singletonMap("myVar", "empty"));

    // After process start, usertask in subprocess should exist
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getTaskDefinitionKey()).isEqualTo("taskBeforeConditionalCatch");
    
    taskService.complete(task.getId());
    
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("catchConditional").singleResult();
    assertThat(execution).isNotNull();
    
    runtimeService.evaluateConditionalEvents(processInstance.getId());
    
    assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).count()).isZero();
    
    runtimeService.evaluateConditionalEvents(processInstance.getId(), Collections.singletonMap("myVar", "test"));

    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getTaskDefinitionKey()).isEqualTo("taskAfterConditionalCatch");
    
    taskService.complete(task.getId());
    assertProcessEnded(processInstance.getId());
}
 
Example #21
Source File: ExecutionQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/runtime/concurrentExecution.bpmn20.xml" })
public void testExecutionQueryWithProcessVariable() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("x", "parent");
    variables.put("xIgnoreCase", "PaReNt");
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("concurrent", variables);

    List<Execution> concurrentExecutions = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).list();
    assertEquals(3, concurrentExecutions.size());
    for (Execution execution : concurrentExecutions) {
        if (!((ExecutionEntity) execution).isProcessInstanceType()) {
            // only the concurrent executions, not the root one, would be cooler to query that directly, see https://activiti.atlassian.net/browse/ACT-1373
            runtimeService.setVariableLocal(execution.getId(), "x", "child");
            runtimeService.setVariableLocal(execution.getId(), "xIgnoreCase", "ChILD");
        }
    }

    assertEquals(2, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).variableValueEquals("x", "child").count());
    assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).variableValueEquals("x", "parent").count());

    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("x", "parent").count());
    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEquals("x", "xxx").count());

    // Test value-only query
    assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("child").count());
    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEquals("parent").count());

    // Test ignore-case queries
    assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEqualsIgnoreCase("xIgnoreCase", "CHILD").count());
    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueEqualsIgnoreCase("xIgnoreCase", "PARENT").count());

    // Test ignore-case queries
    assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEqualsIgnoreCase("xIgnoreCase", "paRent").count());
    assertEquals(3, runtimeService.createExecutionQuery().processInstanceId(pi.getId()).processVariableValueNotEqualsIgnoreCase("xIgnoreCase", "chilD").count());

}
 
Example #22
Source File: RuntimeServiceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void testSetVariablesUnexistingExecutionId() {
    try {
        runtimeService.setVariables("unexistingexecution", Collections.EMPTY_MAP);
        fail("ActivitiException expected");
    } catch (FlowableObjectNotFoundException ae) {
        assertTextPresent("execution unexistingexecution doesn't exist", ae.getMessage());
        assertEquals(Execution.class, ae.getObjectClass());
    }
}
 
Example #23
Source File: ProcessInstanceMigrationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { TEST_PROCESS_CALL_ACTIVITY })
public void testSetProcessDefinitionVersionWithCallActivity() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("parentProcess");

    // check that receive task has been reached
    Execution execution = runtimeService.createExecutionQuery().activityId("waitState1").processDefinitionKey("childProcess").singleResult();
    assertThat(execution).isNotNull();

    // deploy new version of the process definition
    org.flowable.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_CALL_ACTIVITY).deploy();
    assertThat(repositoryService.createProcessDefinitionQuery().processDefinitionKey("parentProcess").count()).isEqualTo(2);

    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));

    // signal process instance
    runtimeService.trigger(execution.getId());

    // should be finished now
    assertThat(runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).count()).isZero();

    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #24
Source File: ExecutionQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryStartedBy() throws Exception {
    final String authenticatedUser = "user1";
    identityService.setAuthenticatedUserId(authenticatedUser);
    runtimeService.startProcessInstanceByKey("oneTaskProcess");

    List<Execution> executions = runtimeService.createExecutionQuery().startedBy(authenticatedUser).list();

    assertThat(executions).hasSize(1);
}
 
Example #25
Source File: ChangeStateForCallActivityTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/twoTasksParentProcess.bpmn20.xml", "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testSetCurrentActivityInParentProcess() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoTasksParentProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getTaskDefinitionKey()).isEqualTo("firstTask");

    taskService.complete(task.getId());

    ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(processInstance.getId()).singleResult();
    assertThat(subProcessInstance).isNotNull();

    task = taskService.createTaskQuery().processInstanceId(subProcessInstance.getId()).singleResult();
    assertThat(task.getTaskDefinitionKey()).isEqualTo("theTask");

    runtimeService.createChangeActivityStateBuilder()
            .processInstanceId(subProcessInstance.getId())
            .moveActivityIdToParentActivityId("theTask", "secondTask")
            .changeState();

    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getTaskDefinitionKey()).isEqualTo("secondTask");

    assertThat(runtimeService.createProcessInstanceQuery().superProcessInstanceId(processInstance.getId()).count()).isEqualTo(0);
    assertThat(runtimeService.createProcessInstanceQuery().processInstanceId(subProcessInstance.getId()).count()).isEqualTo(0);

    List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).onlyChildExecutions().list();
    assertThat(executions).hasSize(1);

    taskService.complete(task.getId());

    assertProcessEnded(processInstance.getId());
}
 
Example #26
Source File: TriggerableServiceTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testAsyncJobs() {
    String processId = runtimeService.startProcessInstanceByKey("process").getProcessInstanceId();
    
    List<Job> jobs = managementService.createJobQuery().processInstanceId(processId).list();
    assertEquals(1, jobs.size());
    assertEquals(AsyncContinuationJobHandler.TYPE, jobs.get(0).getJobHandlerType());
    
    waitForJobExecutorToProcessAllJobs(7000L, 250L);

    Execution execution = runtimeService.createExecutionQuery().processInstanceId(processId).activityId("service1").singleResult();
    assertNotNull(execution);
    int count = (int) runtimeService.getVariable(processId, "count");
    assertEquals(1, count);

    Map<String,Object> processVariables = new HashMap<>();
    processVariables.put("count", ++count);
    runtimeService.triggerAsync(execution.getId(), processVariables);
    
    jobs = managementService.createJobQuery().processInstanceId(processId).list();
    assertEquals(1, jobs.size());
    assertEquals(AsyncTriggerJobHandler.TYPE, jobs.get(0).getJobHandlerType());
    
    waitForJobExecutorToProcessAllJobs(7000L, 250L);

    execution = runtimeService.createExecutionQuery().processInstanceId(processId).activityId("usertask1").singleResult();
    assertNotNull(execution);
    assertEquals(3, runtimeService.getVariable(processId, "count"));
}
 
Example #27
Source File: ExecutionQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Validate fix for ACT-1896
 */
public void testQueryByActivityIdAndBusinessKeyWithChildren() {
    ExecutionQuery query = runtimeService.createExecutionQuery().activityId("receivePayment")
            .processInstanceBusinessKey("BUSINESS-KEY-1", true);
    assertEquals(1, query.list().size());
    assertEquals(1, query.count());

    Execution execution = query.singleResult();
    assertNotNull(execution);
    assertEquals("receivePayment", execution.getActivityId());
}
 
Example #28
Source File: ExecutionQueryEscapeClauseTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryLikeByQueryVariableValue() {
    Execution execution = runtimeService.createExecutionQuery().variableValueLike("var1", "%|%%").singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance1.getId());

    execution = runtimeService.createExecutionQuery().variableValueLike("var1", "%|_%").singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance2.getId());
}
 
Example #29
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Test to validate fix for ACT-1399: Boundary-event and event-based auditing
 */
@Test
@Deployment
public void testBoundaryEvent() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("boundaryEventProcess");
    // Complete the task with the boundary-event on it
    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task).isNotNull();
    taskService.complete(task.getId());

    assertThat(runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(0L);
    
    waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("boundary").processInstanceId(processInstance.getId()).singleResult();
    assertThat(historicActivityInstance).isNotNull();

    // Now check the history when the boundary-event is fired
    processInstance = runtimeService.startProcessInstanceByKey("boundaryEventProcess");

    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    Execution signalExecution = runtimeService.createExecutionQuery().signalEventSubscriptionName("alert").singleResult();
    runtimeService.signalEventReceived("alert", signalExecution.getId());
    assertThat(runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(0L);
    
    waitForHistoryJobExecutorToProcessAllJobs(7000, 100);

    historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("boundary").processInstanceId(processInstance.getId()).singleResult();

    assertThat(historicActivityInstance).isNotNull();
    assertThat(historicActivityInstance.getStartTime()).isNotNull();
    assertThat(historicActivityInstance.getEndTime()).isNotNull();
}
 
Example #30
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testParallelScriptTasks() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("sum", 0);
    vars.put("nrOfLoops", 10);
    runtimeService.startProcessInstanceByKey("miParallelScriptTask", vars);
    Execution waitStateExecution = runtimeService.createExecutionQuery().singleResult();
    int sum = (Integer) runtimeService.getVariable(waitStateExecution.getId(), "sum");
    assertEquals(45, sum);
}