Search in sources :

Example 11 with EventSubscription

use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.

the class MigrationBoundaryEventsTest method testMigrateSignalBoundaryEventKeepTrigger.

@Test
public void testMigrateSignalBoundaryEventKeepTrigger() {
    // given
    BpmnModelInstance sourceProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder(USER_TASK_ID).boundaryEvent(BOUNDARY_ID).signal(SIGNAL_NAME).userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    BpmnModelInstance targetProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder(USER_TASK_ID).boundaryEvent(BOUNDARY_ID).signal("new" + SIGNAL_NAME).userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
    Map<String, String> activities = new HashMap<String, String>();
    activities.put(USER_TASK_ID, USER_TASK_ID);
    activities.put(BOUNDARY_ID, BOUNDARY_ID);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(USER_TASK_ID, USER_TASK_ID).mapActivities(BOUNDARY_ID, BOUNDARY_ID).build();
    // when
    testHelper.createProcessInstanceAndMigrate(migrationPlan);
    // then
    testHelper.assertEventSubscriptionMigrated(BOUNDARY_ID, BOUNDARY_ID, SIGNAL_NAME);
    // and no event subscription for the new message name exists
    EventSubscription eventSubscription = rule.getRuntimeService().createEventSubscriptionQuery().eventName("new" + SIGNAL_NAME).singleResult();
    assertNull(eventSubscription);
    assertEquals(1, rule.getRuntimeService().createEventSubscriptionQuery().count());
    // and it is possible to trigger the event with the old message name and successfully complete the migrated instance
    rule.getProcessEngine().getRuntimeService().signalEventReceived(SIGNAL_NAME);
    testHelper.completeTask(AFTER_BOUNDARY_TASK);
    testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
Also used : EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) HashMap(java.util.HashMap) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Example 12 with EventSubscription

use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.

the class MigrationMessageStartEventTest method testMigrateEventSubscriptionWithEventSubProcess.

@Test
public void testMigrateEventSubscriptionWithEventSubProcess() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(EventSubProcessModels.MESSAGE_EVENT_SUBPROCESS_PROCESS);
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());
    // when
    runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance.getId()).execute();
    // then
    EventSubscription eventSubscriptionAfter = runtimeService.createEventSubscriptionQuery().singleResult();
    assertNotNull(eventSubscriptionAfter);
    assertEquals(EventSubProcessModels.MESSAGE_NAME, eventSubscriptionAfter.getEventName());
    runtimeService.correlateMessage(EventSubProcessModels.MESSAGE_NAME);
    testHelper.completeTask("eventSubProcessTask");
    testHelper.assertProcessEnded(processInstance.getId());
}
Also used : EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 13 with EventSubscription

use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.

the class MigrationMessageStartEventTest method testMigrateEventSubscription.

@Test
public void testMigrateEventSubscription() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(MessageReceiveModels.MESSAGE_START_PROCESS);
    String sourceProcessDefinitionId = sourceProcessDefinition.getId();
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcessDefinitionId, sourceProcessDefinitionId).mapEqualActivities().build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinitionId);
    EventSubscription eventSubscription = runtimeService.createEventSubscriptionQuery().activityId("startEvent").eventName(MessageReceiveModels.MESSAGE_NAME).singleResult();
    // when
    runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance.getId()).execute();
    // then
    assertEventSubscriptionMigrated(eventSubscription, "startEvent", MessageReceiveModels.MESSAGE_NAME);
    testHelper.completeTask("userTask");
    testHelper.assertProcessEnded(processInstance.getId());
}
Also used : EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 14 with EventSubscription

use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.

