org.camunda.bpm.engine.variable.VariableMap Java Examples

The following examples show how to use org.camunda.bpm.engine.variable.VariableMap. 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: ProcessTaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetVariablesTyped() {
  // given
  runtimeService.startProcessInstanceByKey(PROCESS_KEY, getVariables());
  String taskId = taskService.createTaskQuery().singleResult().getId();

  // when
  authRule
      .init(scenario)
      .withUser("userId")
      .bindResource("taskId", taskId)
      .start();

  VariableMap variables = taskService.getVariablesTyped(taskId);

  // then
  if (authRule.assertScenario(scenario)) {
    verifyGetVariables(variables);
  }
}
 
Example #2
Source File: PurgeDatabaseTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testPurgeWithExistingProcessInstance() {
  //given process with variable and staying process instance in second user task
  BpmnModelInstance test = Bpmn.createExecutableProcess(PROCESS_DEF_KEY)
                               .startEvent()
                               .userTask()
                               .userTask()
                               .endEvent()
                               .done();
  engineRule.getRepositoryService().createDeployment().addModelInstance(PROCESS_MODEL_NAME, test).deploy();

  VariableMap variables = Variables.createVariables();
  variables.put("key", "value");
  engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEF_KEY, variables);
  Task task = engineRule.getTaskService().createTaskQuery().singleResult();
  engineRule.getTaskService().complete(task.getId());

  // when purge is executed
  ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
  managementService.purge();

  // then no more data exist
  assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
}
 
Example #3
Source File: StandaloneTaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetVariablesLocalTypedByName() {
  createTask(taskId);

  taskService.setVariablesLocal(taskId, getVariables());

  // when
  authRule
      .init(scenario)
      .withUser("userId")
      .bindResource("taskId", taskId)
      .start();

  VariableMap variables = taskService.getVariablesLocalTyped(taskId, Arrays.asList(VARIABLE_NAME), false);

  // then
  if (authRule.assertScenario(scenario)) {
    verifyGetVariables(variables);
  }
}
 
Example #4
Source File: FeelEngineIT.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected VariableMap createSpinParsedVariableInMap(String serializationType) {
  if ("json".equalsIgnoreCase(serializationType)) {
    JsonListSerializable<String> jsonList = new JsonListSerializable<>();
    jsonList.setListProperty(TEST_LIST);
    return Variables.createVariables()
                    .putValue("inputVar", Spin.JSON(jsonList.toExpectedJsonString()));

  } else if ("xml".equalsIgnoreCase(serializationType)) {
    XmlListSerializable<String> xmlList = new XmlListSerializable<>();
    xmlList.setListProperty(TEST_LIST);
    return Variables.createVariables()
                    .putValue("inputVar", Spin.XML(xmlList.toExpectedXmlString()));

  } else {
    return Variables.createVariables();

  }
}
 
Example #5
Source File: MultiTenancyExecutionPropagationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testPropagateTenantIdToVariableInstanceOnStartProcessInstance() {

    deploymentForTenant(TENANT_ID, Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY)
        .startEvent()
        .userTask()
        .endEvent()
      .done());

    VariableMap variables = Variables.putValue("var", "test");

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceById(processDefinition.getId(), variables);

    VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
    assertThat(variableInstance, is(notNullValue()));
    // inherit the tenant id from process instance
    assertThat(variableInstance.getTenantId(), is(TENANT_ID));
  }
 
Example #6
Source File: ProcessInstantiationWithVariablesInReturnTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void checkVariables(VariableMap map, int expectedSize) {
  List<HistoricVariableInstance> variables = engineRule.getHistoryService()
          .createHistoricVariableInstanceQuery()
          .orderByVariableName()
          .asc()
          .list();

  assertEquals(expectedSize, variables.size());

  assertEquals(variables.size(), map.size());
  for (HistoricVariableInstance instance : variables) {
    assertTrue(map.containsKey(instance.getName()));
    Object instanceValue = instance.getTypedValue().getValue();
    Object mapValue = map.getValueTyped(instance.getName()).getValue();
    if (instanceValue == null) {
      assertNull(mapValue);
    } else if (instanceValue instanceof byte[]) {
      assertTrue(Arrays.equals((byte[]) instanceValue, (byte[]) mapValue));
    } else {
      assertEquals(instanceValue, mapValue);
    }
  }
}
 
