Search in sources :

Example 66 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersionSubExecutions.

@Deployment(resources = { TEST_PROCESS_WITH_PARALLEL_GATEWAY })
public void testSetProcessDefinitionVersionSubExecutions() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("forkJoin");
    // check that the user tasks have been reached
    assertEquals(2, taskService.createTaskQuery().count());
    // deploy new version of the process definition
    org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_WITH_PARALLEL_GATEWAY).deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    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);
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 67 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersion.

@Deployment
public void testSetProcessDefinitionVersion() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");
    // check that receive task has been reached
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).activityId("waitState1").singleResult();
    assertNotNull(execution);
    // deploy new version of the process definition
    org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS).deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));
    // signal process instance
    runtimeService.signal(execution.getId());
    // check that the instance now uses the new process definition version
    ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionVersion(2).singleResult();
    pi = runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals(newProcessDefinition.getId(), pi.getProcessDefinitionId());
    // check history
    if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE) {
        HistoricProcessInstance historicPI = historyService.createHistoricProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
    // assertEquals(newProcessDefinition.getId(), historicPI.getProcessDefinitionId());
    }
    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 68 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersionWithMultipleParents.

@Deployment(resources = { TEST_PROCESS_WITH_MULTIPLE_PARENTS })
public void testSetProcessDefinitionVersionWithMultipleParents() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("multipleJoins");
    // check that the user tasks have been reached
    assertEquals(2, taskService.createTaskQuery().count());
    // finish task1
    Task task = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
    taskService.complete(task.getId());
    // we have reached task4
    task = taskService.createTaskQuery().taskDefinitionKey("task4").singleResult();
    assertNotNull(task);
    // The timer job has been created
    Job job = managementService.createJobQuery().executionId(task.getExecutionId()).singleResult();
    assertNotNull(job);
    // check there are 2 user tasks task4 and task2
    assertEquals(2, taskService.createTaskQuery().count());
    // deploy new version of the process definition
    org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_WITH_MULTIPLE_PARENTS).deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    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);
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 69 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class MigrationVariablesTest method testVariableAtConcurrentExecutionInTransitionAddParentScope.

@Test
public void testVariableAtConcurrentExecutionInTransitionAddParentScope() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_BEFORE_SUBPROCESS_USER_TASK_PROCESS);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "userTask").build();
    ProcessInstance processInstance = rule.getRuntimeService().createProcessInstanceById(sourceProcessDefinition.getId()).startBeforeActivity("userTask").startBeforeActivity("userTask").execute();
    Execution concurrentExecution = runtimeService.createExecutionQuery().activityId("userTask").list().get(0);
    Job jobForExecution = rule.getManagementService().createJobQuery().executionId(concurrentExecution.getId()).singleResult();
    runtimeService.setVariableLocal(concurrentExecution.getId(), "var", "value");
    // when
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then
    Job jobAfterMigration = rule.getManagementService().createJobQuery().jobId(jobForExecution.getId()).singleResult();
    testHelper.assertVariableMigratedToExecution(testHelper.snapshotBeforeMigration.getSingleVariable("var"), jobAfterMigration.getExecutionId());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Example 70 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class TaskQueryTest method testQueryByVariableInParallelBranch.

@Deployment
public void testQueryByVariableInParallelBranch() throws Exception {
    runtimeService.startProcessInstanceByKey("parallelGateway");
    // when there are two process variables of the same name but different types
    Execution task1Execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
    runtimeService.setVariableLocal(task1Execution.getId(), "var", 12345L);
    Execution task2Execution = runtimeService.createExecutionQuery().activityId("task2").singleResult();
    runtimeService.setVariableLocal(task2Execution.getId(), "var", 12345);
    // then the task query should be able to filter by both variables and return both tasks
    assertEquals(2, taskService.createTaskQuery().processVariableValueEquals("var", 12345).count());
    assertEquals(2, taskService.createTaskQuery().processVariableValueEquals("var", 12345L).count());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) CaseExecution(org.camunda.bpm.engine.runtime.CaseExecution) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Execution (org.camunda.bpm.engine.runtime.Execution)279 Deployment (org.camunda.bpm.engine.test.Deployment)188 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)143 Task (org.camunda.bpm.engine.task.Task)99 Test (org.junit.Test)95 HashMap (java.util.HashMap)45 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)33 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)23 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 ThrowErrorDelegate.leaveExecution (org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate.leaveExecution)18 ExecutionQuery (org.camunda.bpm.engine.runtime.ExecutionQuery)17 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)15 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)14 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)14 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)14 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)14 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)13 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)12 ArrayList (java.util.ArrayList)11