Search in sources :

Example 6 with SetProcessDefinitionVersionCmd

use of org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd in project Activiti by Activiti.

the class ProcessInstanceMigrationTest 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.activiti.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.getCommandExecutor();
    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.activiti.engine.runtime.Execution) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 7 with SetProcessDefinitionVersionCmd

use of org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd in project Activiti by Activiti.

the class ProcessInstanceMigrationTest method testSetProcessDefinitionVersionActivityMissing.

@Deployment(resources = { TEST_PROCESS })
public void testSetProcessDefinitionVersionActivityMissing() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");
    // check that receive task has been reached
    Execution execution = runtimeService.createExecutionQuery().activityId("waitState1").singleResult();
    assertNotNull(execution);
    // deploy new version of the process definition
    org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_ACTIVITY_MISSING).deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    SetProcessDefinitionVersionCmd setProcessDefinitionVersionCmd = new SetProcessDefinitionVersionCmd(pi.getId(), 2);
    try {
        commandExecutor.execute(setProcessDefinitionVersionCmd);
        fail("ActivitiException expected");
    } catch (ActivitiException ae) {
        assertTextPresent("The new process definition (key = 'receiveTask') does not contain the current activity (id = 'waitState1') of the process instance (id = '", ae.getMessage());
    }
    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Execution(org.activiti.engine.runtime.Execution) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 8 with SetProcessDefinitionVersionCmd

use of org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd in project Activiti by Activiti.

the class ProcessInstanceMigrationTest method testSetProcessDefinitionVersionNonExistingPD.

@Deployment(resources = { TEST_PROCESS })
public void testSetProcessDefinitionVersionNonExistingPD() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    try {
        commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 23));
        fail("ActivitiException expected");
    } catch (ActivitiObjectNotFoundException ae) {
        assertTextPresent("no processes deployed with key = 'receiveTask' and version = '23'", ae.getMessage());
        assertEquals(ProcessDefinition.class, ae.getObjectClass());
    }
}
Also used : CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) Deployment(org.activiti.engine.test.Deployment)

Example 9 with SetProcessDefinitionVersionCmd

use of org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd in project Activiti by Activiti.

the class ProcessInstanceMigrationTest method testSetProcessDefinitionVersionWithWithTask.

@Deployment(resources = { TEST_PROCESS_USER_TASK_V1 })
public void testSetProcessDefinitionVersionWithWithTask() {
    try {
        // start process instance
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("userTask");
        // check that user task has been reached    
        assertEquals(1, taskService.createTaskQuery().processInstanceId(pi.getId()).count());
        // deploy new version of the process definition
        org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_USER_TASK_V2).deploy();
        assertEquals(2, repositoryService.createProcessDefinitionQuery().processDefinitionKey("userTask").count());
        ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("userTask").processDefinitionVersion(2).singleResult();
        // migrate process instance to new process definition version
        processEngineConfiguration.getCommandExecutor().execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));
        // check UserTask
        Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
        assertEquals(newProcessDefinition.getId(), task.getProcessDefinitionId());
        assertEquals("testFormKey", formService.getTaskFormData(task.getId()).getFormKey());
        if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
            HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(pi.getId()).singleResult();
            assertEquals(newProcessDefinition.getId(), historicTask.getProcessDefinitionId());
            assertEquals("testFormKey", formService.getTaskFormData(historicTask.getId()).getFormKey());
        }
        // continue
        taskService.complete(task.getId());
        assertProcessEnded(pi.getId());
        // undeploy "manually" deployed process definition
        repositoryService.deleteDeployment(deployment.getId(), true);
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) SetProcessDefinitionVersionCmd(org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)9 SetProcessDefinitionVersionCmd (org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd)9 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)8 Deployment (org.activiti.engine.test.Deployment)8 Execution (org.activiti.engine.runtime.Execution)6 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)5 ActivitiException (org.activiti.engine.ActivitiException)3 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)3 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)1 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)1 Task (org.activiti.engine.task.Task)1