Example #7
Source File: JsonValueTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = ONE_TASK_PROCESS)
public void testGetTypedJsonValue() throws JSONException {
  // given
  JsonValue jsonValue = jsonValue(jsonString).create();
  VariableMap variables = Variables.createVariables().putValueTyped(variableName, jsonValue);

  String processInstanceId = runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();

  // when
  JsonValue typedValue = runtimeService.getVariableTyped(processInstanceId, variableName);

  // then
  SpinJsonNode value = typedValue.getValue();
  JSONAssert.assertEquals(jsonString, value.toString(), true);

  assertTrue(typedValue.isDeserialized());
  assertEquals(JSON, typedValue.getType());
  assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
  JSONAssert.assertEquals(jsonString, typedValue.getValueSerialized(), true);
}
 
Example #8
Source File: MultiInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment( resources = {
  "org/camunda/bpm/engine/test/bpmn/multiinstance/MultiInstanceTest.testCatchErrorThrownBySequentialDelegateExpression.bpmn20.xml"
})
public void testCatchExceptionThrownByExecuteOfSequentialDelegateExpression() {
  VariableMap variables = Variables.createVariables().putValue("myDelegate", new ThrowErrorDelegate());
  variables.putAll(throwException());
  String pi = runtimeService.startProcessInstanceByKey("testProcess", variables).getId();

  assertTrue((Boolean) runtimeService.getVariable(pi, "executed"));
  assertNull(runtimeService.getVariable(pi, "signaled"));

  Task userTask = taskService.createTaskQuery().processInstanceId(pi).singleResult();
  assertNotNull(userTask);
  assertEquals("userTaskException", userTask.getTaskDefinitionKey());

  taskService.complete(userTask.getId());
}
 
Example #9
Source File: DefaultDmnDecisionContext.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected VariableMap buildVariableMapFromVariableContext(VariableContext variableContext) {

    VariableMap variableMap = Variables.createVariables();

    Set<String> variables = variableContext.keySet();
    for(String variable: variables) {
      variableMap.put(variable, variableContext.resolve(variable));
    }

    return variableMap;
  }
 
Example #10
Source File: RuntimeServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
@Test
public void testGetVariableInstancesFromVariableScope() {

  VariableMap variables = createVariables()
    .putValue("anIntegerVariable", 1234)
    .putValue("anObjectValue", objectValue(new SimpleSerializableBean(10)).serializationDataFormat(Variables.SerializationDataFormats.JAVA))
    .putValue("anUntypedObjectValue", new SimpleSerializableBean(30));

  runtimeService.startProcessInstanceByKey("testProcess", variables);

  // assertions are part of the java delegate AssertVariableInstancesDelegate
  // only there we can access the VariableScope methods
}
 
Example #11
Source File: ProcessOrCaseTaskActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void performStart(CmmnActivityExecution execution) {
  VariableMap variables = getInputVariables(execution);
  String businessKey = getBusinessKey(execution);
  triggerCallableElement(execution, variables, businessKey);

  if (execution.isActive() && !isBlocking(execution)) {
    execution.complete();
  }
}
 
Example #12
Source File: FluentExecutionListenerMock.java    From camunda-bpm-mockito with Apache License 2.0 5 votes vote down vote up
@Override
public void onExecutionSetVariables(final VariableMap variables) {
  doAnswer(new ExecutionListener() {

    @Override
    public void notify(final DelegateExecution execution) throws Exception {
      setVariables(execution, variables);
    }
  });
}
 
