org.flowable.engine.runtime.ProcessInstance Java Examples

The following examples show how to use org.flowable.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: TerminateEndEventTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {
        "org/flowable/engine/test/bpmn/event/end/TerminateEndEventTest.testTerminateWithCallActivity.bpmn",
        "org/flowable/engine/test/bpmn/event/end/TerminateEndEventTest.subProcessNoTerminate.bpmn"
})
public void testTerminateWithCallActivity() throws Exception {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample");

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

    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preTerminateEnd").singleResult();
    taskService.complete(task.getId());

    assertProcessEnded(pi.getId());
    assertHistoricProcessInstanceDetails(pi);

    assertHistoricProcessInstanceDeleteReason(pi, DeleteReason.TERMINATE_END_EVENT);
    assertHistoricTasksDeleteReason(pi, null, "check before termination");
    assertHistoricTasksDeleteReason(subProcessInstance, DeleteReason.TERMINATE_END_EVENT, "Perform Sample");
    assertHistoricActivitiesDeleteReason(pi, null, "preTerminateEnd");
    assertHistoricActivitiesDeleteReason(subProcessInstance, DeleteReason.TERMINATE_END_EVENT, "task");
}
 
Example #2
Source File: ProcessInstanceIdentityLinkResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a specific involved people from process instance", tags = { "Process Instance Identity Links" }, nickname = "getProcessInstanceIdentityLinks")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the process instance was found and the specified link is retrieved."),
        @ApiResponse(code = 404, message = "Indicates the requested process instance was not found or the link to delete does not exist. The response status contains additional information about the error.")
})
@GetMapping(value = "/runtime/process-instances/{processInstanceId}/identitylinks/users/{identityId}/{type}", produces = "application/json")
public RestIdentityLink getIdentityLink(@ApiParam(name = "processInstanceId") @PathVariable("processInstanceId") String processInstanceId, @ApiParam(name = "identityId") @PathVariable("identityId") String identityId,
        @ApiParam(name = "type") @PathVariable("type") String type,
        HttpServletRequest request) {

    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);

    validateIdentityLinkArguments(identityId, type);

    IdentityLink link = getIdentityLink(identityId, type, processInstance.getId());
    return restResponseFactory.createRestIdentityLink(link);
}
 
Example #3
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceNoop() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("noopProcess");

    HistoricActivityInstance historicActivityInstance = historyService
            .createHistoricActivityInstanceQuery()
            .activityId("noop")
            .singleResult();

    assertEquals("noop", historicActivityInstance.getActivityId());
    assertEquals("serviceTask", historicActivityInstance.getActivityType());
    assertNotNull(historicActivityInstance.getProcessDefinitionId());
    assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
    assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
    assertNotNull(historicActivityInstance.getStartTime());
    assertNotNull(historicActivityInstance.getEndTime());
    assertTrue(historicActivityInstance.getDurationInMillis() >= 0);
}
 
Example #4
Source File: DynamicUserTaskTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testChangeFormKey() {
    // first test without changing the form key
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");
    String processDefinitionId = processInstance.getProcessDefinitionId();

    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertEquals("test", task.getFormKey());
    taskService.complete(task.getId());

    assertProcessEnded(processInstance.getId());

    // now test with changing the form key
    ObjectNode infoNode = dynamicBpmnService.changeUserTaskFormKey("task1", "test2");
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);

    processInstance = runtimeService.startProcessInstanceByKey("dynamicUserTask");

    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertEquals("test2", task.getFormKey());
    taskService.complete(task.getId());

    assertProcessEnded(processInstance.getId());
}
 
