Search in sources :

Example 26 with EventSubscription

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

the class MessageBoundaryEventTest method testBoundaryMessageEventConcurrent.

/**
 * Triggering one boundary event should not remove the event subscription
 * of a boundary event for a concurrent task
 */
@Deployment
public void testBoundaryMessageEventConcurrent() {
    runtimeService.startProcessInstanceByKey("boundaryEvent");
    EventSubscription eventSubscriptionTask1 = runtimeService.createEventSubscriptionQuery().activityId("messageBoundary1").singleResult();
    assertNotNull(eventSubscriptionTask1);
    EventSubscription eventSubscriptionTask2 = runtimeService.createEventSubscriptionQuery().activityId("messageBoundary2").singleResult();
    assertNotNull(eventSubscriptionTask2);
    // when I trigger the boundary event for task1
    runtimeService.correlateMessage("task1Message");
    // then the event subscription for task2 still exists
    assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
    assertNotNull(runtimeService.createEventSubscriptionQuery().activityId("messageBoundary2").singleResult());
}
Also used : EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 27 with EventSubscription

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

the class MessageIntermediateEventTest method testSetSerializedVariableValues.

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/message/MessageIntermediateEventTest.testSingleIntermediateMessageEvent.bpmn20.xml")
@Test
public void testSetSerializedVariableValues() throws IOException, ClassNotFoundException {
    // given
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    EventSubscription messageEventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    // when
    FailingJavaSerializable javaSerializable = new FailingJavaSerializable("foo");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectOutputStream(baos).writeObject(javaSerializable);
    String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
    // then it is not possible to deserialize the object
    try {
        new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
    } catch (RuntimeException e) {
        testRule.assertTextPresent("Exception while deserializing object.", e.getMessage());
    }
    // but it can be set as a variable when delivering a message:
    runtimeService.messageEventReceived("newInvoiceMessage", messageEventSubscription.getExecutionId(), Variables.createVariables().putValueTyped("var", Variables.serializedObjectValue(serializedObject).objectTypeName(FailingJavaSerializable.class.getName()).serializationDataFormat(SerializationDataFormats.JAVA).create()));
    // then
    ObjectValue variableTyped = runtimeService.getVariableTyped(processInstance.getId(), "var", false);
    assertNotNull(variableTyped);
    assertFalse(variableTyped.isDeserialized());
    assertEquals(serializedObject, variableTyped.getValueSerialized());
    assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName());
    assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) ByteArrayInputStream(java.io.ByteArrayInputStream) FailingJavaSerializable(org.camunda.bpm.engine.test.api.variables.FailingJavaSerializable) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 28 with EventSubscription

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

the class ReceiveTaskTest method testSupportsCorrelateMessageByBusinessKeyOnSingleReceiveTask.

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.singleReceiveTask.bpmn20.xml")
public void testSupportsCorrelateMessageByBusinessKeyOnSingleReceiveTask() {
    // given: a process instance with business key 23 waiting in the receive task
    ProcessInstance processInstance23 = runtimeService.startProcessInstanceByKey("testProcess", "23");
    // given: a 2nd process instance with business key 42 waiting in the receive task
    ProcessInstance processInstance42 = runtimeService.startProcessInstanceByKey("testProcess", "42");
    // expect: there is two message event subscriptions for the tasks
    List<EventSubscription> subscriptionList = getEventSubscriptionList();
    assertEquals(2, subscriptionList.size());
    // then: we can correlate the event subscription to one of the process instances
    runtimeService.correlateMessage("newInvoiceMessage", "23");
    // expect: one subscription is removed
    assertEquals(1, getEventSubscriptionList().size());
    // expect: this ends the process instance with business key 23
    assertProcessEnded(processInstance23.getId());
    // expect: other process instance is still running
    assertEquals(1, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance42.getId()).count());
    // then: we can correlate the event subscription to the other process instance
    runtimeService.correlateMessage("newInvoiceMessage", "42");
    // expect: subscription is removed
    assertEquals(0, getEventSubscriptionList().size());
    // expect: this ends the process instance
    assertProcessEnded(processInstance42.getId());
}
Also used : EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 29 with EventSubscription

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

the class ReceiveTaskTest method testSupportsMessageEventReceivedOnParallelMultiReceiveTaskWithCompensation.

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.multiParallelReceiveTaskCompensate.bpmn20.xml")
public void testSupportsMessageEventReceivedOnParallelMultiReceiveTaskWithCompensation() {
    // given: a process instance waiting in two receive tasks
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    // expect: there are two message event subscriptions
    List<EventSubscription> subscriptions = getEventSubscriptionList();
    assertEquals(2, subscriptions.size());
    // then: we can trigger the first event subscription
    runtimeService.messageEventReceived(subscriptions.get(0).getEventName(), subscriptions.get(0).getExecutionId());
    // expect: after completing the first receive task there is one event subscription for compensation
    assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType(EventType.COMPENSATE.name()).count());
    // then: we can trigger the second event subscription
    runtimeService.messageEventReceived(subscriptions.get(1).getEventName(), subscriptions.get(1).getExecutionId());
    // expect: there are three event subscriptions for compensation (two subscriptions for tasks and one for miBody)
    assertEquals(3, runtimeService.createEventSubscriptionQuery().eventType(EventType.COMPENSATE.name()).count());
    // expect: one user task is created
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    // expect: this ends the process instance
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 30 with EventSubscription

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

the class ReceiveTaskTest method testSupportsCorrelateMessageOnSingleReceiveTask.

@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.singleReceiveTask.bpmn20.xml")
public void testSupportsCorrelateMessageOnSingleReceiveTask() {
    // given: a process instance waiting in the receive task
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
    // expect: there is a message event subscription for the task
    List<EventSubscription> subscriptionList = getEventSubscriptionList();
    assertEquals(1, subscriptionList.size());
    EventSubscription subscription = subscriptionList.get(0);
    // then: we can correlate the event subscription
    runtimeService.correlateMessage(subscription.getEventName());
    // expect: subscription is removed
    assertEquals(0, getEventSubscriptionList().size());
    // expect: this ends the process instance
    assertProcessEnded(processInstance.getId());
}
Also used : EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) 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