Search in sources :

Example 31 with Task

use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.

the class ProcessApplicationElResolverTest method testCallActivityOutputExpression.

/**
 * Tests that an expression for a call activity output parameter is resolved
 * in the context of the called process definition's application.
 */
public void testCallActivityOutputExpression() {
    // given an instance of the calling process that calls the called process
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("callingProcess");
    // when the called process is completed
    Task calledProcessTask = taskService.createTaskQuery().singleResult();
    taskService.complete(calledProcessTask.getId());
    // then the output mapping should have successfully resolved the expression
    String outVariable = (String) runtimeService.getVariable(instance.getId(), "outVar");
    assertEquals(CalledProcessApplication.STRING_VARIABLE_VALUE, outVariable);
}
Also used : Task(org.camunda.bpm.engine.task.Task) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance)

Example 32 with Task

use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.

the class DelegationAuthorizationTest method testScriptTaskListenerExecutesQueryAfterUserCompletesTask.

@Deployment
public void testScriptTaskListenerExecutesQueryAfterUserCompletesTask() {
    // given
    startProcessInstancesByKey(DEFAULT_PROCESS_KEY, 5);
    Task task = selectAnyTask();
    String taskId = task.getId();
    String processInstanceId = task.getProcessInstanceId();
    createGrantAuthorization(TASK, taskId, userId, UPDATE);
    // when
    taskService.complete(taskId);
    // then
    disableAuthorization();
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstanceId);
    VariableInstance variableUser = query.variableName("userId").singleResult();
    assertNotNull(variableUser);
    assertEquals(userId, variableUser.getValue());
    VariableInstance variableCount = query.variableName("count").singleResult();
    assertNotNull(variableCount);
    assertEquals(5l, variableCount.getValue());
    enableAuthorization();
}
Also used : Task(org.camunda.bpm.engine.task.Task) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 33 with Task

use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testExecutionListenerWithMultiInstanceBody.

@Deployment
public void testExecutionListenerWithMultiInstanceBody() {
    final AtomicInteger eventCountForMultiInstanceBody = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            return new ExecutionListener() {

                public void notify(DelegateExecution execution) throws Exception {
                    if ("miTasks#multiInstanceBody".equals(execution.getCurrentActivityId()) && (ExecutionListener.EVENTNAME_START.equals(execution.getEventName()) || ExecutionListener.EVENTNAME_END.equals(execution.getEventName()))) {
                        eventCountForMultiInstanceBody.incrementAndGet();
                    }
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // complete task
    List<Task> miTasks = taskService.createTaskQuery().list();
    for (Task task : miTasks) {
        taskService.complete(task.getId());
    }
    // 2 events are expected: one for mi body start; one for mi body end
    assertEquals(2, eventCountForMultiInstanceBody.get());
}
Also used : DelegateTask(org.camunda.bpm.engine.delegate.DelegateTask) Task(org.camunda.bpm.engine.task.Task) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 34 with Task

use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testExecutionListenerWithTimerBoundaryEvent.

@Deployment
public void testExecutionListenerWithTimerBoundaryEvent() {
    final AtomicInteger eventCount = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            return new ExecutionListener() {

                public void notify(DelegateExecution execution) throws Exception {
                    eventCount.incrementAndGet();
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // 1. (start)startEvent(end) -(take)-> (start)userTask(end) -(take)-> (start)endEvent(end) (8 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // complete task
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    assertEquals(10, eventCount.get());
    // reset counter
    eventCount.set(0);
    // 2. (start)startEvent(end) -(take)-> (start)userTask(end)/(start)timerBoundaryEvent(end) -(take)-> (start)endEvent(end) (10 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // fire timer event
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    assertEquals(12, eventCount.get());
}
Also used : DelegateTask(org.camunda.bpm.engine.delegate.DelegateTask) Task(org.camunda.bpm.engine.task.Task) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) Job(org.camunda.bpm.engine.runtime.Job) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 35 with Task

use of org.camunda.bpm.engine.task.Task in project camunda-bpm-platform by camunda.

the class ExternalTaskServiceTest method testHandleBpmnErrorLockExpiredTask.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml")
public void testHandleBpmnErrorLockExpiredTask() {
    // given
    runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");
    // when
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    // and the lock expires without the task being reclaimed
    ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());
    externalTaskService.handleBpmnError(externalTasks.get(0).getId(), WORKER_ID, "ERROR-OCCURED");
    externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    assertEquals(0, externalTasks.size());
    assertEquals(0, externalTaskService.createExternalTaskQuery().count());
    Task afterBpmnError = taskService.createTaskQuery().singleResult();
    assertNotNull(afterBpmnError);
    assertEquals(afterBpmnError.getTaskDefinitionKey(), "afterBpmnError");
}
Also used : ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Task(org.camunda.bpm.engine.task.Task) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) DateTime(org.joda.time.DateTime) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Task (org.camunda.bpm.engine.task.Task)1654 Deployment (org.camunda.bpm.engine.test.Deployment)788 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)660 Test (org.junit.Test)648 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)230 ScenarioUnderTest (org.camunda.bpm.qa.upgrade.ScenarioUnderTest)190 HashMap (java.util.HashMap)140 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)139 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)108 Execution (org.camunda.bpm.engine.runtime.Execution)99 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)98 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)87 Job (org.camunda.bpm.engine.runtime.Job)71 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)67 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)52 DescribesScenario (org.camunda.bpm.qa.upgrade.DescribesScenario)46 ScenarioSetup (org.camunda.bpm.qa.upgrade.ScenarioSetup)46 Times (org.camunda.bpm.qa.upgrade.Times)46 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)45 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)45