org.camunda.bpm.engine.runtime.VariableInstance Java Examples

The following examples show how to use org.camunda.bpm.engine.runtime.VariableInstance. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SampleCamundaRestApplicationIT.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Test
public void multipartFileUploadCamundaRestIsWorking() throws Exception {
  final String variableName = "testvariable";
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TestProcess");
  LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
  map.add("data", new ClassPathResource("/bpmn/test.bpmn"));
  map.add("valueType", "File");
  HttpHeaders headers = new HttpHeaders();
  headers.setContentType(MediaType.MULTIPART_FORM_DATA);
  headers.setContentDispositionFormData("data", "test.bpmn");

  HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
  ResponseEntity<String> exchange = testRestTemplate.exchange("/rest/engine/{enginename}/process-instance/{id}/variables/{variableName}/data",
      HttpMethod.POST, requestEntity, String.class, camundaBpmProperties.getProcessEngineName(), processInstance.getId(), variableName);

  assertEquals(HttpStatus.NO_CONTENT, exchange.getStatusCode());

  VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()).variableName(variableName)
      .singleResult();
  ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) variableInstance.getValue();
  assertTrue(byteArrayInputStream.available() > 0);
}
 
Example #2
Source File: ExternalTaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCompleteWithNonLocalVariables() {
  // given
  BpmnModelInstance instance = Bpmn.createExecutableProcess("Process").startEvent().serviceTask("externalTask")
      .camundaType("external").camundaTopic("foo").camundaTaskPriority("100")
      .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadLocalVariableListenerImpl.class)
      .userTask("user").endEvent().done();

  deployment(instance);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");

  List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic("foo", 1L).execute();

  // when
  externalTaskService.complete(lockedTasks.get(0).getId(), WORKER_ID,
      Variables.createVariables().putValue("abc", "bar"), null);

  // then
  VariableInstance variableInstance = runtimeService.createVariableInstanceQuery()
      .processInstanceIdIn(processInstance.getId()).singleResult();
  assertNotNull(variableInstance);
  assertEquals("bar", variableInstance.getValue());
  assertEquals("abc", variableInstance.getName());
}
 
Example #3
Source File: FilterResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected List<VariableInstance> queryVariablesInstancesByVariableScopeIds(Collection<String> variableNames, Collection<String> variableScopeIds) {

    VariableInstanceQueryImpl query = (VariableInstanceQueryImpl) getProcessEngine().getRuntimeService()
        .createVariableInstanceQuery()
        .disableBinaryFetching()
        .disableCustomObjectDeserialization()
        .variableNameIn(variableNames.toArray(new String[0]))
        .variableScopeIdIn(variableScopeIds.toArray(new String[0]));

    // the number of results is capped at:
    // #tasks * #variableNames * 5 (we have five variable scopes per task)
    // this value may exceed the configured query pagination limit, so we make an unbounded query.
    // As #tasks is bounded by the pagination limit, it will never load an unbounded number of variables.
    return query.unlimitedList();

  }
 
Example #4
Source File: ConditionalStartEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = SINGLE_CONDITIONAL_START_EVENT_XML)
public void testStartInstanceWithTransientVariableCondition() {
  // given a deployed process
  VariableMap variableMap = Variables.createVariables()
      .putValueTyped("foo", Variables.integerValue(1, true));

  // when
  List<ProcessInstance> instances = runtimeService
      .createConditionEvaluation()
      .setVariables(variableMap)
      .evaluateStartConditions();

  // then
  assertEquals(1, instances.size());

  VariableInstance vars = runtimeService.createVariableInstanceQuery().singleResult();
  assertNull(vars);
}
 
Example #5
Source File: InputOutputTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testOutputNested() {
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("exprKey", "b");
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess", variables);

  VariableInstance var1 = runtimeService.createVariableInstanceQuery().variableName("var1").singleResult();
  TreeMap<String, Object> value = (TreeMap) var1.getValue();
  List<Object> nestedList = (List<Object>) value.get("a");
  assertEquals("stringInListNestedInMap", nestedList.get(0));
  assertEquals("b", nestedList.get(1));
  assertEquals(pi.getId(), var1.getExecutionId());
  assertEquals("stringValueWithExprKey", value.get("b"));

  VariableInstance var2 = runtimeService.createVariableInstanceQuery().variableName("var2").singleResult();
  assertNotNull(var2);
  assertEquals("stringConstantValue", var2.getValue());
  assertEquals(pi.getId(), var2.getExecutionId());
}
 