Example #5
Source File: ProcessInstanceSuspensionTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testSignalEventReceivedAfterProcessInstanceSuspended() {

    final String signal = "Some Signal";

    // Test if process instance can be completed using the signal
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.signalEventReceived(signal);
    assertThat(runtimeService.createProcessInstanceQuery().count()).isZero();

    // Now test when suspending the process instance: the process instance
    // shouldn't be continued
    processInstance = runtimeService.startProcessInstanceByKey("signalSuspendedProcessInstance");
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    runtimeService.signalEventReceived(signal);
    assertThat(runtimeService.createProcessInstanceQuery().count()).isEqualTo(1);

    runtimeService.signalEventReceived(signal, new HashMap<>());
    assertThat(runtimeService.createProcessInstanceQuery().count()).isEqualTo(1);

    // Activate and try again
    runtimeService.activateProcessInstanceById(processInstance.getId());
    runtimeService.signalEventReceived(signal);
    assertThat(runtimeService.createProcessInstanceQuery().count()).isZero();
}
 
Example #6
Source File: IntermediateTimerEventTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testCatchingTimerEvent() throws Exception {

    // Set the clock fixed
    Date startTime = new Date();

    // After process start, there should be timer created
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("intermediateTimerEventExample");
    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    assertEquals(1, jobQuery.count());

    // After setting the clock to time '50minutes and 5 seconds', the second timer should fire
    processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((50 * 60 * 1000) + 5000)));
    waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(7000L, 200L);

    assertEquals(0, jobQuery.count());
    assertProcessEnded(pi.getProcessInstanceId());
}
 
Example #7
Source File: ProcessDefinitionScopedEventListenerDefinitionTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Test to verify listeners defined in the BPMN xml are added to the process definition and are active, for all entity types
 */
@Test
@Deployment
public void testProcessDefinitionListenerDefinitionEntities() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testEventListeners");
    assertThat(processInstance).isNotNull();
    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task).isNotNull();

    // Attachment entity
    TestFlowableEventListener theListener = (TestFlowableEventListener) processEngineConfiguration.getBeans().get("testAttachmentEventListener");
    assertThat(theListener).isNotNull();
    assertThat(theListener.getEventsReceived()).isEmpty();

    taskService.createAttachment("test", task.getId(), processInstance.getId(), "test", "test", "url");
    assertThat(theListener.getEventsReceived())
            .extracting(FlowableEvent::getType)
            .containsExactly(FlowableEngineEventType.ENTITY_CREATED, FlowableEngineEventType.ENTITY_INITIALIZED);
}
 
Example #8
Source File: TransientVariablesTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testTriggerWithTransientVars() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transientVarsTest");

    Execution executionInWait1 = runtimeService.createExecutionQuery().activityId("wait1").singleResult();
    runtimeService.trigger(executionInWait1.getId(), CollectionUtil.singletonMap("persistentVar", "persistentValue01"));

    Execution executionInWait2 = runtimeService.createExecutionQuery().activityId("wait2").singleResult();
    runtimeService.trigger(executionInWait2.getId(), CollectionUtil.singletonMap("anotherPersistentVar", "persistentValue02"), CollectionUtil.singletonMap("transientVar", "transientValue"));

    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    String result = (String) taskService.getVariable(task.getId(), "result");
    assertEquals("persistentValue02persistentValue01transientValue", result);

    assertNull(runtimeService.getVariable(processInstance.getId(), "transientVar"));
}
 
Example #9
Source File: RestResponseFactory.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public ProcessInstanceResponse createProcessInstanceResponse(ProcessInstance processInstance, boolean returnVariables,
        Map<String, Object> runtimeVariableMap, List<HistoricVariableInstance> historicVariableList) {

    RestUrlBuilder urlBuilder = createUrlBuilder();
    ProcessInstanceResponse result = internalCreateProcessInstanceResponse(processInstance, urlBuilder);

    if (returnVariables) {

        if (processInstance.isEnded()) {
            if (historicVariableList != null) {
                for (HistoricVariableInstance historicVariable : historicVariableList) {
                    result.addVariable(createRestVariable(historicVariable.getVariableName(), historicVariable.getValue(), RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false,
                            urlBuilder));
                }
            }

        } else {
            if (runtimeVariableMap != null) {
                for (String name : runtimeVariableMap.keySet()) {
                    result.addVariable(createRestVariable(name, runtimeVariableMap.get(name), RestVariableScope.LOCAL, processInstance.getId(), VARIABLE_PROCESS, false, urlBuilder));
                }
            }
        }
    }
    return result;
}
 