Example #13
Source File: FluentJavaDelegateMock.java    From camunda-bpm-mockito with Apache License 2.0 5 votes vote down vote up
@Override
public void onExecutionSetVariables(final VariableMap variables) {
  doAnswer(new JavaDelegate() {

    @Override
    public void execute(final DelegateExecution execution) throws Exception {
      setVariables(execution, variables);
    }
  });
}
 
Example #14
Source File: ProcessInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testGetVariablesLocalTypedByNameWithReadInstanceVariablePermissionOnAnyProcessDefinition() {
  // given
  setReadVariableAsDefaultReadVariablePermission();
  String processInstanceId = startProcessInstanceByKey(PROCESS_KEY, getVariables()).getId();
  createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE_VARIABLE);

  // when
  VariableMap variables = runtimeService.getVariablesLocalTyped(processInstanceId, Arrays.asList(VARIABLE_NAME), false);

  // then
  verifyGetVariables(variables);
}
 
Example #15
Source File: JavaSerializationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransientObjectValue() throws IOException {
  // given
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("foo")
      .startEvent()
      .exclusiveGateway("gtw")
        .sequenceFlowId("flow1")
        .condition("cond", "${x.property == \"bar\"}")
        .userTask("userTask1")
        .endEvent()
      .moveToLastGateway()
        .sequenceFlowId("flow2")
        .userTask("userTask2")
        .endEvent()
      .done();

  testRule.deploy(modelInstance);

  JavaSerializable bean = new JavaSerializable("bar");
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  new ObjectOutputStream(baos).writeObject(bean);
  String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
  ObjectValue javaValue = serializedObjectValue(serializedObject, true)
      .serializationDataFormat(Variables.SerializationDataFormats.JAVA)
      .objectTypeName(JavaSerializable.class.getName())
      .create();
  VariableMap variables = Variables.createVariables().putValueTyped("x", javaValue);

  // when
  runtimeService.startProcessInstanceByKey("foo", variables);

  // then
  List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list();
  assertEquals(0, variableInstances.size());

  Task task = taskService.createTaskQuery().singleResult();
  assertNotNull(task);
  assertEquals("userTask1", task.getTaskDefinitionKey());
}
 
Example #16
Source File: ProcessInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testGetVariablesTypedByNameWithReadInstanceVariablePermissionOnAnyProcessDefinition() {
  // given
  setReadVariableAsDefaultReadVariablePermission();
  String processInstanceId = startProcessInstanceByKey(PROCESS_KEY, getVariables()).getId();
  createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_INSTANCE_VARIABLE);

  // when
  VariableMap variables = runtimeService.getVariablesTyped(processInstanceId, Arrays.asList(VARIABLE_NAME), false);

  // then
  verifyGetVariables(variables);
}
 
Example #17
Source File: AbstractVariableScope.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void setVariables(Map<String, ? extends Object> variables) {
  if (variables!=null) {
    for (String variableName : variables.keySet()) {
      Object value = null;
      if (variables instanceof VariableMap) {
        value = ((VariableMap) variables).getValueTyped(variableName);
      }
      else {
        value = variables.get(variableName);
      }
      setVariable(variableName, value);
    }
  }
}
 
Example #18
Source File: FormAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testStandaloneTaskGetTaskFormVariablesWithReadVariablePermission() {
  // given
  setReadVariableAsDefaultReadVariablePermission();
  String taskId = "myTask";
  createTask(taskId);
  createGrantAuthorization(TASK, taskId, userId, READ_VARIABLE);

  // when
  VariableMap variables = formService.getTaskFormVariables(taskId);

  // then
  assertNotNull(variables);

  deleteTask(taskId, true);
}
 
Example #19
Source File: HistoricDecisionInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { DECISION_SINGLE_OUTPUT_DMN })
public void testDecisionEvaluatedWithAuthenticatedUser() {
  identityService.setAuthenticatedUserId("demo");
  VariableMap variables = Variables.putValue("input1", "test");
  decisionService.evaluateDecisionTableByKey(DECISION_DEFINITION_KEY, variables);

  HistoricDecisionInstance historicDecisionInstance = historyService.createHistoricDecisionInstanceQuery().singleResult();

  assertThat(historicDecisionInstance, is(notNullValue()));
  // the user should be set since the decision was evaluated with the decision service
  assertThat(historicDecisionInstance.getUserId(), is("demo"));
}
 
