use of org.activiti.api.process.model.payloads.CreateProcessInstancePayload in project Activiti by Activiti.
the class ProcessRuntimeImplTest method should_createAProcessInstance_whenCreateIsCalled.
@Test
public void should_createAProcessInstance_whenCreateIsCalled() {
// given
String processDefinitionId = "processDefinitionId";
ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
processDefinition.setId(processDefinitionId);
processDefinition.setKey("key");
CreateProcessInstancePayload createPayload = ProcessPayloadBuilder.create().withProcessDefinitionId(processDefinitionId).withProcessDefinitionKey("key").withName("test-create").build();
doReturn(processDefinition).when(processRuntime).getProcessDefinitionAndCheckUserHasRights(createPayload.getProcessDefinitionId(), createPayload.getProcessDefinitionKey());
ProcessInstanceBuilder processInstanceBuilder = mock(ProcessInstanceBuilder.class, Answers.RETURNS_SELF);
given(runtimeService.createProcessInstanceBuilder()).willReturn(processInstanceBuilder);
org.activiti.engine.runtime.ProcessInstance internalProcessInstance = mock(org.activiti.engine.runtime.ProcessInstance.class);
given(processInstanceBuilder.create()).willReturn(internalProcessInstance);
ProcessInstanceImpl apiProcessInstance = new ProcessInstanceImpl();
given(processInstanceConverter.from(internalProcessInstance)).willReturn(apiProcessInstance);
// when
ProcessInstance createdProcessInstance = processRuntime.create(createPayload);
// then
assertThat(createdProcessInstance).isEqualTo(apiProcessInstance);
verify(processInstanceBuilder).processDefinitionId(processDefinition.getId());
verify(processInstanceBuilder).processDefinitionKey(processDefinition.getKey());
verify(processInstanceBuilder).name(createPayload.getName());
}
Aggregations