Example #6
Source File: CreateProcessInstanceWithJsonVariablesTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@ScenarioUnderTest("initProcessInstance.1")
@Test
public void testCreateProcessInstanceWithVariable() {
  // then
  ProcessInstance processInstance = engineRule.getRuntimeService().createProcessInstanceQuery().processInstanceBusinessKey("processWithJsonVariables79").singleResult();
  List<VariableInstance> variables = engineRule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()).list();
  assertEquals(4, variables.size());

  final Object objectVariable = engineRule.getRuntimeService().getVariable(processInstance.getId(), "objectVariable");
  assertObjectVariable(objectVariable);

  final Object plainTypeArrayVariable = engineRule.getRuntimeService().getVariable(processInstance.getId(), "plainTypeArrayVariable");
  assertPlainTypeArrayVariable(plainTypeArrayVariable);

  final Object notGenericObjectListVariable = engineRule.getRuntimeService().getVariable(processInstance.getId(), "notGenericObjectListVariable");
  assertNotGenericObjectListVariable(notGenericObjectListVariable);

  final TypedValue serializedObject = engineRule.getRuntimeService().getVariableTyped(processInstance.getId(), "serializedMapVariable", true);
  assertSerializedMap(serializedObject);
}
 
Example #7
Source File: ExecutionVariablesTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/variables/ExecutionVariablesTest.testTreeCompactionForkParallelGateway.bpmn20.xml")
public void testTreeCompactionAndExpansionWithConcurrentLocalVariables() {

  // given
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

  Execution task1Execution = runtimeService.createExecutionQuery().activityId("task1").singleResult();
  Task task2 = taskService.createTaskQuery().taskDefinitionKey("task2").singleResult();

  runtimeService.setVariableLocal(task1Execution.getId(), "var", "value");

  // when compacting the tree
  taskService.complete(task2.getId());

  // and expanding again
  runtimeService.createProcessInstanceModification(processInstance.getId())
    .startBeforeActivity("task2")
    .execute();

  // then the variable is again assigned to task1's concurrent execution
  Task task1 = taskService.createTaskQuery().taskDefinitionKey("task1").singleResult();
  VariableInstance variable = runtimeService.createVariableInstanceQuery().singleResult();

  assertEquals(task1.getExecutionId(), variable.getExecutionId());
}
 
Example #8
Source File: ProcessInstanceSnapshot.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected VariableInstance getSingleVariable(Condition<VariableInstance> condition) {
  List<VariableInstance> matchingVariables = new ArrayList<VariableInstance>();

  for (VariableInstance variable : variables.values()) {
    if (condition.matches(variable)) {
      matchingVariables.add(variable);
    }
  }

  if (matchingVariables.size() == 1) {
    return  matchingVariables.get(0);
  }
  else if (matchingVariables.size() == 0) {
    return null;
  }
  else {
    throw new RuntimeException("There is more than one variable that matches the given condition");
  }
}
 
Example #9
Source File: RestartProcessInstanceSyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotSetInitialVersionOfLocalVariables() {
  // given
  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.SUBPROCESS_PROCESS);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process", Variables.createVariables().putValue("var", "bar"));

  Execution subProcess = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("userTask").singleResult();
  runtimeService.setVariableLocal(subProcess.getId(), "local", "foo");

  runtimeService.deleteProcessInstance(processInstance.getId(), "test");

  // when
  runtimeService.restartProcessInstances(processDefinition.getId())
    .startBeforeActivity("userTask")
    .processInstanceIds(processInstance.getId())
    .initialSetOfVariables()
    .execute();

  // then
  ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult();
  List<VariableInstance> variables = runtimeService.createVariableInstanceQuery().processInstanceIdIn(restartedProcessInstance.getId()).list();
  assertEquals(1, variables.size());
  assertEquals("var", variables.get(0).getName());
  assertEquals("bar", variables.get(0).getValue());
}
 
