Search in sources :

Example 41 with Execution

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

the class ProcessInstanceModificationMultiInstanceTest method testStartBeforeInnerActivityWithMiBodySequentialSubprocess.

@Deployment(resources = SEQUENTIAL_MULTI_INSTANCE_SUBPROCESS_PROCESS)
public void testStartBeforeInnerActivityWithMiBodySequentialSubprocess() {
    // given the mi body is not yet instantiated
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("miSequentialSubprocess");
    // when
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("subProcessTask").execute();
    // then the mi variables should be correct
    Execution leafExecution = runtimeService.createExecutionQuery().activityId("subProcessTask").singleResult();
    assertNotNull(leafExecution);
    assertVariable(leafExecution, "loopCounter", 0);
    assertVariable(leafExecution, "nrOfInstances", 1);
    assertVariable(leafExecution, "nrOfCompletedInstances", 0);
    assertVariable(leafExecution, "nrOfActiveInstances", 1);
    // and the trees should be correct
    tree = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("beforeTask").beginMiBody("miSubProcess").beginScope("miSubProcess").activity("subProcessTask").endScope().done());
    ExecutionTree executionTree = ExecutionTree.forExecution(processInstance.getId(), processEngine);
    assertThat(executionTree).matches(describeExecutionTree(null).scope().child("beforeTask").concurrent().noScope().up().child(null).concurrent().noScope().child(null).scope().child("subProcessTask").scope().done());
    // and the process is able to complete successfully
    completeTasksInOrder("subProcessTask", "afterTask", "beforeTask", "subProcessTask", "subProcessTask", "subProcessTask", "afterTask");
    assertProcessEnded(processInstance.getId());
}
Also used : ExecutionAssert.describeExecutionTree(org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree) ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) Execution(org.camunda.bpm.engine.runtime.Execution) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 42 with Execution

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

the class ProcessInstanceModificationMultiInstanceTest method testStartBeforeInnerActivityWithMiBodySetNrOfInstancesSequentialSubprocess.

@Deployment(resources = SEQUENTIAL_MULTI_INSTANCE_SUBPROCESS_PROCESS)
public void testStartBeforeInnerActivityWithMiBodySetNrOfInstancesSequentialSubprocess() {
    // given the mi body is not yet instantiated
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("miSequentialSubprocess");
    // when
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("subProcessTask").setVariable("nrOfInstances", 3).execute();
    // then the mi variables should be correct
    Execution leafExecution = runtimeService.createExecutionQuery().activityId("subProcessTask").singleResult();
    assertNotNull(leafExecution);
    assertVariable(leafExecution, "loopCounter", 0);
    assertVariable(leafExecution, "nrOfInstances", 3);
    assertVariable(leafExecution, "nrOfCompletedInstances", 0);
    assertVariable(leafExecution, "nrOfActiveInstances", 1);
    // and the trees should be correct
    tree = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("beforeTask").beginMiBody("miSubProcess").beginScope("miSubProcess").activity("subProcessTask").endScope().done());
    ExecutionTree executionTree = ExecutionTree.forExecution(processInstance.getId(), processEngine);
    assertThat(executionTree).matches(describeExecutionTree(null).scope().child("beforeTask").concurrent().noScope().up().child(null).concurrent().noScope().child(null).scope().child("subProcessTask").scope().done());
    // and two following sequential instances should be created
    completeTasksInOrder("subProcessTask");
    tree = runtimeService.getActivityInstance(processInstance.getId());
    assertThat(tree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("beforeTask").beginMiBody("miSubProcess").beginScope("miSubProcess").activity("subProcessTask").done());
    leafExecution = runtimeService.createExecutionQuery().activityId("subProcessTask").singleResult();
    assertNotNull(leafExecution);
    assertVariable(leafExecution, "loopCounter", 1);
    assertVariable(leafExecution, "nrOfInstances", 3);
    assertVariable(leafExecution, "nrOfCompletedInstances", 1);
    assertVariable(leafExecution, "nrOfActiveInstances", 1);
    completeTasksInOrder("subProcessTask");
    // and the remainder of the process completes successfully
    completeTasksInOrder("subProcessTask", "beforeTask", "subProcessTask", "subProcessTask", "subProcessTask", "afterTask", "afterTask");
    assertProcessEnded(processInstance.getId());
}
Also used : ExecutionAssert.describeExecutionTree(org.camunda.bpm.engine.test.util.ExecutionAssert.describeExecutionTree) ExecutionTree(org.camunda.bpm.engine.test.util.ExecutionTree) Execution(org.camunda.bpm.engine.runtime.Execution) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 43 with Execution

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

