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());
}
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);
}
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);
}
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");
}
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);
}
Aggregations