Example #10
Source File: RestartProcessInstanceSyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotSetLocalVariables() {
  // given
  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.SUBPROCESS_PROCESS);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");

  Execution subProcess = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId())
      .activityId("userTask").singleResult();
  runtimeService.setVariableLocal(subProcess.getId(), "local", "foo");
  runtimeService.setVariable(processInstance.getId(), "var", "bar");

  runtimeService.deleteProcessInstance(processInstance.getId(), "test");

  // when
  runtimeService.restartProcessInstances(processDefinition.getId())
  .startBeforeActivity("userTask")
  .processInstanceIds(processInstance.getId())
  .execute();

  // then
  ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).active().singleResult();
  List<VariableInstance> variables = runtimeService.createVariableInstanceQuery().processInstanceIdIn(restartedProcessInstance.getId()).list();
  assertEquals(1, variables.size());
  assertEquals("var", variables.get(0).getName());
  assertEquals("bar", variables.get(0).getValue());
}
 
Example #11
Source File: InputOutputTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCompositeExpressionForOutputValue() {

    // given
    BpmnModelInstance instance = Bpmn.createExecutableProcess("Process")
      .startEvent()
      .serviceTask()
        .camundaExpression("${true}")
        .camundaInputParameter("var1", "World!")
        .camundaOutputParameter("var2", "Hello ${var1}")
      .userTask()
      .endEvent("end")
      .done();

    deployment(instance);
    runtimeService.startProcessInstanceByKey("Process");

    // when
    VariableInstance variableInstance = runtimeService
      .createVariableInstanceQuery()
      .variableName("var2")
      .singleResult();

    // then
    assertEquals("Hello World!", variableInstance.getValue());
  }
 
Example #12
Source File: VariableInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"})
public void testQueryByProcessInstanceIdWithoutAnyResult() {
  // given
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("stringVar", "test");
  runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
  runtimeService.startProcessInstanceByKey("oneTaskProcess");

  // when
  VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().processInstanceIdIn("aProcessInstanceId");

  // then
  List<VariableInstance> result = query.list();
  assertTrue(result.isEmpty());

  assertEquals(0, query.count());
}
 
Example #13
Source File: HalVariableValue.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static HalVariableValue generateVariableValue(VariableInstance variableInstance, String variableScopeId) {
  if (variableScopeId.equals(variableInstance.getTaskId())) {
    return generateTaskVariableValue(variableInstance, variableScopeId);
  }
  else if (variableScopeId.equals(variableInstance.getProcessInstanceId())) {
    return generateProcessInstanceVariableValue(variableInstance, variableScopeId);
  }
  else if (variableScopeId.equals(variableInstance.getExecutionId())) {
    return generateExecutionVariableValue(variableInstance, variableScopeId);
  }
  else if (variableScopeId.equals(variableInstance.getCaseInstanceId())) {
    return generateCaseInstanceVariableValue(variableInstance, variableScopeId);
  }
  else if (variableScopeId.equals(variableInstance.getCaseExecutionId())) {
    return generateCaseExecutionVariableValue(variableInstance, variableScopeId);
  }
  else {
    throw new RestException("Variable scope id '" + variableScopeId + "' does not match with variable instance '" + variableInstance + "'");
  }
}
 
Example #14
Source File: RestartProcessInstanceSyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotSetInitialVariablesIfThereIsNoUniqueStartActivity() {
  // given
  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(ProcessModels.TWO_TASKS_PROCESS);

  ProcessInstance processInstance = runtimeService.createProcessInstanceById(processDefinition.getId())
      .startBeforeActivity("userTask1")
      .startBeforeActivity("userTask2")
      .setVariable("foo", "bar")
      .execute();

  runtimeService.deleteProcessInstance(processInstance.getId(), "test");

  // when
  runtimeService.restartProcessInstances(processDefinition.getId())
  .startBeforeActivity("userTask1")
  .initialSetOfVariables()
  .processInstanceIds(processInstance.getId())
  .execute();

  // then
  ProcessInstance restartedProcessInstance = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition.getId()).singleResult();
  List<VariableInstance> variables = runtimeService.createVariableInstanceQuery().processInstanceIdIn(restartedProcessInstance.getId()).list();
  assertEquals(0, variables.size());
}
 