Example #20
Source File: CaseServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn"})
public void testGetVariablesTyped() {
  // given:
  // a deployed case definition
  String caseDefinitionId = repositoryService
      .createCaseDefinitionQuery()
      .singleResult()
      .getId();

  // an active case instance
   caseService
      .withCaseDefinition(caseDefinitionId)
      .setVariable("aVariableName", "abc")
      .setVariable("anotherVariableName", 999)
      .create()
      .getId();

   String caseExecutionId = caseService
       .createCaseExecutionQuery()
       .activityId("PI_HumanTask_1")
       .singleResult()
       .getId();

   // when
   VariableMap variables = caseService.getVariablesTyped(caseExecutionId);

   // then
   assertNotNull(variables);
   assertFalse(variables.isEmpty());
   assertEquals(2, variables.size());

   assertEquals("abc", variables.get("aVariableName"));
   assertEquals(999, variables.get("anotherVariableName"));

   assertEquals(variables, caseService.getVariablesTyped(caseExecutionId, true));
}
 
Example #21
Source File: ProcessVariableLocalTypedTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/annotation/CompleteTaskTest.bpmn20.xml")
public void testProcessVariableLocalTypeAnnotation() {
  BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);

  VariableMap variables = Variables.createVariables().putValue("injectedLocalValue", "camunda");
  businessProcess.startProcessByKey("keyOfTheProcess", variables);

  TypedValue value = getBeanInstance(DeclarativeProcessController.class).getInjectedLocalValue();
  assertNotNull(value);
  assertTrue(value instanceof StringValue);
  assertEquals(ValueType.STRING, value.getType());
  assertEquals("camunda", value.getValue());
}
 
Example #22
Source File: ProcessDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void setUpRuntimeDataForDefinition(ProcessDefinition mockDefinition) {
  mockInstance = MockProvider.createMockInstanceWithVariables();

  // we replace this mock with every test in order to have a clean one (in terms of invocations) for verification
  runtimeServiceMock = mock(RuntimeService.class);
  when(processEngine.getRuntimeService()).thenReturn(runtimeServiceMock);
  when(runtimeServiceMock.startProcessInstanceById(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID), Matchers.<Map<String, Object>>any())).thenReturn(mockInstance);
  when(runtimeServiceMock.startProcessInstanceById(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID), anyString(), anyString(), Matchers.<Map<String, Object>>any())).thenReturn(mockInstance);


  mockInstantiationBuilder = setUpMockInstantiationBuilder();
  when(mockInstantiationBuilder.executeWithVariablesInReturn(anyBoolean(), anyBoolean())).thenReturn(mockInstance);
  when(runtimeServiceMock.createProcessInstanceById(anyString())).thenReturn(mockInstantiationBuilder);


  repositoryServiceMock = mock(RepositoryService.class);
  when(processEngine.getRepositoryService()).thenReturn(repositoryServiceMock);
  when(repositoryServiceMock.getProcessDefinition(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))).thenReturn(mockDefinition);
  when(repositoryServiceMock.getProcessModel(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))).thenReturn(createMockProcessDefinionBpmn20Xml());

  DeleteProcessDefinitionsSelectBuilder deleteProcessDefinitionsSelectBuilder = mock(DeleteProcessDefinitionsSelectBuilder.class, RETURNS_DEEP_STUBS);
  when(repositoryServiceMock.deleteProcessDefinitions()).thenReturn(deleteProcessDefinitionsSelectBuilder);

  setUpMockDefinitionQuery(mockDefinition);

  StartFormData formDataMock = MockProvider.createMockStartFormData(mockDefinition);
  formServiceMock = mock(FormService.class);
  when(processEngine.getFormService()).thenReturn(formServiceMock);
  when(formServiceMock.getStartFormData(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))).thenReturn(formDataMock);
  when(formServiceMock.submitStartForm(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID),  Matchers.<Map<String, Object>>any())).thenReturn(mockInstance);
  when(formServiceMock.submitStartForm(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID),  anyString(), Matchers.<Map<String, Object>>any())).thenReturn(mockInstance);

  VariableMap startFormVariablesMock = MockProvider.createMockFormVariables();
  when(formServiceMock.getStartFormVariables(eq(EXAMPLE_PROCESS_DEFINITION_ID), Matchers.<Collection<String>>any(), anyBoolean())).thenReturn(startFormVariablesMock);
}
 
