Search in sources :

Example 66 with VariableInstance

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

the class MigrationSignalCatchEventTest method testMigrateEventSubscriptionUpdateSignalExpressionNameWithVariables.

@Test
public void testMigrateEventSubscriptionUpdateSignalExpressionNameWithVariables() {
    // given
    String newSignalName = "new" + SignalCatchModels.SIGNAL_NAME + "-${var}";
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(SignalCatchModels.ONE_SIGNAL_CATCH_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.newModel().startEvent().intermediateCatchEvent("signalCatch").signal(newSignalName).userTask("userTask").endEvent().done());
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("signalCatch", "signalCatch").updateEventTrigger().build();
    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("var", "foo");
    // when
    ProcessInstance processInstance = testHelper.createProcessInstanceAndMigrate(migrationPlan, variables);
    // then there should be a variable
    VariableInstance beforeMigration = testHelper.snapshotBeforeMigration.getSingleVariable("var");
    Assert.assertEquals(1, testHelper.snapshotAfterMigration.getVariables().size());
    testHelper.assertVariableMigratedToExecution(beforeMigration, beforeMigration.getExecutionId());
    // and the signal event subscription's event name has changed
    String resolvedSignalName = "new" + SignalCatchModels.SIGNAL_NAME + "-foo";
    testHelper.assertEventSubscriptionMigrated("signalCatch", SignalCatchModels.SIGNAL_NAME, "signalCatch", resolvedSignalName);
    // and it is possible to trigger the event and complete the task afterwards
    rule.getRuntimeService().signalEventReceived(resolvedSignalName);
    testHelper.completeTask("userTask");
    testHelper.assertProcessEnded(processInstance.getId());
}
Also used : HashMap(java.util.HashMap) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 67 with VariableInstance

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

the class VariableInstanceQueryForOracleTest method testQueryWhen1000InstancesActive.

@Test
public void testQueryWhen1000InstancesActive() {
    // given
    Assume.assumeTrue(engineRule.getProcessEngineConfiguration().getDatabaseType().equals("oracle"));
    RuntimeService runtimeService = engineRule.getRuntimeService();
    testRule.deploy(ProcessModels.TWO_TASKS_PROCESS);
    String[] ids = new String[1000];
    // when
    for (int i = 0; i < 1000; i++) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", Variables.createVariables().putValue("foo", "bar"));
        String activityInstanceId = runtimeService.getActivityInstance(processInstance.getId()).getId();
        ids[i] = activityInstanceId;
    }
    // then
    List<VariableInstance> variables = engineRule.getRuntimeService().createVariableInstanceQuery().activityInstanceIdIn(ids).list();
    assertEquals(1000, variables.size());
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test)

Example 68 with VariableInstance

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

the class VariableInstanceQueryTest method testQueryOrderByType_Desc.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryOrderByType_Desc() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("intVar", 123);
    variables.put("myVar", "test123");
    runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    // when
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().orderByVariableType().desc();
    // then
    List<VariableInstance> result = query.list();
    assertFalse(result.isEmpty());
    assertEquals(2, result.size());
    VariableInstance first = result.get(0);
    VariableInstance second = result.get(1);
    // string
    assertEquals("myVar", first.getName());
    assertEquals("string", first.getTypeName());
    // integer
    assertEquals("intVar", second.getName());
    assertEquals("integer", second.getTypeName());
}
Also used : HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 69 with VariableInstance

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

the class VariableInstanceQueryTest method testSimpleSubProcessVariables.

@Deployment
public void testSimpleSubProcessVariables() {
    // given
    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("processVariable", "aProcessVariable");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processWithSubProcess", processVariables);
    Task task = taskService.createTaskQuery().taskDefinitionKey("UserTask_1").singleResult();
    runtimeService.setVariableLocal(task.getExecutionId(), "aLocalVariable", "aLocalValue");
    ActivityInstance tree = runtimeService.getActivityInstance(processInstance.getId());
    assertEquals(1, tree.getChildActivityInstances().length);
    ActivityInstance subProcessInstance = tree.getActivityInstances("SubProcess_1")[0];
    // then the local variable has activity instance Id of the subprocess
    VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(subProcessInstance.getId());
    VariableInstance localVariable = query.singleResult();
    assertNotNull(localVariable);
    assertEquals("aLocalVariable", localVariable.getName());
    assertEquals("aLocalValue", localVariable.getValue());
    // and the global variable has the activity instance Id of the process instance:
    query = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(processInstance.getId());
    VariableInstance globalVariable = query.singleResult();
    assertNotNull(localVariable);
    assertEquals("processVariable", globalVariable.getName());
    assertEquals("aProcessVariable", globalVariable.getValue());
    taskService.complete(task.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 70 with VariableInstance

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

the class VariableInstanceQueryTest method testQueryByActivityInstanceId.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testQueryByActivityInstanceId() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("stringVar", "test");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    String activityId = runtimeService.getActivityInstance(processInstance.getId()).getChildActivityInstances()[0].getId();
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "taskVariable", "aCustomValue");
    // when
    VariableInstanceQuery taskVariablesQuery = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(activityId);
    VariableInstanceQuery processVariablesQuery = runtimeService.createVariableInstanceQuery().activityInstanceIdIn(processInstance.getId());
    // then
    VariableInstance taskVar = taskVariablesQuery.singleResult();
    assertNotNull(taskVar);
    assertEquals(1, taskVariablesQuery.count());
    assertEquals("string", taskVar.getTypeName());
    assertEquals("taskVariable", taskVar.getName());
    assertEquals("aCustomValue", taskVar.getValue());
    VariableInstance processVar = processVariablesQuery.singleResult();
    assertEquals(1, processVariablesQuery.count());
    assertEquals("string", processVar.getTypeName());
    assertEquals("stringVar", processVar.getName());
    assertEquals("test", processVar.getValue());
}
Also used : Task(org.camunda.bpm.engine.task.Task) HashMap(java.util.HashMap) VariableInstanceQuery(org.camunda.bpm.engine.runtime.VariableInstanceQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)374 Deployment (org.camunda.bpm.engine.test.Deployment)265 Test (org.junit.Test)167 HashMap (java.util.HashMap)136 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)122 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)93 Task (org.camunda.bpm.engine.task.Task)67 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)42 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)39 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)33 Execution (org.camunda.bpm.engine.runtime.Execution)33 VariableMap (org.camunda.bpm.engine.variable.VariableMap)30 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)27 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)26 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)23 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)21 ExecutionTree (org.camunda.bpm.engine.test.util.ExecutionTree)17 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)13 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)11 List (java.util.List)10