Example #15
Source File: MockVariableInstanceBuilder.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected <T extends VariableInstance> T build(T mockVariable) {
  when(mockVariable.getId()).thenReturn(id);
  when(mockVariable.getName()).thenReturn(name);
  when(mockVariable.getTypeName()).thenReturn(typedValue.getType().getName());

  if (ObjectValue.class.isAssignableFrom(typedValue.getClass())) {
    ObjectValue objectValue = (ObjectValue) typedValue;
    if (objectValue.isDeserialized()) {
      when(mockVariable.getValue()).thenReturn(typedValue.getValue());
    } else {
      when(mockVariable.getValue()).thenReturn(null);
    }
  } else {
    when(mockVariable.getValue()).thenReturn(typedValue.getValue());
  }

  when(mockVariable.getTypedValue()).thenReturn(typedValue);
  when(mockVariable.getProcessDefinitionId()).thenReturn(processDefinitionId);
  when(mockVariable.getProcessInstanceId()).thenReturn(processInstanceId);
  when(mockVariable.getExecutionId()).thenReturn(executionId);
  when(mockVariable.getCaseInstanceId()).thenReturn(caseInstanceId);
  when(mockVariable.getCaseExecutionId()).thenReturn(caseExecutionId);
  when(mockVariable.getTaskId()).thenReturn(taskId);
  when(mockVariable.getActivityInstanceId()).thenReturn(activityInstanceId);
  when(mockVariable.getTenantId()).thenReturn(tenantId);
  when(mockVariable.getErrorMessage()).thenReturn(errorMessage);

  return mockVariable;
}
 
Example #16
Source File: VariableInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"})
public void testQueryByProcessInstanceId() {
  // given
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("stringVar", "test");
  variables.put("myVar", "test123");
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);

  // when
  VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstance.getId());

  // then
  List<VariableInstance> result = query.list();
  assertFalse(result.isEmpty());
  assertEquals(2, result.size());

  assertEquals(2, query.count());

  for (VariableInstance var : result) {
    assertEquals("string", var.getTypeName());
    if (var.getName().equals("myVar")) {
      assertEquals("myVar", var.getName());
      assertEquals("test123", var.getValue());
    } else if (var.getName().equals("stringVar")) {
      assertEquals("stringVar", var.getName());
      assertEquals("test", var.getValue());
    } else {
      fail("An unexpected variable '" + var.getName() + "' was found with value " + var.getValue());
    }
  }
}
 
Example #17
Source File: VariableInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn"})
public void testQueryByCaseExecutionIds() {
  CaseInstance instance1 = caseService
    .withCaseDefinitionByKey("oneTaskCase")
    .setVariable("aVariableName", "abc")
    .create();

  CaseInstance instance2 = caseService
      .withCaseDefinitionByKey("oneTaskCase")
      .setVariable("anotherVariableName", "xyz")
      .create();

  VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();

  query
    .caseExecutionIdIn(instance1.getId(), instance2.getId())
    .orderByVariableName()
    .asc();

  List<VariableInstance> result = query.list();

  assertEquals(2, result.size());

  for (VariableInstance variableInstance : result) {
    if (variableInstance.getName().equals("aVariableName")) {
      assertEquals("aVariableName", variableInstance.getName());
      assertEquals("abc", variableInstance.getValue());
    } else if (variableInstance.getName().equals("anotherVariableName")) {
      assertEquals("anotherVariableName", variableInstance.getName());
      assertEquals("xyz", variableInstance.getValue());
    } else {
      fail("Unexpected variable: " + variableInstance.getName());
    }

  }
}
 
Example #18
Source File: TaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowBpmnErrorCatchInEventSubprocess() {
  // given
  String errorCodeVariableName = "errorCodeVar";
  String errorMessageVariableName = "errorMessageVar";
  BpmnModelInstance model = createUserTaskProcessWithEventSubprocess(errorCodeVariableName, errorMessageVariableName);
  testRule.deploy(model);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY);
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals(USER_TASK_THROW_ERROR, task.getTaskDefinitionKey());
  String variableName = "foo";
  String variableValue = "bar";
  String errorMessageValue = "Error message for ERROR-" + ERROR_CODE;

  // when
  taskService.handleBpmnError(task.getId(), ERROR_CODE, errorMessageValue, Variables.createVariables().putValue(variableName, variableValue));

  // then
  Task taskAfterThrow = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals(USER_TASK_AFTER_CATCH, taskAfterThrow.getTaskDefinitionKey());
  VariableInstance variablePassedDuringThrowError = runtimeService.createVariableInstanceQuery().variableName(variableName).singleResult();
  assertEquals(variableValue, variablePassedDuringThrowError.getValue());
  VariableInstance errorMessageVariable = runtimeService.createVariableInstanceQuery().variableName(errorMessageVariableName).singleResult();
  assertEquals(errorMessageValue, errorMessageVariable.getValue());
  VariableInstance errorCodeVariable = runtimeService.createVariableInstanceQuery().variableName(errorCodeVariableName).singleResult();
  assertEquals(ERROR_CODE, errorCodeVariable.getValue());
}
 