Example #23
Source File: ProcessInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testGetVariablesTypedByNameWithReadInstancePermissionOnProcessDefinition() {
  // given
  String processInstanceId = startProcessInstanceByKey(PROCESS_KEY, getVariables()).getId();
  createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_INSTANCE);

  // when
  VariableMap variables = runtimeService.getVariablesTyped(processInstanceId, Arrays.asList(VARIABLE_NAME), false);

  // then
  assertNotNull(variables);
  assertFalse(variables.isEmpty());
  assertEquals(1, variables.size());

  assertEquals(VARIABLE_VALUE, variables.get(VARIABLE_NAME));
}
 
Example #24
Source File: ModifyVariableInSameTransactionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_AUDIT)
public void testInsertDeleteInsertTheSameVariable() {
  BpmnModelInstance bpmnModel =
      Bpmn.createExecutableProcess("serviceTaskProcess")
      .startEvent()
      .userTask("userTask")
      .serviceTask("service")
        .camundaClass(InsertDeleteInsertVariableDelegate.class)
      .userTask("userTask1")
      .endEvent()
      .done();
  ProcessDefinition processDefinition = testHelper.deployAndGetDefinition(bpmnModel);
  VariableMap variables = Variables.createVariables().putValue("listVar", Arrays.asList(new int[] { 1, 2, 3 }));
  ProcessInstance instance = engineRule.getRuntimeService().startProcessInstanceById(processDefinition.getId(), variables);

  Task task = engineRule.getTaskService().createTaskQuery().singleResult();
  engineRule.getTaskService().complete(task.getId());

  VariableInstance variable = engineRule.getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(instance.getId()).variableName("foo")
      .singleResult();
  assertNotNull(variable);
  assertEquals("bar", variable.getValue());
  List<HistoricVariableInstance> historyVariables = engineRule.getHistoryService().createHistoricVariableInstanceQuery().list();
  for (HistoricVariableInstance historicVariable : historyVariables) {
    if (variable.getName().equals(historicVariable.getName())) {
      assertEquals(HistoricVariableInstance.STATE_CREATED, historicVariable.getState());
      break;
    }
  }
}
 
Example #25
Source File: XmlValueTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = ONE_TASK_PROCESS)
public void testTransientXmlValue() {
  // given
  XmlValue xmlValue = xmlValue(xmlString, true).create();
  VariableMap variables = Variables.createVariables().putValueTyped(variableName, xmlValue);

  // when
  runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS_KEY, variables).getId();

  // then
  List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list();
  assertEquals(0, variableInstances.size());
}
 
Example #26
Source File: FormAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testGetStartFormVariables() {
  // given
  String processDefinitionId = selectProcessDefinitionByKey(RENDERED_FORM_PROCESS_KEY).getId();
  createGrantAuthorization(PROCESS_DEFINITION, RENDERED_FORM_PROCESS_KEY, userId, READ);

  // when
  VariableMap variables = formService.getStartFormVariables(processDefinitionId);

  // then
  assertNotNull(variables);
  assertEquals(1, variables.size());
}
 
