ProcessRuntimeImpl implements ProcessRuntime { @Override public ProcessInstance startCreatedProcess(String processInstanceId, StartProcessPayload startProcessPayload) { org.activiti.engine.runtime.ProcessInstance internalProcessInstance = runtimeService .createProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); if (internalProcessInstance == null) { throw new NotFoundException("Unable to find process instance for the given id:'" + processInstanceId + "'"); } if (!securityPoliciesManager.canRead(internalProcessInstance.getProcessDefinitionKey())) { throw new ActivitiObjectNotFoundException("You cannot read the process instance with Id:'" + processInstanceId + "' due to security policies violation"); } processVariablesValidator.checkStartProcessPayloadVariables(startProcessPayload, internalProcessInstance.getProcessDefinitionId()); return processInstanceConverter.from(runtimeService.startCreatedProcessInstance(internalProcessInstance, startProcessPayload.getVariables())); } ProcessRuntimeImpl(RepositoryService repositoryService,
                              APIProcessDefinitionConverter processDefinitionConverter,
                              RuntimeService runtimeService,
                              ProcessSecurityPoliciesManager securityPoliciesManager,
                              APIProcessInstanceConverter processInstanceConverter,
                              APIVariableInstanceConverter variableInstanceConverter,
                              APIDeploymentConverter deploymentConverter,
                              ProcessRuntimeConfiguration configuration,
                              ApplicationEventPublisher eventPublisher,
                              ProcessVariablesPayloadValidator processVariablesValidator); @Override ProcessDefinition processDefinition(String processDefinitionId); @Override Page<ProcessDefinition> processDefinitions(Pageable pageable); @Override Page<ProcessDefinition> processDefinitions(Pageable pageable,
                                                      GetProcessDefinitionsPayload getProcessDefinitionsPayload); @Override ProcessInstance processInstance(String processInstanceId); @Override Page<ProcessInstance> processInstances(Pageable pageable); @Override Page<ProcessInstance> processInstances(Pageable pageable,
                                                  GetProcessInstancesPayload getProcessInstancesPayload); @Override ProcessRuntimeConfiguration configuration(); @Override ProcessInstance start(StartProcessPayload startProcessPayload); @Override ProcessInstance startCreatedProcess(String processInstanceId, StartProcessPayload startProcessPayload); @Override ProcessInstance create(CreateProcessInstancePayload startProcessPayload); @Override ProcessInstance suspend(SuspendProcessPayload suspendProcessPayload); @Override ProcessInstance resume(ResumeProcessPayload resumeProcessPayload); @Override ProcessInstance delete(DeleteProcessPayload deleteProcessPayload); @Override List<VariableInstance> variables(GetVariablesPayload getVariablesPayload); @Override void removeVariables(RemoveProcessVariablesPayload removeProcessVariablesPayload); @Override void setVariables(SetProcessVariablesPayload setProcessVariablesPayload); @Override @Transactional void signal(SignalPayload signalPayload); @Override ProcessDefinitionMeta processDefinitionMeta(String processDefinitionKey); @Override ProcessInstanceMeta processInstanceMeta(String processInstanceId); @Override ProcessInstance update(UpdateProcessPayload updateProcessPayload); @Override @Transactional void receive(ReceiveMessagePayload messagePayload); @Override ProcessInstance start(StartMessagePayload messagePayload); @Override Deployment selectLatestDeployment();  }
@Test public void should_startAnAlreadyCreatedProcessInstance_whenCalled() { String processInstanceId = "process-instance-id"; ProcessInstanceQuery processQuery = mock(ProcessInstanceQuery.class); doReturn(processQuery).when(processQuery).processInstanceId(processInstanceId); doReturn(processQuery).when(runtimeService).createProcessInstanceQuery(); org.activiti.engine.runtime.ProcessInstance internalProcess = new ExecutionEntityImpl(); internalProcess.setAppVersion(1); doReturn(internalProcess).when(processQuery).singleResult(); when(runtimeService.startCreatedProcessInstance(internalProcess, new HashMap<>())).thenReturn(internalProcess); ProcessInstanceImpl apiProcessInstance = new ProcessInstanceImpl(); apiProcessInstance.setBusinessKey("business-result"); apiProcessInstance.setId("999-999"); given(processInstanceConverter.from(internalProcess)).willReturn(apiProcessInstance); given(securityPoliciesManager.canRead(any())).willReturn(true); StartProcessPayload payload = new StartProcessPayload(); ProcessInstance createdProcessInstance = processRuntime.startCreatedProcess(processInstanceId, payload); assertThat(createdProcessInstance.getId()).isEqualTo("999-999"); assertThat(createdProcessInstance.getBusinessKey()).isEqualTo("business-result"); }
@Test public void should_throwAndException_whenProcessIdDoesNotExists() { String processInstanceId = "process-instance-id"; ProcessInstanceQuery processQuery = mock(ProcessInstanceQuery.class); doReturn(processQuery).when(processQuery).processInstanceId(processInstanceId); doReturn(processQuery).when(runtimeService).createProcessInstanceQuery(); doReturn(null).when(processQuery).singleResult(); StartProcessPayload payload = new StartProcessPayload(); Throwable exception = catchThrowable(() -> processRuntime.startCreatedProcess(processInstanceId, payload)); assertThat(exception) .isInstanceOf(NotFoundException.class) .hasMessage("Unable to find process instance for the given id:'process-instance-id'"); }