Example #10
Source File: CamelVariableBodyTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {"process/HelloCamelBody.bpmn20.xml"})
public void testCamelBody() throws Exception {
    service1.expectedBodiesReceived("hello world");
    Map<String, Object> varMap = new HashMap<>();
    varMap.put("camelBody", "hello world");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HelloCamel", varMap);
    // Ensure that the variable is equal to the expected value.
    assertThat(runtimeService.getVariable(processInstance.getId(), "camelBody")).isEqualTo("hello world");
    service1.assertIsSatisfied();

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

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

    // Complete the task.
    taskService.complete(task.getId());
}
 
Example #11
Source File: RestResponseFactory.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected ProcessInstanceResponse internalCreateProcessInstanceResponse(ProcessInstance processInstance, RestUrlBuilder urlBuilder) {
    ProcessInstanceResponse result = new ProcessInstanceResponse();
    result.setActivityId(processInstance.getActivityId());
    result.setStartUserId(processInstance.getStartUserId());
    result.setStartTime(processInstance.getStartTime());
    result.setBusinessKey(processInstance.getBusinessKey());
    result.setId(processInstance.getId());
    result.setName(processInstance.getName());
    result.setProcessDefinitionId(processInstance.getProcessDefinitionId());
    result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId()));
    result.setEnded(processInstance.isEnded());
    result.setSuspended(processInstance.isSuspended());
    result.setUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
    result.setCallbackId(processInstance.getCallbackId());
    result.setCallbackType(processInstance.getCallbackType());
    result.setReferenceId(processInstance.getReferenceId());
    result.setReferenceType(processInstance.getReferenceType());
    result.setTenantId(processInstance.getTenantId());

    if (processInstance.isEnded()) {
        result.setCompleted(true);
    } else {
        result.setCompleted(false);
    }
    return result;
}
 
Example #12
Source File: ExternalWorkerJobQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/engine/test/api/mgmt/ExternalWorkerJobQueryTest.bpmn20.xml")
public void testQueryByProcessDefinitionId() {
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("externalWorkerJobQueryTest");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("externalWorkerJobQueryTest");
    ExternalWorkerJobQuery query = managementService.createExternalWorkerJobQuery().processDefinitionId(processInstance1.getProcessDefinitionId());
    assertThat(query.count()).isEqualTo(4);
    assertThat(query.list())
            .extracting(ExternalWorkerJob::getProcessInstanceId)
            .containsOnly(processInstance1.getId(), processInstance2.getId());

    query = managementService.createExternalWorkerJobQuery().processDefinitionId("invalid");
    assertThat(query.count()).isEqualTo(0);
    assertThat(query.list()).isEmpty();
    assertThat(query.singleResult()).isNull();
}
 
Example #13
Source File: TaskServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testCompleteWithTaskLocalParameters() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testTaskLocalVars");

    // Fetch first task
    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();

    // Complete first task
    Map<String, Object> taskParams = new HashMap<>();
    taskParams.put("a", 1);
    taskParams.put("b", 1);
    taskService.complete(task.getId(), taskParams, true);

    // Verify vars are not stored process instance wide
    assertThat(runtimeService.getVariable(processInstance.getId(), "a")).isNull();
    assertThat(runtimeService.getVariable(processInstance.getId(), "b")).isNull();

    // verify script listener has done its job
    assertThat(runtimeService.getVariable(processInstance.getId(), "sum")).isEqualTo(2);

    // Fetch second task
    taskService.createTaskQuery().singleResult();
}
 
