cancel
Showing results for 
Search instead for 
Did you mean: 

Undeployment Testing

izaak
Champ in-the-making
Champ in-the-making
I'm attempting to verify some methods for programmatically migrating between versions of a given process definition. I'm having a hard time simulating it in a test however. I expected i could deploy my process once, create a process instance and move it through workflow a bit:


repositoryService.createDeployment().addClasspathResource("Process.bpmn20.xml").deploy();
ProcessInstance processInstance = engine.getRuntimeService().startProcessInstanceByKey("Process");
int version = processDefinition.getVersion();

// move the the workflow

Then redeploy it, verify the new version exists:


      System.out.println("Before (RE)Deployment");
      Deployment deployment = repositoryService.createDeployment().addClasspathResource("Process-v2.bpmn20.xml").deploy();
ProcessInstance newVersionProcessInstance = engine.getRuntimeService().startProcessInstanceByKey("Process");
      ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.getDeployedProcessDefinition(newVersionProcessInstance
       .getProcessDefinitionId());

      [b]assertEquals(version + 1, processDefinition.getVersion());[/b]

Then forceably modify the version of the given instance (this code seems awful – is there a more intended way to do this?):


SetProcessDefinitionVersionCmd cmd = new SetProcessDefinitionVersionCmd(procId, processDefinition.getVersion() + 1);
      ((ProcessEngineConfigurationImpl) ((WorkflowConfigurationActivitiImpl) activitiConfig).getProcessEngineConfig())
            .getCommandExecutorTxRequired().execute(cmd);

      assertEquals(newVersionProcessDefinition.getVersion(), processDefinition.getVersion());
//continue moving through workflow

Then continue moving through the workflow. Everytime i do this however the new process doesn't seem to update the version number on the bolded assertion. Any suggestions for accomplishing this?

Any suggestions on resources for people who've had to do this (it seems a bit sparse out there – and i haven't even gotten near the real problem of what happens when there is a significant change to the process).
2 REPLIES 2

frederikherema1
Star Contributor
Star Contributor
Have you looked into org.activiti.engine.test.db.ProcessInstanceMigrationTest? This contains all test for this use case, e.g.:


@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.activiti.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().isAtLeast(HistoryLevel.ACTIVITY)) {
      HistoricProcessInstance historicPI = historyService
        .createHistoricProcessInstanceQuery()
        .processInstanceId(pi.getId())
        .singleResult();
      assertEquals(newProcessDefinition.getId(), historicPI.getProcessDefinitionId());
    }

    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
  }

izaak
Champ in-the-making
Champ in-the-making
Thanks!

My problem (or at least one of my problems) was that I didn't reload the ProcessInstance/ProcessDefinition after updating the version, before checking that the version was updated.