Search in sources :

Example 31 with Execution

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

the class BoundaryErrorEventTest method testCatchErrorOnSubprocessThrownByInterruptingEventSubprocess.

@Deployment
public void testCatchErrorOnSubprocessThrownByInterruptingEventSubprocess() {
    runtimeService.startProcessInstanceByKey("testProcess");
    EventSubscription messageSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
    runtimeService.messageEventReceived("message", messageSubscription.getExecutionId());
    // should successfully have reached the task following the boundary event
    Execution taskExecution = runtimeService.createExecutionQuery().activityId("afterBoundaryTask").singleResult();
    assertNotNull(taskExecution);
    Task task = taskService.createTaskQuery().executionId(taskExecution.getId()).singleResult();
    assertNotNull(task);
}
Also used : Task(org.camunda.bpm.engine.task.Task) Execution(org.camunda.bpm.engine.runtime.Execution) EventSubscription(org.camunda.bpm.engine.runtime.EventSubscription) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 32 with Execution

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

the class DefaultCorrelationHandler method correlateMessageToExecutions.

protected List<CorrelationHandlerResult> correlateMessageToExecutions(CommandContext commandContext, String messageName, CorrelationSet correlationSet) {
    ExecutionQueryImpl query = new ExecutionQueryImpl();
    Map<String, Object> correlationKeys = correlationSet.getCorrelationKeys();
    if (correlationKeys != null) {
        for (Map.Entry<String, Object> correlationKey : correlationKeys.entrySet()) {
            query.processVariableValueEquals(correlationKey.getKey(), correlationKey.getValue());
        }
    }
    Map<String, Object> localCorrelationKeys = correlationSet.getLocalCorrelationKeys();
    if (localCorrelationKeys != null) {
        for (Map.Entry<String, Object> correlationKey : localCorrelationKeys.entrySet()) {
            query.variableValueEquals(correlationKey.getKey(), correlationKey.getValue());
        }
    }
    String businessKey = correlationSet.getBusinessKey();
    if (businessKey != null) {
        query.processInstanceBusinessKey(businessKey);
    }
    String processInstanceId = correlationSet.getProcessInstanceId();
    if (processInstanceId != null) {
        query.processInstanceId(processInstanceId);
    }
    if (messageName != null) {
        query.messageEventSubscriptionName(messageName);
    } else {
        query.messageEventSubscription();
    }
    if (correlationSet.isTenantIdSet) {
        String tenantId = correlationSet.getTenantId();
        if (tenantId != null) {
            query.tenantIdIn(tenantId);
        } else {
            query.withoutTenantId();
        }
    }
    // restrict to active executions
    query.active();
    List<Execution> matchingExecutions = query.evaluateExpressionsAndExecuteList(commandContext, null);
    List<CorrelationHandlerResult> result = new ArrayList<CorrelationHandlerResult>(matchingExecutions.size());
    for (Execution matchingExecution : matchingExecutions) {
        CorrelationHandlerResult correlationResult = CorrelationHandlerResult.matchedExecution((ExecutionEntity) matchingExecution);
        result.add(correlationResult);
    }
    return result;
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) ExecutionQueryImpl(org.camunda.bpm.engine.impl.ExecutionQueryImpl) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 33 with Execution

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

the class MessageCorrelationTest method testCorrelationWithoutMessageNameFluent.

@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testCorrelationWithoutMessageNameFluent() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("variable", "value1");
    runtimeService.startProcessInstanceByKey("process", variables);
    variables.put("variable", "value2");
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("process", variables);
    runtimeService.createMessageCorrelation(null).processInstanceVariableEquals("variable", "value2").correlate();
    List<Execution> correlatedExecutions = runtimeService.createExecutionQuery().activityId("task").list();
    assertEquals(1, correlatedExecutions.size());
    assertEquals(instance.getId(), correlatedExecutions.get(0).getId());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 34 with Execution

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

the class MessageCorrelationTest method testCorrelationByProcessInstanceIdOnly.

@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testCorrelationByProcessInstanceIdOnly() {
    runtimeService.startProcessInstanceByKey("process");
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("process");
    runtimeService.createMessageCorrelation(null).processInstanceId(instance.getId()).correlate();
    List<Execution> correlatedExecutions = runtimeService.createExecutionQuery().activityId("task").list();
    assertEquals(1, correlatedExecutions.size());
    assertEquals(instance.getId(), correlatedExecutions.get(0).getId());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 35 with Execution

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

the class MessageCorrelationTest method testCorrelationByBusinessKeyAndVariables.

@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testCorrelationByBusinessKeyAndVariables() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aKey", "aValue");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process", "aBusinessKey", variables);
    variables = new HashMap<String, Object>();
    variables.put("aKey", "aValue");
    runtimeService.startProcessInstanceByKey("process", "anotherBusinessKey", variables);
    String messageName = "newInvoiceMessage";
    Map<String, Object> correlationKeys = new HashMap<String, Object>();
    correlationKeys.put("aKey", "aValue");
    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("aProcessVariable", "aVariableValue");
    runtimeService.correlateMessage(messageName, "aBusinessKey", correlationKeys, processVariables);
    Execution correlatedExecution = runtimeService.createExecutionQuery().activityId("task").processVariableValueEquals("aProcessVariable", "aVariableValue").singleResult();
    assertNotNull(correlatedExecution);
    ProcessInstance correlatedProcessInstance = runtimeService.createProcessInstanceQuery().processInstanceId(correlatedExecution.getProcessInstanceId()).singleResult();
    assertEquals("aBusinessKey", correlatedProcessInstance.getBusinessKey());
    runtimeService.deleteProcessInstance(processInstance.getId(), null);
    // fluent builder /////////////////////////////
    variables = new HashMap<String, Object>();
    variables.put("aKey", "aValue");
    processInstance = runtimeService.startProcessInstanceByKey("process", "aBusinessKey", variables);
    runtimeService.createMessageCorrelation(messageName).processInstanceBusinessKey("aBusinessKey").processInstanceVariableEquals("aKey", "aValue").setVariable("aProcessVariable", "aVariableValue").correlate();
    correlatedExecution = runtimeService.createExecutionQuery().activityId("task").processVariableValueEquals("aProcessVariable", "aVariableValue").singleResult();
    assertNotNull(correlatedExecution);
    correlatedProcessInstance = runtimeService.createProcessInstanceQuery().processInstanceId(correlatedExecution.getProcessInstanceId()).singleResult();
    assertEquals("aBusinessKey", correlatedProcessInstance.getBusinessKey());
    runtimeService.deleteProcessInstance(processInstance.getId(), null);
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Execution (org.camunda.bpm.engine.runtime.Execution)279 Deployment (org.camunda.bpm.engine.test.Deployment)188 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)143 Task (org.camunda.bpm.engine.task.Task)99 Test (org.junit.Test)95 HashMap (java.util.HashMap)45 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)33 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)23 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 ThrowErrorDelegate.leaveExecution (org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate.leaveExecution)18 ExecutionQuery (org.camunda.bpm.engine.runtime.ExecutionQuery)17 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)15 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)14 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)14 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)14 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)14 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)13 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)12 ArrayList (java.util.ArrayList)11