Example #14
Source File: TaskServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testRemoveVariableLocal() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    org.flowable.task.api.Task currentTask = taskService.createTaskQuery().singleResult();

    taskService.setVariableLocal(currentTask.getId(), "variable1", "value1");
    assertThat(taskService.getVariable(currentTask.getId(), "variable1")).isEqualTo("value1");
    assertThat(taskService.getVariableLocal(currentTask.getId(), "variable1")).isEqualTo("value1");

    taskService.removeVariableLocal(currentTask.getId(), "variable1");

    assertThat(taskService.getVariable(currentTask.getId(), "variable1")).isNull();
    assertThat(taskService.getVariableLocal(currentTask.getId(), "variable1")).isNull();

    checkHistoricVariableUpdateEntity("variable1", processInstance.getId());
}
 
Example #15
Source File: ProcessInstanceSuspensionTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/db/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisisbleToAcquisitionIfInstanceSuspended() {

    ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance pi = runtimeService.startProcessInstanceByKey(pd.getKey());

    // now there is one job:
    Job job = managementService.createTimerJobQuery().singleResult();
    assertNotNull(job);

    makeSureJobDue(job);

    // suspend the process instance:
    runtimeService.suspendProcessInstanceById(pi.getId());

    job = managementService.createTimerJobQuery().singleResult();
    assertNull(job);

    assertEquals(1, managementService.createSuspendedJobQuery().processInstanceId(pi.getId()).count());
}
 
Example #16
Source File: TaskServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
        "org/activiti/engine/test/api/twoTasksProcess.bpmn20.xml" })
public void testCompleteWithParametersTask() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoTasksProcess");

    // Fetch first task
    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();
    assertEquals("First task", task.getName());

    // Complete first task
    Map<String, Object> taskParams = new HashMap<String, Object>();
    taskParams.put("myParam", "myValue");
    taskService.complete(task.getId(), taskParams);

    // Fetch second task
    task = taskService.createTaskQuery().singleResult();
    assertEquals("Second task", task.getName());

    // Verify task parameters set on execution
    Map<String, Object> variables = runtimeService.getVariables(processInstance.getId());
    assertEquals(1, variables.size());
    assertEquals("myValue", variables.get("myParam"));
}
 
Example #17
Source File: TaskDueDateExtensionsTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testDueDateStringExtension() throws Exception {

    Map<String, Object> variables = new HashMap<>();
    variables.put("dateVariable", "1986-07-06T12:10:00");

    // Start process-instance, passing date that should be used as dueDate
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dueDateExtension", variables);

    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    assertNotNull(task.getDueDate());
    Date date = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").parse("06-07-1986 12:10:00");
    assertEquals(date, task.getDueDate());
}
 
Example #18
Source File: TaskServiceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testTaskAttachmentWithProcessInstanceId() {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {

        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);
        assertThat(attachment.getName()).isEqualTo("weatherforcast");
        assertThat(attachment.getDescription()).isEqualTo("temperatures and more");
        assertThat(attachment.getType()).isEqualTo("web page");
        assertThat(attachment.getProcessInstanceId()).isEqualTo(processInstanceId);
        assertThat(attachment.getTaskId()).isNull();
        assertThat(attachment.getUrl()).isEqualTo("http://weather.com");
        assertThat(taskService.getAttachmentContent(attachment.getId())).isNull();

        // Finally, clean up
        taskService.deleteAttachment(attachment.getId());

        // TODO: Bad API design. Need to fix attachment/comment properly
        ((TaskServiceImpl) taskService).deleteComments(null, processInstanceId);
    }
}
 
