Search in sources :

Example 6 with ActivitiMessageEvent

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

the class ActivityEventsTest method testActivityMessageEventsInEventSubprocess.

/**
 * Test events related to message events, called from the API, targeting an event-subprocess.
 */
@Deployment
public void testActivityMessageEventsInEventSubprocess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageProcess");
    assertThat(processInstance).isNotNull();
    Execution executionWithMessage = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
    assertThat(executionWithMessage).isNotNull();
    runtimeService.messageEventReceived("messageName", executionWithMessage.getId());
    // Only a message-event should be present, no signal-event, since the event-subprocess is
    // not signaled, but executed instead
    assertThat(listener.getEventsReceived()).hasSize(3);
    // An ACTIVITY_MESSAGE_WAITING event is expected
    assertThat(listener.getEventsReceived().get(0)).isInstanceOf(ActivitiMessageEvent.class);
    ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(0);
    assertThat(messageEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_MESSAGE_WAITING);
    assertThat(messageEvent.getActivityId()).isEqualTo("catchMessage");
    assertThat(messageEvent.getExecutionId()).isEqualTo(executionWithMessage.getId());
    assertThat(messageEvent.getProcessInstanceId()).isEqualTo(executionWithMessage.getProcessInstanceId());
    assertThat(messageEvent.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(messageEvent.getMessageName()).isEqualTo("messageName");
    assertThat(messageEvent.getMessageData()).isNull();
    // An ACTIVITY_MESSAGE_RECEIVED event is expected
    assertThat(listener.getEventsReceived().get(1)).isInstanceOf(ActivitiMessageEvent.class);
    messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(1);
    assertThat(messageEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
    assertThat(messageEvent.getActivityId()).isEqualTo("catchMessage");
    assertThat(messageEvent.getExecutionId()).isEqualTo(executionWithMessage.getId());
    assertThat(messageEvent.getProcessInstanceId()).isEqualTo(executionWithMessage.getProcessInstanceId());
    assertThat(messageEvent.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(messageEvent.getMessageName()).isEqualTo("messageName");
    assertThat(messageEvent.getMessageData()).isNull();
    // An ACTIVITY_CANCELLED event is expected
    assertThat(listener.getEventsReceived().get(2)).isInstanceOf(ActivitiActivityCancelledEvent.class);
    ActivitiActivityEvent activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(2);
    assertThat(activityEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_CANCELLED);
    assertThat(activityEvent.getActivityId()).isEqualTo("shipOrder");
    assertThat(activityEvent.getActivityType()).isEqualTo("userTask");
    assertThat(activityEvent.getProcessInstanceId()).isEqualTo(executionWithMessage.getProcessInstanceId());
    assertThat(activityEvent.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiActivityEvent(org.activiti.engine.delegate.event.ActivitiActivityEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent) Deployment(org.activiti.engine.test.Deployment)

Example 7 with ActivitiMessageEvent

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

the class ActivityEventsTest method testActivityMessageBoundaryEventsOnUserTask.

/**
 * Test events related to message events, called from the API.
 */
@Deployment
public void testActivityMessageBoundaryEventsOnUserTask() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageOnUserTaskProcess");
    assertThat(processInstance).isNotNull();
    Execution executionWithMessage = runtimeService.createExecutionQuery().messageEventSubscriptionName("message_1").singleResult();
    assertThat(executionWithMessage).isNotNull();
    Execution taskExecution = runtimeService.createExecutionQuery().activityId("cloudformtask1").processInstanceId(processInstance.getId()).singleResult();
    assertThat(taskExecution).isNotNull();
    runtimeService.messageEventReceived("message_1", executionWithMessage.getId());
    assertThat(listener.getEventsReceived()).hasSize(3);
    // First, an ACTIVITY_MESSAGE_WAITING event is expected
    assertThat(listener.getEventsReceived().get(0)).isInstanceOf(ActivitiMessageEvent.class);
    ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(0);
    assertThat(messageEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_MESSAGE_WAITING);
    assertThat(messageEvent.getActivityId()).isEqualTo("boundaryMessageEventCatching");
    assertThat(messageEvent.getExecutionId()).isEqualTo(executionWithMessage.getId());
    assertThat(messageEvent.getProcessInstanceId()).isEqualTo(executionWithMessage.getProcessInstanceId());
    assertThat(messageEvent.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(messageEvent.getMessageName()).isEqualTo("message_1");
    assertThat(messageEvent.getMessageData()).isNull();
    // Second, an ACTIVITY_MESSAGE_RECEIVED event is expected
    assertThat(listener.getEventsReceived().get(1)).isInstanceOf(ActivitiMessageEvent.class);
    messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(1);
    assertThat(messageEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
    assertThat(messageEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
    assertThat(messageEvent.getActivityId()).isEqualTo("boundaryMessageEventCatching");
    assertThat(messageEvent.getExecutionId()).isEqualTo(executionWithMessage.getId());
    assertThat(messageEvent.getProcessInstanceId()).isEqualTo(executionWithMessage.getProcessInstanceId());
    assertThat(messageEvent.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(messageEvent.getMessageName()).isEqualTo("message_1");
    assertThat(messageEvent.getMessageData()).isNull();
    // Next, an signal-event is expected, as a result of the message
    assertThat(listener.getEventsReceived().get(2)).isInstanceOf(ActivitiActivityCancelledEvent.class);
    ActivitiActivityCancelledEvent cancelledEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(2);
    assertThat(cancelledEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_CANCELLED);
    assertThat(cancelledEvent.getActivityId()).isEqualTo("cloudformtask1");
    assertThat(cancelledEvent.getExecutionId()).isEqualTo(taskExecution.getId());
    assertThat(cancelledEvent.getProcessInstanceId()).isEqualTo(executionWithMessage.getProcessInstanceId());
    assertThat(cancelledEvent.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(cancelledEvent.getCause()).isEqualTo("boundary event (boundaryMessageEventCatching)");
    assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent) Deployment(org.activiti.engine.test.Deployment)

Example 8 with ActivitiMessageEvent

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

the class ToMessageWaitingConverterTest method fromShouldReturnConvertedEventAndSetProcessInstanceIdAndProcessDefinitionId.

@Test
public void fromShouldReturnConvertedEventAndSetProcessInstanceIdAndProcessDefinitionId() {
    // given
    ActivitiMessageEvent internalEvent = mock(ActivitiMessageEvent.class);
    given(internalEvent.getProcessDefinitionId()).willReturn("procDefId");
    given(internalEvent.getProcessInstanceId()).willReturn("procInstId");
    BPMNMessageImpl bpmnMessage = new BPMNMessageImpl("myMessage");
    given(bpmnMessageConverter.convertToBPMNMessage(internalEvent)).willReturn(bpmnMessage);
    // when
    BPMNMessageWaitingEvent messageEvent = toMessageConverter.from(internalEvent).orElse(null);
    // then
    assertThat(messageEvent).isNotNull();
    assertThat(messageEvent.getProcessInstanceId()).isEqualTo("procInstId");
    assertThat(messageEvent.getProcessDefinitionId()).isEqualTo("procDefId");
    assertThat(messageEvent.getEntity()).isEqualTo(bpmnMessage);
}
Also used : BPMNMessageWaitingEvent(org.activiti.api.process.model.events.BPMNMessageWaitingEvent) BPMNMessageImpl(org.activiti.api.runtime.model.impl.BPMNMessageImpl) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent) Test(org.junit.jupiter.api.Test)

Example 9 with ActivitiMessageEvent

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

the class BPMNMessageConverterTest method convertShouldReturnBPMNMessage.

@Test
public void convertShouldReturnBPMNMessage() {
    ActivitiMessageEvent internalEvent = mock(ActivitiMessageEvent.class);
    given(internalEvent.getMessageBusinessKey()).willReturn("businessKey");
    given(internalEvent.getMessageCorrelationKey()).willReturn("correlationKey");
    given(internalEvent.getMessageName()).willReturn("messageName");
    given(internalEvent.getProcessDefinitionId()).willReturn("procDefId");
    given(internalEvent.getProcessInstanceId()).willReturn("procInstId");
    BPMNMessageImpl bpmnMessage = bpmnMessageConverter.convertToBPMNMessage(internalEvent);
    // then
    assertThat(bpmnMessage).isNotNull();
    assertThat(bpmnMessage.getProcessInstanceId()).isEqualTo("procInstId");
    assertThat(bpmnMessage.getProcessDefinitionId()).isEqualTo("procDefId");
    assertThat(bpmnMessage.getMessagePayload()).isNotNull().extracting(MessageEventPayload::getName, MessageEventPayload::getBusinessKey, MessageEventPayload::getCorrelationKey).contains("messageName", "businessKey", "correlationKey");
}
Also used : BPMNMessageImpl(org.activiti.api.runtime.model.impl.BPMNMessageImpl) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent) Test(org.junit.jupiter.api.Test)

Example 10 with ActivitiMessageEvent

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

the class ToMessageSentConverterTest method fromShouldReturnConvertedEventAndSetProcessInstanceIdAndProcessDefinitionId.

@Test
public void fromShouldReturnConvertedEventAndSetProcessInstanceIdAndProcessDefinitionId() {
    // given
    ActivitiMessageEvent internalEvent = mock(ActivitiMessageEvent.class);
    given(internalEvent.getProcessDefinitionId()).willReturn("procDefId");
    given(internalEvent.getProcessInstanceId()).willReturn("procInstId");
    BPMNMessageImpl bpmnMessage = new BPMNMessageImpl("myMessage");
    given(bpmnMessageConverter.convertToBPMNMessage(internalEvent)).willReturn(bpmnMessage);
    // when
    BPMNMessageSentEvent messageEvent = toMessageConverter.from(internalEvent).orElse(null);
    // then
    assertThat(messageEvent).isNotNull();
    assertThat(messageEvent.getProcessInstanceId()).isEqualTo("procInstId");
    assertThat(messageEvent.getProcessDefinitionId()).isEqualTo("procDefId");
    assertThat(messageEvent.getEntity()).isEqualTo(bpmnMessage);
}
Also used : BPMNMessageSentEvent(org.activiti.api.process.model.events.BPMNMessageSentEvent) BPMNMessageImpl(org.activiti.api.runtime.model.impl.BPMNMessageImpl) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent) Test(org.junit.jupiter.api.Test)

Aggregations

ActivitiMessageEvent (org.activiti.engine.delegate.event.ActivitiMessageEvent)18 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)13 Deployment (org.activiti.engine.test.Deployment)13 IntermediateThrowMessageEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.IntermediateThrowMessageEventActivityBehavior)5 BPMNMessageImpl (org.activiti.api.runtime.model.impl.BPMNMessageImpl)4 ThrowMessageEndEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.ThrowMessageEndEventActivityBehavior)4 Execution (org.activiti.engine.runtime.Execution)4 Test (org.junit.jupiter.api.Test)4 ActivitiActivityCancelledEvent (org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent)2 HashMap (java.util.HashMap)1 BPMNMessageReceivedEvent (org.activiti.api.process.model.events.BPMNMessageReceivedEvent)1 BPMNMessageSentEvent (org.activiti.api.process.model.events.BPMNMessageSentEvent)1 BPMNMessageWaitingEvent (org.activiti.api.process.model.events.BPMNMessageWaitingEvent)1 ActivitiActivityEvent (org.activiti.engine.delegate.event.ActivitiActivityEvent)1