Search in sources :

Example 11 with MessageCorrelationResult

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

the class MessageCorrelationByLocalVariablesTest method testReceiveTaskMessageCorrelationAll.

@Test
public void testReceiveTaskMessageCorrelationAll() {
    // given
    BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1").startEvent().subProcess("SubProcess_1").embeddedSubProcess().startEvent().receiveTask("MessageReceiver_1").message(TEST_MESSAGE_NAME).camundaInputParameter("localVar", "${loopVar}").camundaInputParameter("constVar", // to test array of parameters
    "someValue").userTask("UserTask_1").endEvent().subProcessDone().multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone().endEvent().done();
    testHelper.deploy(model);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("vars", Arrays.asList(1, 2, 1));
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables);
    // when correlated ALL by local variables
    String messageName = TEST_MESSAGE_NAME;
    Map<String, Object> correlationKeys = new HashMap<String, Object>();
    int correlationKey = 1;
    correlationKeys.put("localVar", correlationKey);
    correlationKeys.put("constVar", "someValue");
    List<MessageCorrelationResult> messageCorrelationResults = engineRule.getRuntimeService().createMessageCorrelation(messageName).localVariablesEqual(correlationKeys).setVariables(Variables.createVariables().putValue("newVar", "newValue")).correlateAllWithResult();
    // then two messages correlated, one message task is still waiting
    for (MessageCorrelationResult result : messageCorrelationResults) {
        checkExecutionMessageCorrelationResult(result, processInstance, "MessageReceiver_1");
    }
    // uncorrelated executions
    List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list();
    assertEquals(1, uncorrelatedExecutions.size());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) Test(org.junit.Test)

Example 12 with MessageCorrelationResult

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

the class MessageCorrelationByLocalVariablesTest method testMessageBoundaryEventMessageCorrelation.

@Test
public void testMessageBoundaryEventMessageCorrelation() {
    // given
    BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1").startEvent().subProcess("SubProcess_1").embeddedSubProcess().startEvent().userTask("UserTask_1").camundaInputParameter("localVar", "${loopVar}").camundaInputParameter("constVar", // to test array of parameters
    "someValue").boundaryEvent("MessageReceiver_1").message(TEST_MESSAGE_NAME).userTask("UserTask_2").endEvent().subProcessDone().multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone().endEvent().done();
    testHelper.deploy(model);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("vars", Arrays.asList(1, 2, 3));
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables);
    // when correlated by local variables
    String messageName = TEST_MESSAGE_NAME;
    Map<String, Object> correlationKeys = new HashMap<String, Object>();
    int correlationKey = 1;
    correlationKeys.put("localVar", correlationKey);
    correlationKeys.put("constVar", "someValue");
    Map<String, Object> messagePayload = new HashMap<String, Object>();
    messagePayload.put("newVar", "newValue");
    MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName).localVariablesEqual(correlationKeys).setVariables(messagePayload).correlateWithResult();
    // then one message is correlated, two others continue waiting
    checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "UserTask_1");
    // uncorrelated executions
    List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("UserTask_1").list();
    assertEquals(2, uncorrelatedExecutions.size());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) Test(org.junit.Test)

Example 13 with MessageCorrelationResult

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

the class MessageCorrelationByLocalVariablesTest method testIntermediateCatchEventMessageCorrelation.

@Test
public void testIntermediateCatchEventMessageCorrelation() {
    // given
    BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1").startEvent().subProcess("SubProcess_1").embeddedSubProcess().startEvent().intermediateCatchEvent("MessageReceiver_1").message(TEST_MESSAGE_NAME).camundaInputParameter("localVar", "${loopVar}").userTask("UserTask_1").endEvent().subProcessDone().multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone().endEvent().done();
    testHelper.deploy(model);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("vars", Arrays.asList(1, 2, 3));
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables);
    // when correlated by local variables
    String messageName = TEST_MESSAGE_NAME;
    int correlationKey = 1;
    MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName).localVariableEquals("localVar", correlationKey).setVariables(Variables.createVariables().putValue("newVar", "newValue")).correlateWithResult();
    // then one message is correlated, two others continue waiting
    checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "MessageReceiver_1");
    // uncorrelated executions
    List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list();
    assertEquals(2, uncorrelatedExecutions.size());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) Test(org.junit.Test)

Aggregations

MessageCorrelationResult (org.camunda.bpm.engine.runtime.MessageCorrelationResult)13 Test (org.junit.Test)10 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)9 Execution (org.camunda.bpm.engine.runtime.Execution)6 HashMap (java.util.HashMap)5 Deployment (org.camunda.bpm.engine.test.Deployment)5 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)5 ArrayList (java.util.ArrayList)2 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)2 List (java.util.List)1 MismatchingMessageCorrelationException (org.camunda.bpm.engine.MismatchingMessageCorrelationException)1 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)1 CorrelationHandler (org.camunda.bpm.engine.impl.runtime.CorrelationHandler)1 CorrelationHandlerResult (org.camunda.bpm.engine.impl.runtime.CorrelationHandlerResult)1 CorrelationSet (org.camunda.bpm.engine.impl.runtime.CorrelationSet)1 MessageCorrelationResultDto (org.camunda.bpm.engine.rest.dto.message.MessageCorrelationResultDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 RestException (org.camunda.bpm.engine.rest.exception.RestException)1 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)1 MessageCorrelationBuilder (org.camunda.bpm.engine.runtime.MessageCorrelationBuilder)1