Example #19
Source File: ProcessInstanceMigrationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { TEST_PROCESS_NESTED_SUB_EXECUTIONS })
public void testSetProcessDefinitionVersionSubExecutionsNested() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("forkJoinNested");

    // check that the user tasks have been reached
    assertEquals(2, taskService.createTaskQuery().count());

    // deploy new version of the process definition
    org.flowable.engine.repository.Deployment deployment = repositoryService
            .createDeployment()
            .addClasspathResource(TEST_PROCESS_NESTED_SUB_EXECUTIONS)
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());

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

    // check that all executions of the instance now use the new process definition version
    ProcessDefinition newProcessDefinition = repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionVersion(2)
            .singleResult();

    List<Execution> executions = runtimeService
            .createExecutionQuery()
            .processInstanceId(pi.getId())
            .list();
    for (Execution execution : executions) {
        assertEquals(newProcessDefinition.getId(), ((ExecutionEntity) execution).getProcessDefinitionId());
    }

    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #20
Source File: RuntimeServiceTest.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 testStartByProcessInstanceBuilderWithFallbackToDefaultTenant() {
    ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();

    ProcessInstance processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess")
            .tenantId("flowable")
            .fallbackToDefaultTenant()
            .start();

    assertThat(processInstance).isNotNull();
}
 
Example #21
Source File: ExpressionServiceTaskTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testSetServiceResultToProcessVariables() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("bean", new ValueBean("ok"));
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("setServiceResultToProcessVariables", variables);
    assertEquals("ok", runtimeService.getVariable(pi.getId(), "result"));
}
 
Example #22
Source File: JobQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private void verifyFailedJob(TimerJobQuery query, ProcessInstance processInstance) {
    verifyQueryResults(query, 1);

    Job failedJob = query.singleResult();
    assertNotNull(failedJob);
    assertEquals(processInstance.getId(), failedJob.getProcessInstanceId());
    assertNotNull(failedJob.getExceptionMessage());
    assertTextPresent(EXCEPTION_MESSAGE, failedJob.getExceptionMessage());
}
 
Example #23
Source File: InstanceInvolvementTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testOrOneInvolvedGroupInNone() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    runtimeService.addGroupIdentityLink(processInstance.getId(), "testGroup", IdentityLinkType.PARTICIPANT);
    runtimeService.deleteGroupIdentityLink(processInstance.getId(), "testGroup", IdentityLinkType.PARTICIPANT);

    assertEquals(0L, runtimeService.createProcessInstanceQuery().
        or().processInstanceId("undefinedId").involvedGroups(Collections.singleton("testGroup")).endOr().count());
}
 
Example #24
Source File: JPAVariableTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testUpdateJPAEntityValues() {
    setupJPAEntityToUpdate();
    Map<String, Object> variables = new HashMap<>();
    variables.put("entityToUpdate", entityToUpdate);

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

    // Servicetask in process 'UpdateJPAValuesProcess' should have set value
    // on entityToUpdate.
    Object updatedEntity = runtimeService.getVariable(processInstance.getId(), "entityToUpdate");
    assertThat(updatedEntity).isInstanceOf(FieldAccessJPAEntity.class);
    assertThat(((FieldAccessJPAEntity) updatedEntity).getValue()).isEqualTo("updatedValue");
}
 