Example #19
Source File: VariableInstanceRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSingleVariableInstanceDeserialized() {
  ObjectValue serializedValue = MockObjectValue.fromObjectValue(
      Variables.objectValue("a value").serializationDataFormat("aDataFormat").create())
      .objectTypeName("aTypeName");

  MockVariableInstanceBuilder builder = MockProvider.mockVariableInstance().typedValue(serializedValue);
  VariableInstance variableInstanceMock = builder.build();

  when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.disableBinaryFetching()).thenReturn(variableInstanceQueryMock);
  when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);

  given()
    .pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID)
  .then().expect().statusCode(Status.OK.getStatusCode())
  .and()
    .body("id", equalTo(builder.getId()))
    .body("name", equalTo(builder.getName()))
    .body("type", equalTo(VariableTypeHelper.toExpectedValueTypeName(builder.getTypedValue().getType())))
    .body("value", equalTo("a value"))
    .body("valueInfo.serializationDataFormat", equalTo("aDataFormat"))
    .body("valueInfo.objectTypeName", equalTo("aTypeName"))
    .body("processInstanceId", equalTo(builder.getProcessInstanceId()))
    .body("executionId", equalTo(builder.getExecutionId()))
    .body("caseInstanceId", equalTo(builder.getCaseInstanceId()))
    .body("caseExecutionId", equalTo(builder.getCaseExecutionId()))
    .body("taskId", equalTo(builder.getTaskId()))
    .body("activityInstanceId", equalTo(builder.getActivityInstanceId()))
    .body("tenantId", equalTo(builder.getTenantId()))
    .body("errorMessage", equalTo(builder.getErrorMessage()))
  .when().get(VARIABLE_INSTANCE_URL);

  verify(variableInstanceQueryMock, times(1)).disableBinaryFetching();
  verify(variableInstanceQueryMock, never()).disableCustomObjectDeserialization();
}
 
Example #20
Source File: InputOutputTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testOutputScriptValue() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess");

  VariableInstance variable = runtimeService.createVariableInstanceQuery().variableName("var1").singleResult();
  assertNotNull(variable);
  assertEquals(2, variable.getValue());
  assertEquals(pi.getId(), variable.getExecutionId());
}
 
Example #21
Source File: ModificationExecutionAsyncTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testIoMappingInvocation() {
  // given
  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(modify(instance)
    .activityBuilder("user1")
    .camundaInputParameter("foo", "bar")
    .done()
  );

  ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());

  Batch batch = runtimeService
    .createModification(processDefinition.getId())
    .startAfterActivity("user2")
    .processInstanceIds(Arrays.asList(processInstance.getId()))
    .executeAsync();

  helper.completeSeedJobs(batch);

  // when
  helper.executeJobs(batch);

  // then
  VariableInstance inputVariable = runtimeService.createVariableInstanceQuery().singleResult();
  Assert.assertNotNull(inputVariable);
  assertEquals("foo", inputVariable.getName());
  assertEquals("bar", inputVariable.getValue());

  ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId());
  assertEquals(activityInstance.getActivityInstances("user1")[0].getId(), inputVariable.getActivityInstanceId());
}
 