the class ExecutionQueryTest method testQueryIntegerVariable.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryIntegerVariable() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("integerVar", 12345);
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("integerVar", 12345);
    vars.put("integerVar2", 67890);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("integerVar", 55555);
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    // Query on single integer variable, should result in 2 matches
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 12345);
    List<Execution> executions = query.list();
    Assert.assertNotNull(executions);
    Assert.assertEquals(2, executions.size());
    // Query on two integer variables, should result in single value
    query = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 12345).variableValueEquals("integerVar2", 67890);
    Execution execution = query.singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance2.getId(), execution.getId());
    // Query with unexisting variable value
    execution = runtimeService.createExecutionQuery().variableValueEquals("integerVar", 9999).singleResult();
    Assert.assertNull(execution);
    // Test NOT_EQUALS
    execution = runtimeService.createExecutionQuery().variableValueNotEquals("integerVar", 12345).singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance3.getId(), execution.getId());
    // Test GREATER_THAN
    execution = runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 44444).singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance3.getId(), execution.getId());
    Assert.assertEquals(0, runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 55555).count());
    Assert.assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThan("integerVar", 1).count());
    // Test GREATER_THAN_OR_EQUAL
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 44444).singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance3.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 55555).singleResult();
    Assert.assertNotNull(execution);
    Assert.assertEquals(processInstance3.getId(), execution.getId());
    Assert.assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("integerVar", 1).count());
    // Test LESS_THAN
    executions = runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 55555).list();
    Assert.assertEquals(2, executions.size());
    List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
    List<String> ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));
    ids.removeAll(expecedIds);
    assertTrue(ids.isEmpty());
    Assert.assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 12345).count());
    Assert.assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThan("integerVar", 66666).count());
    // Test LESS_THAN_OR_EQUAL
    executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("integerVar", 55555).list();
    Assert.assertEquals(3, executions.size());
    Assert.assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThanOrEqual("integerVar", 12344).count());
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ExecutionQuery(org.camunda.bpm.engine.runtime.ExecutionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 44 with Execution

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

the class ExecutionQueryTest method testQueryAllVariableTypes.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryAllVariableTypes() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("nullVar", null);
    vars.put("stringVar", "string");
    vars.put("longVar", 10L);
    vars.put("doubleVar", 1.2);
    vars.put("integerVar", 1234);
    vars.put("booleanVar", true);
    vars.put("shortVar", (short) 123);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("nullVar", null).variableValueEquals("stringVar", "string").variableValueEquals("longVar", 10L).variableValueEquals("doubleVar", 1.2).variableValueEquals("integerVar", 1234).variableValueEquals("booleanVar", true).variableValueEquals("shortVar", (short) 123);
    List<Execution> executions = query.list();
    Assert.assertNotNull(executions);
    Assert.assertEquals(1, executions.size());
    Assert.assertEquals(processInstance.getId(), executions.get(0).getId());
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ExecutionQuery(org.camunda.bpm.engine.runtime.ExecutionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 45 with Execution

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

the class ExecutionQueryTest method testQueryForExecutionsWithMessageEventSubscriptionsOverlappingFilters.

@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/oneMessageCatchProcess.bpmn20.xml")
public void testQueryForExecutionsWithMessageEventSubscriptionsOverlappingFilters() {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneMessageCatchProcess");
    Execution execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("newInvoiceMessage").messageEventSubscription().singleResult();
    assertNotNull(execution);
    assertEquals(instance.getId(), execution.getProcessInstanceId());
    runtimeService.createExecutionQuery().messageEventSubscription().messageEventSubscriptionName("newInvoiceMessage").list();
    assertNotNull(execution);
    assertEquals(instance.getId(), execution.getProcessInstanceId());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) 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