Search in sources :

Example 1 with CreateProcessInstancePayload

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());
}
Also used : ProcessInstanceBuilder(org.activiti.engine.runtime.ProcessInstanceBuilder) ProcessDefinitionImpl(org.activiti.api.runtime.model.impl.ProcessDefinitionImpl) ProcessInstanceImpl(org.activiti.api.runtime.model.impl.ProcessInstanceImpl) ProcessInstance(org.activiti.api.process.model.ProcessInstance) CreateProcessInstancePayload(org.activiti.api.process.model.payloads.CreateProcessInstancePayload) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessInstance (org.activiti.api.process.model.ProcessInstance)1 CreateProcessInstancePayload (org.activiti.api.process.model.payloads.CreateProcessInstancePayload)1 ProcessDefinitionImpl (org.activiti.api.runtime.model.impl.ProcessDefinitionImpl)1 ProcessInstanceImpl (org.activiti.api.runtime.model.impl.ProcessInstanceImpl)1 ProcessInstanceBuilder (org.activiti.engine.runtime.ProcessInstanceBuilder)1 Test (org.junit.jupiter.api.Test)1