Example #22
Source File: ExecutionVariablesTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testTreeCompactionNestedForkParallelGateway() {
  // given
  runtimeService.startProcessInstanceByKey("process");

  Task task1 = taskService
      .createTaskQuery()
      .taskDefinitionKey("task1")
      .singleResult();

  Execution task2Execution = runtimeService
      .createExecutionQuery()
      .activityId("task2")
      .singleResult();
  String subProcessScopeExecutionId = ((ExecutionEntity) task2Execution).getParentId();

  // when
  runtimeService.setVariableLocal(task2Execution.getId(), "foo", "bar");
  // and completing the other task, thereby pruning the concurrent execution
  taskService.complete(task1.getId());

  // then the variable still exists on the subprocess scope execution
  VariableInstance variable = runtimeService.createVariableInstanceQuery().singleResult();
  assertNotNull(variable);
  assertEquals("foo", variable.getName());
  assertEquals(subProcessScopeExecutionId, variable.getExecutionId());
}
 
Example #23
Source File: VariableInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn"})
public void testQueryByCaseActivityInstanceIds() {
  CaseInstance instance1 = caseService
    .withCaseDefinitionByKey("oneTaskCase")
    .setVariable("aVariableName", "abc")
    .create();

  CaseInstance instance2 = caseService
      .withCaseDefinitionByKey("oneTaskCase")
      .setVariable("anotherVariableName", "xyz")
      .create();

  VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();

  query
    // activityInstanceId == caseExecutionId
    .activityInstanceIdIn(instance1.getId(), instance2.getId())
    .orderByVariableName()
    .asc();

  List<VariableInstance> result = query.list();

  assertEquals(2, result.size());

  for (VariableInstance variableInstance : result) {
    if (variableInstance.getName().equals("aVariableName")) {
      assertEquals("aVariableName", variableInstance.getName());
      assertEquals("abc", variableInstance.getValue());
    } else if (variableInstance.getName().equals("anotherVariableName")) {
      assertEquals("anotherVariableName", variableInstance.getName());
      assertEquals("xyz", variableInstance.getValue());
    } else {
      fail("Unexpected variable: " + variableInstance.getName());
    }

  }
}
 
Example #24
Source File: VariableInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"})
public void testQuery() {
  // given
  Map<String, Object> variables1 = new HashMap<String, Object>();
  variables1.put("intVar", 123);
  runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);

  Map<String, Object> variables2 = new HashMap<String, Object>();
  variables2.put("stringVar", "test");
  runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);

  // when
  VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();

  // then
  assertNotNull(query);

  List<VariableInstance> result = query.list();
  assertFalse(result.isEmpty());
  assertEquals(2, result.size());

  assertEquals(2, query.count());

  for (VariableInstance var : result) {
    assertNotNull(var.getId());
    if (var.getName().equals("intVar")) {
      assertEquals("intVar", var.getName());
      assertEquals(123, var.getValue());
    } else if (var.getName().equals("stringVar")) {
      assertEquals("stringVar", var.getName());
      assertEquals("test", var.getValue());
    } else {
      fail("An unexpected variable '" + var.getName() + "' was found with value " + var.getValue());
    }

  }
}
 
Example #25
Source File: VariableInstanceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"})
public void testQueryByNameAndVariableLessThanAndEqual_Long() {
  // given
  Map<String, Object> variables1 = new HashMap<String, Object>();
  variables1.put("longValue", 123456L);
  runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1);

  Map<String, Object> variables2 = new HashMap<String, Object>();
  variables2.put("longValue", 987654L);
  runtimeService.startProcessInstanceByKey("oneTaskProcess", variables2);

  Map<String, Object> variables3 = new HashMap<String, Object>();
  variables3.put("longValue", 555555L);
  runtimeService.startProcessInstanceByKey("oneTaskProcess", variables3);

  // when
  VariableInstanceQuery query = runtimeService.createVariableInstanceQuery().variableValueLessThanOrEqual("longValue", 987654L);

  // then
  List<VariableInstance> result = query.list();
  assertFalse(result.isEmpty());
  assertEquals(3, result.size());

  assertEquals(3, query.count());

  for (VariableInstance var : result) {
    assertEquals("longValue", var.getName());
    assertEquals("long", var.getTypeName());
    if (var.getValue().equals(123456L)) {
      assertEquals(123456L, var.getValue());
    } else if (var.getValue().equals(555555L)) {
      assertEquals(555555L, var.getValue());
    } else if (var.getValue().equals(987654L)) {
      assertEquals(987654L, var.getValue());
    } else {
      fail("A non expected value occured: " + var.getValue());
    }
  }
}
 
