ProcessRuntimeImpl implements ProcessRuntime { @Override public ProcessDefinition processDefinition(String processDefinitionId) { org.activiti.engine.repository.ProcessDefinition processDefinition; processDefinition = findLatestProcessDefinitionByKey(processDefinitionId) .orElseGet(() -> repositoryService.getProcessDefinition(processDefinitionId)); checkProcessDefinitionBelongsToLatestDeployment(processDefinition); if (!securityPoliciesManager.canRead(processDefinition.getKey())) { throw new ActivitiObjectNotFoundException("Unable to find process definition for the given id:'" + processDefinitionId + "'"); } return processDefinitionConverter.from(processDefinition); } 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_getProcessDefinitionById_when_appVersionIsNull() { String processDefinitionId = "processDefinitionId"; String processDefinitionKey = "processDefinitionKey"; ProcessDefinitionEntityImpl processDefinition = new ProcessDefinitionEntityImpl(); processDefinition.setId(processDefinitionId); processDefinition.setKey(processDefinitionKey); processDefinition.setAppVersion(null); List<ProcessDefinition> findProcessDefinitionResult = singletonList(processDefinition); DeploymentEntityImpl deploymentEntity = new DeploymentEntityImpl(); deploymentEntity.setId("deploymentId"); given(commandExecutor.execute(any())).willReturn(Arrays.asList(deploymentEntity)) .willReturn(findProcessDefinitionResult); given(securityPoliciesManager.canRead(processDefinitionKey)).willReturn(true); processRuntime.processDefinition(processDefinitionId); verify(processDefinitionConverter).from(processDefinition); verifyZeroInteractions(deploymentConverter); }
@Test public void should_throwActivitiUnprocessableEntryException_when_processDefinitionAppVersionDiffersFromCurrentDeploymentVersion() { String processDefinitionId = "processDefinitionId"; ProcessDefinitionEntityImpl processDefinition = new ProcessDefinitionEntityImpl(); processDefinition.setId(processDefinitionId); processDefinition.setAppVersion(1); List<ProcessDefinition> findProcessDefinitionResult = singletonList(processDefinition); DeploymentEntityImpl latestDeploymentEntity = new DeploymentEntityImpl(); latestDeploymentEntity.setId("deploymentId"); DeploymentImpl latestDeployment = new DeploymentImpl(); latestDeployment.setVersion(2); given(deploymentConverter.from(latestDeploymentEntity)).willReturn(latestDeployment); given(commandExecutor.execute(any())) .willReturn(Arrays.asList(latestDeploymentEntity)) .willReturn(findProcessDefinitionResult) .willReturn(latestDeploymentEntity) .willReturn(latestDeployment); Throwable exception = catchThrowable(() -> processRuntime.processDefinition(processDefinitionId)); assertThat(exception) .isInstanceOf(UnprocessableEntityException.class) .hasMessage("Process definition with the given id:'processDefinitionId' belongs to a different application version."); }
@Test public void should_throwActivitiObjectNotFoundException_when_canReadFalse() { String processDefinitionId = "processDefinitionId"; String processDefinitionKey = "processDefinitionKey"; ProcessDefinitionEntityImpl processDefinition = new ProcessDefinitionEntityImpl(); processDefinition.setId(processDefinitionId); processDefinition.setKey(processDefinitionKey); processDefinition.setAppVersion(1); List<ProcessDefinition> findProcessDefinitionResult = singletonList(processDefinition); DeploymentEntityImpl latestDeploymentEntity = new DeploymentEntityImpl(); latestDeploymentEntity.setId("deploymentId"); DeploymentImpl deployment = new DeploymentImpl(); deployment.setVersion(1); given(deploymentConverter.from(latestDeploymentEntity)).willReturn(deployment); given(commandExecutor.execute(any())) .willReturn(Arrays.asList(latestDeploymentEntity)) .willReturn(findProcessDefinitionResult) .willReturn(latestDeploymentEntity); given(securityPoliciesManager.canRead(processDefinitionKey)).willReturn(false); Throwable exception = catchThrowable(() -> processRuntime.processDefinition(processDefinitionId)); assertThat(exception) .isInstanceOf(ActivitiObjectNotFoundException.class) .hasMessage("Unable to find process definition for the given id:'processDefinitionId'"); }