Example #25
Source File: DynamicProcessDefinitionSummaryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/bpmn/dynamic/dynamic-bpmn-test-process.bpmn20.xml" })
public void testTheCandidateUserOfTheFirstTasksIsChangedMultipleTimes() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTest");
    String processDefinitionId = processInstance.getProcessDefinitionId();

    ObjectNode processInfo = dynamicBpmnService.changeUserTaskCandidateUser(TASK_ONE_SID, "bob", false);
    dynamicBpmnService.changeUserTaskCandidateUser(TASK_ONE_SID, "david", false, processInfo);
    dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, processInfo);

    ArrayNode bpmnModelCandidateUsers = processEngineConfiguration.getObjectMapper().createArrayNode();
    bpmnModelCandidateUsers.add("david");

    ArrayNode dynamicCandidateUsers = processEngineConfiguration.getObjectMapper().createArrayNode();
    dynamicCandidateUsers.add("bob");
    dynamicCandidateUsers.add("david");

    DynamicProcessDefinitionSummary summary = dynamicBpmnService.getDynamicProcessDefinitionSummary(processDefinitionId);

    JsonNode taskOneNode = summary.getElement(TASK_ONE_SID).get(ELEMENT_PROPERTIES);
    assertThat((ArrayNode) taskOneNode.get(USER_TASK_CANDIDATE_USERS).get(BPMN_MODEL_VALUE), is(bpmnModelCandidateUsers));
    assertThat((ArrayNode) taskOneNode.get(USER_TASK_CANDIDATE_USERS).get(DYNAMIC_VALUE), is(dynamicCandidateUsers));

    // verify if runtime is up to date
    runtimeService.startProcessInstanceById(processDefinitionId);

    org.flowable.task.api.Task bobTask = taskService.createTaskQuery().taskCandidateUser("bob").singleResult();
    assertThat("Bob must have one task", bobTask, is(notNullValue()));

    List<org.flowable.task.api.Task> davidTasks = taskService.createTaskQuery().taskCandidateUser("david").list();
    assertThat("David must have two task", davidTasks.size(), is(2));
}
 
Example #26
Source File: CompetingSignalsTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/concurrency/CompetingSignalsTest.testCompetingSignals.bpmn20.xml" })
public void testCompetingSignalsWithRetry() throws Exception {
    RuntimeServiceImpl runtimeServiceImpl = (RuntimeServiceImpl) runtimeService;
    CommandExecutorImpl before = (CommandExecutorImpl) runtimeServiceImpl.getCommandExecutor();
    try {
        CommandInterceptor retryInterceptor = new RetryInterceptor();
        retryInterceptor.setNext(before.getFirst());

        runtimeServiceImpl.setCommandExecutor(new CommandExecutorImpl(before.getDefaultConfig(), retryInterceptor));

        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("CompetingSignalsProcess");
        String processInstanceId = processInstance.getId();

        LOGGER.debug("test thread starts thread one");
        SignalThread threadOne = new SignalThread(processInstanceId);
        threadOne.startAndWaitUntilControlIsReturned();

        LOGGER.debug("test thread continues to start thread two");
        SignalThread threadTwo = new SignalThread(processInstanceId);
        threadTwo.startAndWaitUntilControlIsReturned();

        LOGGER.debug("test thread notifies thread 1");
        threadOne.proceedAndWaitTillDone();
        assertNull(threadOne.exception);

        LOGGER.debug("test thread notifies thread 2");
        threadTwo.proceedAndWaitTillDone();
        assertNull(threadTwo.exception);
    } finally {
        // restore the command executor
        runtimeServiceImpl.setCommandExecutor(before);
    }

}
 
Example #27
Source File: HistoricActivityInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceForEventsQuery() {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("eventProcess");
    assertEquals(1, taskService.createTaskQuery().count());
    runtimeService.signalEventReceived("signal");
    assertProcessEnded(pi.getId());

    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("noop").list().size());
    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("userTask").list().size());
    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("intermediate-event").list().size());
    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("start").list().size());
    assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("end").list().size());

    // TODO: Discuss if boundary events will occur in the log!
    // assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("boundaryEvent").list().size());

    HistoricActivityInstance intermediateEvent = historyService.createHistoricActivityInstanceQuery().activityId("intermediate-event").singleResult();
    assertNotNull(intermediateEvent.getStartTime());
    assertNotNull(intermediateEvent.getEndTime());

    HistoricActivityInstance startEvent = historyService.createHistoricActivityInstanceQuery().activityId("start").singleResult();
    assertNotNull(startEvent.getStartTime());
    assertNotNull(startEvent.getEndTime());

    HistoricActivityInstance endEvent = historyService.createHistoricActivityInstanceQuery().activityId("end").singleResult();
    assertNotNull(endEvent.getStartTime());
    assertNotNull(endEvent.getEndTime());
}
 