the class CallActivityTest method testInterruptingMessageEventSubProcessEventSubscriptionsInsideCallActivity.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testInterruptingEventSubProcessEventSubscriptions.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/callactivity/interruptingEventSubProcessEventSubscriptions.bpmn20.xml" })
public void testInterruptingMessageEventSubProcessEventSubscriptionsInsideCallActivity() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callInterruptingEventSubProcess");
    // one task in the call activity subprocess should be active after starting the process instance
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task taskInsideCallActivity = taskQuery.singleResult();
    assertEquals("taskBeforeInterruptingEventSubprocess", taskInsideCallActivity.getTaskDefinitionKey());
    // we should have no event subscriptions for the parent process
    assertEquals(0, runtimeService.createEventSubscriptionQuery().processInstanceId(processInstance.getId()).count());
    // we should have two event subscriptions for the called process instance, one for message and one for signal
    String calledProcessInstanceId = taskInsideCallActivity.getProcessInstanceId();
    EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery().processInstanceId(calledProcessInstanceId);
    List<EventSubscription> subscriptions = eventSubscriptionQuery.list();
    assertEquals(2, subscriptions.size());
    // start the message interrupting event sub process
    runtimeService.correlateMessage("newMessage");
    Task taskAfterMessageStartEvent = taskQuery.processInstanceId(calledProcessInstanceId).singleResult();
    assertEquals("taskAfterMessageStartEvent", taskAfterMessageStartEvent.getTaskDefinitionKey());
    // no subscriptions left
    assertEquals(0, eventSubscriptionQuery.count());
    // Complete the task inside the called process instance
    taskService.complete(taskAfterMessageStartEvent.getId());
    assertProcessEnded(calledProcessInstanceId);
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) EventSubscriptionQuery(org.camunda.bpm.engine.runtime.EventSubscriptionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 15 with EventSubscription

use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.

the class CallActivityTest method testInterruptingSignalEventSubProcessEventSubscriptionsInsideCallActivity.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testInterruptingEventSubProcessEventSubscriptions.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/callactivity/interruptingEventSubProcessEventSubscriptions.bpmn20.xml" })
public void testInterruptingSignalEventSubProcessEventSubscriptionsInsideCallActivity() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callInterruptingEventSubProcess");
    // one task in the call activity subprocess should be active after starting the process instance
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task taskInsideCallActivity = taskQuery.singleResult();
    assertEquals("taskBeforeInterruptingEventSubprocess", taskInsideCallActivity.getTaskDefinitionKey());
    // we should have no event subscriptions for the parent process
    assertEquals(0, runtimeService.createEventSubscriptionQuery().processInstanceId(processInstance.getId()).count());
    // we should have two event subscriptions for the called process instance, one for message and one for signal
    String calledProcessInstanceId = taskInsideCallActivity.getProcessInstanceId();
    EventSubscriptionQuery eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery().processInstanceId(calledProcessInstanceId);
    List<EventSubscription> subscriptions = eventSubscriptionQuery.list();
    assertEquals(2, subscriptions.size());
    // start the signal interrupting event sub process
    runtimeService.signalEventReceived("newSignal");
    Task taskAfterSignalStartEvent = taskQuery.processInstanceId(calledProcessInstanceId).singleResult();
    assertEquals("taskAfterSignalStartEvent", taskAfterSignalStartEvent.getTaskDefinitionKey());
    // no subscriptions left
    assertEquals(0, eventSubscriptionQuery.count());
    // Complete the task inside the called process instance
    taskService.complete(taskAfterSignalStartEvent.getId());
    assertProcessEnded(calledProcessInstanceId);
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) EventSubscriptionQuery(org.camunda.bpm.engine.runtime.EventSubscriptionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

EventSubscription (org.camunda.bpm.engine.runtime.EventSubscription)71 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)38 Deployment (org.camunda.bpm.engine.test.Deployment)38 Task (org.camunda.bpm.engine.task.Task)16 EventSubscriptionQuery (org.camunda.bpm.engine.runtime.EventSubscriptionQuery)13 Test (org.junit.Test)13 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)10 Execution (org.camunda.bpm.engine.runtime.Execution)8 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)6 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)4 HashMap (java.util.HashMap)3 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)2 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)2 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)2 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1