APIProcessInstanceConverter extends ListConverter<org.activiti.engine.runtime.ProcessInstance, ProcessInstance> implements ModelConverter<org.activiti.engine.runtime.ProcessInstance, ProcessInstance> { @Override public ProcessInstance from(org.activiti.engine.runtime.ProcessInstance internalProcessInstance) { ProcessInstanceImpl processInstance = new ProcessInstanceImpl(); processInstance.setId(internalProcessInstance.getId()); processInstance.setParentId(internalProcessInstance.getParentProcessInstanceId()); processInstance.setName(internalProcessInstance.getName()); processInstance.setProcessDefinitionId(internalProcessInstance.getProcessDefinitionId()); processInstance.setProcessDefinitionKey(internalProcessInstance.getProcessDefinitionKey()); processInstance.setProcessDefinitionVersion(internalProcessInstance.getProcessDefinitionVersion()); processInstance.setInitiator(internalProcessInstance.getStartUserId()); processInstance.setStartDate(internalProcessInstance.getStartTime()); processInstance.setProcessDefinitionKey(internalProcessInstance.getProcessDefinitionKey()); processInstance.setBusinessKey(internalProcessInstance.getBusinessKey()); processInstance.setStatus(calculateStatus(internalProcessInstance)); processInstance.setProcessDefinitionVersion(internalProcessInstance.getProcessDefinitionVersion()); processInstance.setAppVersion(Objects.toString(internalProcessInstance.getAppVersion(), null)); processInstance.setProcessDefinitionName(internalProcessInstance.getProcessDefinitionName()); return processInstance; }  @Override ProcessInstance from(org.activiti.engine.runtime.ProcessInstance internalProcessInstance);  }
@Test public void should_convertFromInternalProcessInstance_when_withRunningStatus() { ExecutionEntity internalProcessInstance = anInternalProcessInstance(APP_VERSION); ProcessInstance result = subject.from(internalProcessInstance); assertValidProcessInstanceResult(result); assertThat(result.getStatus()).isEqualTo(ProcessInstanceStatus.RUNNING); }
@Test public void should_returnStatusCreated_when_StartDateIsNull() { ExecutionEntity internalProcessInstance = anInternalProcessInstance(APP_VERSION); internalProcessInstance.setStartTime(null); ProcessInstance result = subject.from(internalProcessInstance); assertThat(result.getStatus()).isEqualTo(ProcessInstanceStatus.CREATED); }
@Test public void should_convertFromInternalProcessInstance_when_withSuspendedStatus() { ExecutionEntity internalProcessInstance = anInternalProcessInstance(APP_VERSION); internalProcessInstance.setSuspensionState(SuspensionState.SUSPENDED.getStateCode()); ProcessInstance result = subject.from(internalProcessInstance); assertValidProcessInstanceResult(result); assertThat(result.getStatus()).isEqualTo(ProcessInstanceStatus.SUSPENDED); }
@Test public void should_convertFromInternalProcessInstance_when_withCompletedStatus() { ExecutionEntity internalProcessInstance = anInternalProcessInstance(APP_VERSION); internalProcessInstance.setEnded(true); ProcessInstance result = subject.from(internalProcessInstance); assertValidProcessInstanceResult(result); assertThat(result.getStatus()).isEqualTo(ProcessInstanceStatus.COMPLETED); }
@Test public void should_convertFromInternalProcessInstance_when_appVersionIsNotSet() { ExecutionEntity internalProcessInstance = anInternalProcessInstance(null); ProcessInstance result = subject.from(internalProcessInstance); assertValidProcessInstanceResult(result, null); }