Search in sources :

Example 16 with ActivitiMessageEvent

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

the class ActivityMessageEventHandler method generateEventLogEntry.

@Override
public EventLogEntryEntity generateEventLogEntry(CommandContext commandContext) {
    ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) event;
    Map<String, Object> data = new HashMap<String, Object>();
    putInMapIfNotNull(data, Fields.ACTIVITY_ID, messageEvent.getActivityId());
    putInMapIfNotNull(data, Fields.ACTIVITY_NAME, messageEvent.getActivityName());
    putInMapIfNotNull(data, Fields.PROCESS_DEFINITION_ID, messageEvent.getProcessDefinitionId());
    putInMapIfNotNull(data, Fields.PROCESS_INSTANCE_ID, messageEvent.getProcessInstanceId());
    putInMapIfNotNull(data, Fields.EXECUTION_ID, messageEvent.getExecutionId());
    putInMapIfNotNull(data, Fields.ACTIVITY_TYPE, messageEvent.getActivityType());
    putInMapIfNotNull(data, Fields.MESSAGE_NAME, messageEvent.getMessageName());
    putInMapIfNotNull(data, Fields.MESSAGE_DATA, messageEvent.getMessageData());
    return createEventLogEntry(messageEvent.getProcessDefinitionId(), messageEvent.getProcessInstanceId(), messageEvent.getExecutionId(), null, data);
}
Also used : HashMap(java.util.HashMap) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent)

Example 17 with ActivitiMessageEvent

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

the class ActivityEventsTest method testActivityMessageBoundaryEventsOnSubProcess.

/**
 * Test events related to message events, called from the API.
 */
@Deployment
public void testActivityMessageBoundaryEventsOnSubProcess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageOnSubProcess");
    assertThat(processInstance).isNotNull();
    Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("boundaryMessageEventCatching").singleResult();
    assertThat(executionWithMessage).isNotNull();
    runtimeService.messageEventReceived("message_1", executionWithMessage.getId());
    assertThat(listener.getEventsReceived()).hasSize(4);
    // 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.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, a 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.getProcessInstanceId()).isEqualTo(executionWithMessage.getProcessInstanceId());
    assertThat(cancelledEvent.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(cancelledEvent.getCause()).isEqualTo("boundary event (boundaryMessageEventCatching)");
    assertThat(listener.getEventsReceived().get(3)).isInstanceOf(ActivitiActivityCancelledEvent.class);
    cancelledEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(3);
    assertThat(cancelledEvent.getType()).isEqualTo(ActivitiEventType.ACTIVITY_CANCELLED);
    assertThat(cancelledEvent.getActivityId()).isEqualTo("subProcess");
    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 18 with ActivitiMessageEvent

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

the class ActivityEventsTest method testActivityMessageEvents.

/**
 * Test events related to message events, called from the API.
 */
@Deployment
public void testActivityMessageEvents() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageProcess");
    assertThat(processInstance).isNotNull();
    Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("shipOrder").singleResult();
    assertThat(executionWithMessage).isNotNull();
    runtimeService.messageEventReceived("messageName", executionWithMessage.getId());
    assertThat(listener.getEventsReceived()).hasSize(2);
    // 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("shipOrder");
    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();
    // 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.getActivityId()).isEqualTo("shipOrder");
    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();
    assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent) Deployment(org.activiti.engine.test.Deployment)

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