Example #26
Source File: InputOutputTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testInputMapElKey() {
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("varExpr1", "a");
  variables.put("varExpr2", "b");
  runtimeService.startProcessInstanceByKey("testProcess", variables);

  VariableInstance variable = runtimeService.createVariableInstanceQuery().variableName("var1").singleResult();
  assertNotNull(variable);
  TreeMap<String, Object> value = (TreeMap) variable.getValue();
  assertEquals("potato", value.get("a"));
  assertEquals("tomato", value.get("b"));
}
 
Example #27
Source File: MigrationVariablesTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testVariableAtTaskAndConcurrentExecutionAddParentScope() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.PARALLEL_GATEWAY_PROCESS);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.PARALLEL_GATEWAY_SUBPROCESS_PROCESS);

  MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapActivities("userTask1", "userTask1")
    .mapActivities("userTask2", "userTask2")
    .build();

  ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcessDefinition.getId());

  Task task = taskService.createTaskQuery().taskDefinitionKey("userTask1").singleResult();
  taskService.setVariableLocal(task.getId(), "foo", 42);
  runtimeService.setVariableLocal(task.getExecutionId(), "foo", 52);

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then
  VariableInstance taskVarBeforeMigration = testHelper.snapshotBeforeMigration.getSingleTaskVariable(task.getId(), "foo");

  ExecutionTree userTask1ExecutionAfter  = testHelper.snapshotAfterMigration.getExecutionTree()
      .getLeafExecutions("userTask1")
      .get(0);

  Assert.assertEquals(2, testHelper.snapshotAfterMigration.getVariables().size());
  testHelper.assertVariableMigratedToExecution(taskVarBeforeMigration, userTask1ExecutionAfter.getId());
}
 
Example #28
Source File: ProcessTaskTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {
    "org/camunda/bpm/engine/test/cmmn/processtask/ProcessTaskTest.testInputAllLocal.cmmn",
    "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"
  })
public void testInputAllLocal() {
  // given
  createCaseInstanceByKey(ONE_PROCESS_TASK_CASE).getId();
  String caseTaskId = queryCaseExecutionByActivityId(PROCESS_TASK).getId();

  // when
  caseService
    .withCaseExecution(caseTaskId)
    .setVariable("aVariable", "abc")
    .setVariableLocal("aLocalVariable", "def")
    .manualStart();

  // then only the local variable is mapped to the sub process instance
  ProcessInstance subProcessInstance = queryProcessInstance();

  List<VariableInstance> variables = runtimeService
      .createVariableInstanceQuery()
      .processInstanceIdIn(subProcessInstance.getId())
      .list();

  assertEquals(1, variables.size());
  assertEquals("aLocalVariable", variables.get(0).getName());
}
 
Example #29
Source File: VariableInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testProcessVariableQueryWithReadInstancesPermissionOnOneTaskProcess() {
  // given
  String processInstanceId = startProcessInstanceByKey(PROCESS_KEY, getVariables()).getId();
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_INSTANCE);

  // when
  VariableInstanceQuery query = runtimeService.createVariableInstanceQuery();

  // then
  verifyQueryResults(query, 1);

  VariableInstance variable = query.singleResult();
  assertNotNull(variable);
  assertEquals(processInstanceId, variable.getProcessInstanceId());
}
 
Example #30
Source File: DelegationAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testScriptConditionExecutesQueryAfterUserCompletesTask() {
  // given
  startProcessInstancesByKey(DEFAULT_PROCESS_KEY, 5);
  Task task = selectAnyTask();

  String taskId = task.getId();
  String processInstanceId = task.getProcessInstanceId();

  createGrantAuthorization(TASK, taskId, userId, UPDATE);

  // when
  taskService.complete(taskId);

  // then
  disableAuthorization();

  VariableInstanceQuery query = runtimeService
      .createVariableInstanceQuery()
      .processInstanceIdIn(processInstanceId);

  VariableInstance variableUser = query
      .variableName("userId")
      .singleResult();
  assertNotNull(variableUser);
  assertEquals(userId, variableUser.getValue());

  VariableInstance variableCount = query
      .variableName("count")
      .singleResult();
  assertNotNull(variableCount);
  assertEquals(5l, variableCount.getValue());

  enableAuthorization();
}