Example #28
Source File: TaskQueryTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/task/TaskQueryTest.testProcessDefinition.bpmn20.xml" })
public void testTaskDueAfterOn() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    // Set due-date on task
    Calendar dueDateCal = Calendar.getInstance();
    task.setDueDate(dueDateCal.getTime());
    taskService.saveTask(task);

    Calendar oneHourAgo = Calendar.getInstance();
    oneHourAgo.setTime(dueDateCal.getTime());
    oneHourAgo.add(Calendar.HOUR, -1);

    Calendar oneHourLater = Calendar.getInstance();
    oneHourLater.setTime(dueDateCal.getTime());
    oneHourLater.add(Calendar.HOUR, 1);

    assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(oneHourAgo.getTime()).count())
            .isEqualTo(1);
    assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(oneHourLater.getTime()).count())
            .isZero();

    // Update due-date to null, shouldn't show up anymore in query that
    // matched before
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    task.setDueDate(null);
    taskService.saveTask(task);

    assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(oneHourLater.getTime()).count())
            .isZero();
    assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).or().taskId("invalid").taskDueAfter(oneHourAgo.getTime()).count())
            .isZero();
}
 
Example #29
Source File: UserTaskSpringTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/spring/test/usertask/VacationRequest.bpmn20.xml")
public void testFormProperties() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("vacationRequest").singleResult();
    assertThat(formService.getStartFormKey(processDefinition.getId())).isNull();
    StartFormData startFormData = formService.getStartFormData(processDefinition.getId());
    assertThat(startFormData.getFormProperties()).hasSize(3);

    List<FormProperty> formProperties = startFormData.getFormProperties();
    assertThat(formProperties.get(0).getId()).isEqualTo("numberOfDays");
    assertThat(formProperties.get(1).getId()).isEqualTo("startDate");
    assertThat(formProperties.get(2).getId()).isEqualTo("vacationMotivation");

    Map<String, String> startProperties = new HashMap<>();
    startProperties.put("numberOfDays", "10");
    startProperties.put("startDate", "02-02-2018 12:00");
    startProperties.put("vacationMotivation", "Badly needed");
    ProcessInstance processInstance = formService.submitStartFormData(processDefinition.getId(), startProperties);

    Task requestTask = taskService.createTaskQuery().taskDefinitionKey("handleRequest").processInstanceId(processInstance.getId()).singleResult();
    assertThat(requestTask).isNotNull();

    TaskFormData taskFormData = formService.getTaskFormData(requestTask.getId());
    assertThat(taskFormData.getFormProperties()).hasSize(2);

    formProperties = taskFormData.getFormProperties();
    assertThat(formProperties.get(0).getId()).isEqualTo("vacationApproved");
    assertThat(formProperties.get(1).getId()).isEqualTo("managerMotivation");

    Map<String, String> taskProperties = new HashMap<>();
    taskProperties.put("vacationApproved", "true");
    formService.submitTaskFormData(requestTask.getId(), taskProperties);

    assertThat(runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult()).isNull();
}
 
Example #30
Source File: TransientVariablesTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testStartProcessInstanceByMessage() {

    ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
            .messageName("myMessage")
            .transientVariable("variable", "gotoA")
            .start();
    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getName()).isEqualTo("A");
    assertThat(runtimeService.getVariables(processInstance.getId())).isEmpty();

    processInstance = runtimeService.createProcessInstanceBuilder()
            .messageName("myMessage")
            .transientVariable("variable", "gotoB")
            .start();
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getName()).isEqualTo("B");
    assertThat(runtimeService.getVariables(processInstance.getId())).isEmpty();

    processInstance = runtimeService.createProcessInstanceBuilder()
            .messageName("myMessage")
            .transientVariable("variable", "somethingElse")
            .start();
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(task.getName()).isEqualTo("Default");
    assertThat(runtimeService.getVariables(processInstance.getId())).isEmpty();
}