Search in sources :

Example 1 with StartProcessPayload

use of org.activiti.api.process.model.payloads.StartProcessPayload in project Activiti by Activiti.

the class ProcessRuntimeImplTest method should_throwAndException_whenProcessIdDoesNotExists.

@Test
public void should_throwAndException_whenProcessIdDoesNotExists() {
    // given
    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'");
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) StartProcessPayload(org.activiti.api.process.model.payloads.StartProcessPayload) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) NotFoundException(org.activiti.api.runtime.shared.NotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) Test(org.junit.jupiter.api.Test)

Example 2 with StartProcessPayload

use of org.activiti.api.process.model.payloads.StartProcessPayload in project Activiti by Activiti.

the class ProcessRuntimeIT method should_throwAnError_when_ProcessInstanceIsAlreadyStartedOrCompleted.

@Test
public void should_throwAnError_when_ProcessInstanceIsAlreadyStartedOrCompleted() {
    ProcessInstance categorizeProcess = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(CATEGORIZE_HUMAN_PROCESS).withVariable("expectedKey", true).withVariable("name", "garth").withVariable("age", 45).withBusinessKey("my business key").build());
    assertThat(categorizeProcess.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
    Throwable throwable = catchThrowable(() -> processRuntime.startCreatedProcess(categorizeProcess.getId(), new StartProcessPayload()));
    assertThat(throwable).isInstanceOf(ActivitiIllegalArgumentException.class).hasMessage("Process instance " + categorizeProcess.getId() + " has already been started");
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) StartProcessPayload(org.activiti.api.process.model.payloads.StartProcessPayload) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with StartProcessPayload

use of org.activiti.api.process.model.payloads.StartProcessPayload in project Activiti by Activiti.

the class ProcessRuntimeImplTest method should_startAnAlreadyCreatedProcessInstance_whenCalled.

@Test
public void should_startAnAlreadyCreatedProcessInstance_whenCalled() {
    // given
    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);
    // when
    StartProcessPayload payload = new StartProcessPayload();
    ProcessInstance createdProcessInstance = processRuntime.startCreatedProcess(processInstanceId, payload);
    // then
    assertThat(createdProcessInstance.getId()).isEqualTo("999-999");
    assertThat(createdProcessInstance.getBusinessKey()).isEqualTo("business-result");
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) ProcessInstanceImpl(org.activiti.api.runtime.model.impl.ProcessInstanceImpl) ExecutionEntityImpl(org.activiti.engine.impl.persistence.entity.ExecutionEntityImpl) StartProcessPayload(org.activiti.api.process.model.payloads.StartProcessPayload) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test)

Aggregations

StartProcessPayload (org.activiti.api.process.model.payloads.StartProcessPayload)3 Test (org.junit.jupiter.api.Test)3 ProcessInstance (org.activiti.api.process.model.ProcessInstance)2 ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)2 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)2 ProcessInstanceImpl (org.activiti.api.runtime.model.impl.ProcessInstanceImpl)1 NotFoundException (org.activiti.api.runtime.shared.NotFoundException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 ExecutionEntityImpl (org.activiti.engine.impl.persistence.entity.ExecutionEntityImpl)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1