Search in sources :

Example 6 with ActivitiActivityCancelledEvent

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

the class ActivityEventsTest method testActivitySignalBoundaryEventsOnUserTask.

@Deployment
public void testActivitySignalBoundaryEventsOnUserTask() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalOnUserTask");
    assertNotNull(processInstance);
    Execution executionWithSignal = runtimeService.createExecutionQuery().activityId("userTask").singleResult();
    assertNotNull(executionWithSignal);
    runtimeService.signalEventReceived("signalName");
    assertEquals(1, listener.getEventsReceived().size());
    // Next, an signal-event is expected, as a result of the message
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiActivityCancelledEvent);
    ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
    assertEquals("userTask", signalEvent.getActivityId());
    assertEquals(executionWithSignal.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithSignal.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertNotNull(signalEvent.getCause());
    assertTrue(signalEvent.getCause() instanceof SignalEventSubscriptionEntity);
    SignalEventSubscriptionEntity cause = (SignalEventSubscriptionEntity) signalEvent.getCause();
    assertEquals("signalName", cause.getEventName());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Example 7 with ActivitiActivityCancelledEvent

use of org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent 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");
    assertNotNull(processInstance);
    Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("cloudformtask1").singleResult();
    assertNotNull(executionWithMessage);
    runtimeService.messageEventReceived("message_1", executionWithMessage.getId());
    assertEquals(2, listener.getEventsReceived().size());
    // First, a message-event is expected
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiMessageEvent);
    ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED, messageEvent.getType());
    assertEquals("boundaryMessageEventCatching", messageEvent.getActivityId());
    assertEquals(executionWithMessage.getId(), messageEvent.getExecutionId());
    assertEquals(executionWithMessage.getProcessInstanceId(), messageEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), messageEvent.getProcessDefinitionId());
    assertEquals("message_1", messageEvent.getMessageName());
    assertNull(messageEvent.getMessageData());
    // Next, an signal-event is expected, as a result of the message
    assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiActivityCancelledEvent);
    ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
    assertEquals("cloudformtask1", signalEvent.getActivityId());
    assertEquals(executionWithMessage.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithMessage.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertNotNull(signalEvent.getCause());
    assertTrue(signalEvent.getCause() instanceof MessageEventSubscriptionEntity);
    MessageEventSubscriptionEntity cause = (MessageEventSubscriptionEntity) signalEvent.getCause();
    assertEquals("message_1", cause.getEventName());
    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) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Example 8 with ActivitiActivityCancelledEvent

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

the class ActivityEventsTest method testActivityTimeOutEvent.

@Deployment(resources = "org/activiti/engine/test/api/event/JobEventsTest.testJobEntityEvents.bpmn20.xml")
public void testActivityTimeOutEvent() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJobEvents");
    Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);
    // Force timer to fire
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DAY_OF_YEAR, 1);
    processEngineConfiguration.getClock().setCurrentTime(tomorrow.getTime());
    waitForJobExecutorToProcessAllJobs(2000, 100);
    // Check timeout has been dispatched
    assertEquals(1, listener.getEventsReceived().size());
    ActivitiEvent activitiEvent = listener.getEventsReceived().get(0);
    assertEquals("ACTIVITY_CANCELLED event expected", ActivitiEventType.ACTIVITY_CANCELLED, activitiEvent.getType());
    ActivitiActivityCancelledEvent cancelledEvent = (ActivitiActivityCancelledEvent) activitiEvent;
    assertTrue("TIMER is the cause of the cancellation", cancelledEvent.getCause() instanceof TimerEntity);
}
Also used : ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) Calendar(java.util.Calendar) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 9 with ActivitiActivityCancelledEvent

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

the class ActivityEventsTest method testActivityTimeOutEventInCallActivity.

@Deployment
public void testActivityTimeOutEventInCallActivity() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnCallActivity");
    Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(theJob);
    // Force timer to fire
    Calendar timeToFire = Calendar.getInstance();
    timeToFire.add(Calendar.HOUR, 2);
    timeToFire.add(Calendar.SECOND, 5);
    processEngineConfiguration.getClock().setCurrentTime(timeToFire.getTime());
    waitForJobExecutorToProcessAllJobs(20000, 500);
    // Check timeout-events have been dispatched
    assertEquals(4, listener.getEventsReceived().size());
    List<String> eventIdList = new ArrayList<String>();
    for (ActivitiEvent event : listener.getEventsReceived()) {
        assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, event.getType());
        assertTrue("TIMER is the cause of the cancellation", ((ActivitiActivityCancelledEvent) event).getCause() instanceof TimerEntity);
        eventIdList.add(((ActivitiActivityEventImpl) event).getActivityId());
    }
    assertTrue(eventIdList.indexOf("innerTask1") >= 0);
    assertTrue(eventIdList.indexOf("innerTask2") >= 0);
    assertTrue(eventIdList.indexOf("innerFork") >= 0);
    assertTrue(eventIdList.indexOf("callActivity") >= 0);
}
Also used : ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiEvent(org.activiti.engine.delegate.event.ActivitiEvent) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ActivitiActivityCancelledEvent (org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent)9 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 Deployment (org.activiti.engine.test.Deployment)9 ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)5 Execution (org.activiti.engine.runtime.Execution)4 Calendar (java.util.Calendar)3 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)3 Job (org.activiti.engine.runtime.Job)3 ArrayList (java.util.ArrayList)2 ActivitiCancelledEvent (org.activiti.engine.delegate.event.ActivitiCancelledEvent)2 ActivitiMessageEvent (org.activiti.engine.delegate.event.ActivitiMessageEvent)2 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)2 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)2