Search in sources :

Example 1 with ActivitiErrorEvent

use of org.activiti.engine.delegate.event.ActivitiErrorEvent in project Activiti by Activiti.

the class ToErrorReceivedConverterTest method fromShouldReturnConvertedEventAndSetProcessInstanceIdAndProcessDefinitionId.

@Test
public void fromShouldReturnConvertedEventAndSetProcessInstanceIdAndProcessDefinitionId() {
    // given
    ActivitiErrorEvent internalEvent = mock(ActivitiErrorEvent.class);
    given(internalEvent.getProcessDefinitionId()).willReturn("procDefId");
    given(internalEvent.getProcessInstanceId()).willReturn("procInstId");
    BPMNErrorImpl bpmnError = new BPMNErrorImpl("myError");
    given(bpmnErrorConverter.convertToBPMNError(internalEvent)).willReturn(bpmnError);
    // when
    BPMNErrorReceivedEvent errorEvent = toErrorReceivedConverter.from(internalEvent).orElse(null);
    // then
    assertThat(errorEvent).isNotNull();
    assertThat(errorEvent.getProcessInstanceId()).isEqualTo("procInstId");
    assertThat(errorEvent.getProcessDefinitionId()).isEqualTo("procDefId");
    assertThat(errorEvent.getEntity()).isEqualTo(bpmnError);
}
Also used : ActivitiErrorEvent(org.activiti.engine.delegate.event.ActivitiErrorEvent) BPMNErrorReceivedEvent(org.activiti.api.process.model.events.BPMNErrorReceivedEvent) BPMNErrorImpl(org.activiti.api.runtime.model.impl.BPMNErrorImpl) Test(org.junit.jupiter.api.Test)

Example 2 with ActivitiErrorEvent

use of org.activiti.engine.delegate.event.ActivitiErrorEvent in project Activiti by Activiti.

the class ActivityEventsTest method testActivityErrorEventsFromBPMNError.

/**
 * Test events related to error-events, thrown from within process-execution (eg. service-task).
 */
@Deployment
public void testActivityErrorEventsFromBPMNError() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("errorProcess");
    assertThat(processInstance).isNotNull();
    // Error-handling should have ended the process
    ProcessInstance afterErrorInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(afterErrorInstance).isNull();
    List<ActivitiErrorEvent> errorEvents = listener.getEventsReceived().stream().filter(ActivitiErrorEvent.class::isInstance).map(ActivitiErrorEvent.class::cast).collect(toList());
    assertThat(errorEvents).as("Only one ActivityErrorEvent expected").hasSize(1);
    ActivitiErrorEvent errorEvent = errorEvents.get(0);
    assertThat(errorEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_ERROR_RECEIVED);
    assertThat(errorEvent.getActivityId()).isEqualTo("catchError");
    assertThat(errorEvent.getErrorId()).isEqualTo("23");
    assertThat(errorEvent.getErrorCode()).isEqualTo("23");
    assertThat(errorEvent.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(errorEvent.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(errorEvent.getExecutionId()).isNotEqualTo(processInstance.getId());
}
Also used : ActivitiErrorEvent(org.activiti.engine.delegate.event.ActivitiErrorEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with ActivitiErrorEvent

use of org.activiti.engine.delegate.event.ActivitiErrorEvent in project Activiti by Activiti.

the class BPMNErrorConverterTest method convertShouldReturnBPMNError.

@Test
public void convertShouldReturnBPMNError() {
    ActivitiErrorEvent internalEvent = mock(ActivitiErrorEvent.class);
    given(internalEvent.getErrorId()).willReturn("errorId");
    given(internalEvent.getErrorCode()).willReturn("errorCode");
    given(internalEvent.getActivityName()).willReturn("activityName");
    given(internalEvent.getActivityType()).willReturn("activityType");
    given(internalEvent.getProcessDefinitionId()).willReturn("procDefId");
    given(internalEvent.getProcessInstanceId()).willReturn("procInstId");
    BPMNErrorImpl bpmnError = bpmnErrorConverter.convertToBPMNError(internalEvent);
    // then
    assertThat(bpmnError).isNotNull();
    assertThat(bpmnError.getProcessInstanceId()).isEqualTo("procInstId");
    assertThat(bpmnError.getProcessDefinitionId()).isEqualTo("procDefId");
    assertThat(bpmnError.getErrorId()).isEqualTo("errorId");
    assertThat(bpmnError.getErrorCode()).isEqualTo("errorCode");
    assertThat(bpmnError.getActivityName()).isEqualTo("activityName");
    assertThat(bpmnError.getActivityType()).isEqualTo("activityType");
}
Also used : ActivitiErrorEvent(org.activiti.engine.delegate.event.ActivitiErrorEvent) BPMNErrorImpl(org.activiti.api.runtime.model.impl.BPMNErrorImpl) Test(org.junit.jupiter.api.Test)

Example 4 with ActivitiErrorEvent

use of org.activiti.engine.delegate.event.ActivitiErrorEvent in project Activiti by Activiti.

the class ActivityEventsTest method testActivityErrorEvents.

/**
 * Test events related to error-events
 */
@Deployment
public void testActivityErrorEvents() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("errorProcess");
    assertThat(processInstance).isNotNull();
    // Error-handling should have ended the process
    ProcessInstance afterErrorInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertThat(afterErrorInstance).isNull();
    List<ActivitiErrorEvent> errorEvents = listener.getEventsReceived().stream().filter(ActivitiErrorEvent.class::isInstance).map(ActivitiErrorEvent.class::cast).collect(toList());
    assertThat(errorEvents).as("Only one ActivityErrorEvent expected").hasSize(1);
    ActivitiErrorEvent errorEvent = errorEvents.get(0);
    assertThat(errorEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_ERROR_RECEIVED);
    assertThat(errorEvent.getActivityId()).isEqualTo("catchError");
    assertThat(errorEvent.getErrorId()).isEqualTo("myError");
    assertThat(errorEvent.getErrorCode()).isEqualTo("123");
    assertThat(errorEvent.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(errorEvent.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(errorEvent.getExecutionId()).isNotEqualTo(processInstance.getId());
}
Also used : ActivitiErrorEvent(org.activiti.engine.delegate.event.ActivitiErrorEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ActivitiErrorEvent (org.activiti.engine.delegate.event.ActivitiErrorEvent)4 BPMNErrorImpl (org.activiti.api.runtime.model.impl.BPMNErrorImpl)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Deployment (org.activiti.engine.test.Deployment)2 Test (org.junit.jupiter.api.Test)2 BPMNErrorReceivedEvent (org.activiti.api.process.model.events.BPMNErrorReceivedEvent)1