ExecutionEntityManagerImpl extends AbstractEntityManager<ExecutionEntity> implements ExecutionEntityManager { @Override public ExecutionEntity createProcessInstanceExecution(ProcessDefinition processDefinition, String businessKey, String tenantId, String initiatorVariableName) { ExecutionEntity processInstanceExecution = executionDataManager.create(); if (isExecutionRelatedEntityCountEnabledGlobally()) { ((CountingExecutionEntity) processInstanceExecution).setCountEnabled(true); } processInstanceExecution.setProcessDefinitionId(processDefinition.getId()); processInstanceExecution.setProcessDefinitionKey(processDefinition.getKey()); processInstanceExecution.setProcessDefinitionName(processDefinition.getName()); processInstanceExecution.setProcessDefinitionVersion(processDefinition.getVersion()); processInstanceExecution.setAppVersion(processDefinition.getAppVersion()); processInstanceExecution.setBusinessKey(businessKey); processInstanceExecution.setScope(true); if (tenantId != null) { processInstanceExecution.setTenantId(tenantId); } String authenticatedUserId = Authentication.getAuthenticatedUserId(); processInstanceExecution.setStartUserId(authenticatedUserId); insert(processInstanceExecution, false); if (initiatorVariableName != null) { processInstanceExecution.setVariable(initiatorVariableName, authenticatedUserId); } processInstanceExecution.setProcessInstanceId(processInstanceExecution.getId()); processInstanceExecution.setRootProcessInstanceId(processInstanceExecution.getId()); if (authenticatedUserId != null) { getIdentityLinkEntityManager().addIdentityLink(processInstanceExecution, authenticatedUserId, null, IdentityLinkType.STARTER); } if (getEventDispatcher().isEnabled()) { getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, processInstanceExecution)); } return processInstanceExecution; } ExecutionEntityManagerImpl(ProcessEngineConfigurationImpl processEngineConfiguration, ExecutionDataManager executionDataManager); @Override void delete(ExecutionEntity entity); @Override void delete(ExecutionEntity entity, boolean fireDeleteEvent); @Override ExecutionEntity findSubProcessInstanceBySuperExecutionId(String superExecutionId); @Override List<ExecutionEntity> findChildExecutionsByParentExecutionId(String parentExecutionId); @Override List<ExecutionEntity> findChildExecutionsByProcessInstanceId(String processInstanceId); @Override List<ExecutionEntity> findExecutionsByParentExecutionAndActivityIds(final String parentExecutionId, final Collection<String> activityIds); @Override long findExecutionCountByQueryCriteria(ExecutionQueryImpl executionQuery); @Override List<ExecutionEntity> findExecutionsByQueryCriteria(ExecutionQueryImpl executionQuery, Page page); @Override long findProcessInstanceCountByQueryCriteria(ProcessInstanceQueryImpl executionQuery); @Override List<ProcessInstance> findProcessInstanceByQueryCriteria(ProcessInstanceQueryImpl executionQuery); @Override ExecutionEntity findByRootProcessInstanceId(String rootProcessInstanceId); @Override List<ProcessInstance> findProcessInstanceAndVariablesByQueryCriteria(ProcessInstanceQueryImpl executionQuery); @Override Collection<ExecutionEntity> findInactiveExecutionsByProcessInstanceId(final String processInstanceId); @Override Collection<ExecutionEntity> findInactiveExecutionsByActivityIdAndProcessInstanceId(final String activityId, final String processInstanceId); @Override List<Execution> findExecutionsByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults); @Override List<ProcessInstance> findProcessInstanceByNativeQuery(Map<String, Object> parameterMap, int firstResult, int maxResults); @Override long findExecutionCountByNativeQuery(Map<String, Object> parameterMap); @Override ExecutionEntity createProcessInstanceExecution(ProcessDefinition processDefinition, String businessKey, String tenantId, String initiatorVariableName); ExecutionEntity updateProcessInstanceStartDate(ExecutionEntity processInstanceExecution); @Override ExecutionEntity createChildExecution(ExecutionEntity parentExecutionEntity); @Override ExecutionEntity createSubprocessInstance(ProcessDefinition processDefinition, ExecutionEntity superExecutionEntity, String businessKey); @Override void updateExecutionTenantIdForDeployment(String deploymentId, String newTenantId); @Override void deleteProcessInstancesByProcessDefinition(String processDefinitionId, String deleteReason, boolean cascade); @Override void deleteProcessInstance(String processInstanceId, String deleteReason, boolean cascade); @Override void deleteExecutionAndRelatedData(ExecutionEntity executionEntity, String deleteReason); @Override void cancelExecutionAndRelatedData(ExecutionEntity executionEntity, String deleteReason); @Override void deleteProcessInstanceExecutionEntity(String processInstanceId,
      String currentFlowElementId, String deleteReason, boolean cascade, boolean cancel); @Override void deleteChildExecutions(ExecutionEntity executionEntity, String deleteReason); @Override void cancelChildExecutions(ExecutionEntity executionEntity, String deleteReason); List<ExecutionEntity> collectChildren(ExecutionEntity executionEntity); @Override ExecutionEntity findFirstScope(ExecutionEntity executionEntity); @Override ExecutionEntity findFirstMultiInstanceRoot(ExecutionEntity executionEntity); @Override void updateProcessInstanceLockTime(String processInstanceId); @Override void clearProcessInstanceLockTime(String processInstanceId); @Override String updateProcessInstanceBusinessKey(ExecutionEntity executionEntity, String businessKey); ExecutionDataManager getExecutionDataManager(); void setExecutionDataManager(ExecutionDataManager executionDataManager);  }
@Test public void should_createProcessInstanceExecution_when_initialVariableNameIsNull() { ProcessDefinitionEntity processDefinition = new ProcessDefinitionEntityImpl(); processDefinition.setId("processDefinitionId"); processDefinition.setKey("processDefinitionKey"); processDefinition.setName("processDefinitionName"); processDefinition.setVersion(1); processDefinition.setAppVersion(3); String businessKey = "businessKey"; String tenantId = "tenantId"; PerformanceSettings performanceSettings = mock(PerformanceSettings.class); given(processEngineConfiguration.getPerformanceSettings()).willReturn(performanceSettings); ExecutionEntity execution = new ExecutionEntityImpl(); execution.setId("processInstanceId"); given(executionDataManager.create()).willReturn(execution); ExecutionEntity processInstanceResult = executionEntityManager.createProcessInstanceExecution(processDefinition, businessKey, tenantId, null); assertThat(processInstanceResult.getProcessDefinitionId()).isEqualTo("processDefinitionId"); assertThat(processInstanceResult.getProcessDefinitionKey()).isEqualTo("processDefinitionKey"); assertThat(processInstanceResult.getProcessDefinitionName()).isEqualTo("processDefinitionName"); assertThat(processInstanceResult.getProcessDefinitionVersion()).isEqualTo(1); assertThat(processInstanceResult.getAppVersion()).isEqualTo(3); assertThat(processInstanceResult.getBusinessKey()).isEqualTo(businessKey); assertThat(processInstanceResult.isScope()).isTrue(); assertThat(processInstanceResult.getTenantId()).isEqualTo(tenantId); assertThat(processInstanceResult.getProcessInstanceId()).isEqualTo("processInstanceId"); assertThat(processInstanceResult.getRootProcessInstanceId()).isEqualTo("processInstanceId"); verify(executionDataManager).insert(processInstanceResult); verify(eventDispatcher).isEnabled(); }