Example #27
Source File: ExternalTaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskVariablesTest.testExternalTaskVariablesLocal.bpmn20.xml" })
public void testFetchOnlyLocalVariables() {

  VariableMap globalVars = Variables.putValue("globalVar", "globalVal");

  runtimeService.startProcessInstanceByKey("oneExternalTaskProcess", globalVars);

  final String workerId = "workerId";
  final String topicName = "testTopic";

  List<LockedExternalTask> lockedExternalTasks = externalTaskService.fetchAndLock(10, workerId)
    .topic(topicName, 60000)
    .execute();

  assertEquals(1, lockedExternalTasks.size());

  LockedExternalTask lockedExternalTask = lockedExternalTasks.get(0);
  VariableMap variables = lockedExternalTask.getVariables();
  assertEquals(2, variables.size());
  assertEquals("globalVal", variables.getValue("globalVar", String.class));
  assertEquals("localVal", variables.getValue("localVar", String.class));

  externalTaskService.unlock(lockedExternalTask.getId());

  lockedExternalTasks = externalTaskService.fetchAndLock(10, workerId)
    .topic(topicName, 60000)
    .variables("globalVar", "localVar")
    .localVariables()
    .execute();

  assertEquals(1, lockedExternalTasks.size());

  lockedExternalTask = lockedExternalTasks.get(0);
  variables = lockedExternalTask.getVariables();
  assertEquals(1, variables.size());
  assertEquals("localVal", variables.getValue("localVar", String.class));
}
 
Example #28
Source File: FormAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testProcessTaskGetTaskFormVariablesWithReadVariablePermissionOnTask() {
  // given
  setReadVariableAsDefaultReadVariablePermission();
  startProcessInstanceByKey(RENDERED_FORM_PROCESS_KEY);
  String taskId = selectSingleTask().getId();
  createGrantAuthorization(TASK, taskId, userId, READ_VARIABLE);

  // when
  VariableMap variables = formService.getTaskFormVariables(taskId);

  // then
  assertNotNull(variables);
  assertEquals(1, variables.size());
}
 
Example #29
Source File: TaskRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubmitFormWithVariablesInReturn() {
  VariableMap variables = MockProvider.createMockSerializedVariables();
  when(formServiceMock.submitTaskFormWithVariablesInReturn(EXAMPLE_TASK_ID, null, false)).thenReturn(variables);

  Map<String, Object> queryParameters = new HashMap<>();
  queryParameters.put("withVariablesInReturn", true);

  given()
    .pathParam("id", EXAMPLE_TASK_ID)
    .contentType(POST_JSON_CONTENT_TYPE)
    .body(queryParameters)
    .header("accept", MediaType.APPLICATION_JSON)
  .expect()
    .statusCode(Status.OK.getStatusCode())
    //serialized variable
    .body(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".value",
            equalTo(MockProvider.EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE))
    .body(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".type",
            equalTo("Object"))
    .body(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".valueInfo.objectTypeName",
            equalTo(ArrayList.class.getName()))
    .body(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".valueInfo.serializationDataFormat",
            equalTo(MockProvider.FORMAT_APPLICATION_JSON))
    // deserialized variable should also returned as serialized variable
    .body(MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".value",
            equalTo(MockProvider.EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE))
    .body(MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".type",
            equalTo("Object"))
    .body(MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".valueInfo.objectTypeName",
            equalTo(Object.class.getName()))
    .body(MockProvider.EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME + ".valueInfo.serializationDataFormat",
            equalTo(MockProvider.FORMAT_APPLICATION_JSON))
  .when().post(SUBMIT_FORM_URL);

  verify(formServiceMock).submitTaskFormWithVariablesInReturn(EXAMPLE_TASK_ID, null, false);
}
 
Example #30
Source File: BusinessProcess.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public ProcessInstance startProcessByKey(String key, Map<String, Object> variables) {
  assertCommandContextNotActive();

  VariableMap cachedVariables = getAndClearCachedVariableMap();
  cachedVariables.putAll(variables);
  ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey(key, cachedVariables);
  if (!instance.isEnded()) {
    setExecution(instance);
  }
  return instance;
}