org.camunda.bpm.engine.variable.Variables.putValue()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(14.1k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.camunda.bpm.engine.variable.Variables.putValue()方法的一些代码示例,展示了Variables.putValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Variables.putValue()方法的具体详情如下:
包路径:org.camunda.bpm.engine.variable.Variables
类名称:Variables
方法名:putValue

Variables.putValue介绍

[英]Shortcut for Variables.createVariables().putValue(name, value)
[中]变量的快捷方式。createVariables()。putValue(名称、值)

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

protected void evaluateDecisionWithAuthenticatedUser(String userId) {
 identityService.setAuthenticatedUserId(userId);
 VariableMap variables = Variables.putValue("input1", "test");
 decisionService.evaluateDecisionTableByKey(DECISION_DEFINITION_KEY, variables);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Deployment
public void FAILURE_testMultipleCompensationOfCancellationOfMultipleTx() {
 // when
 List<String> devices = new ArrayList<String>();
  devices.add("device1");
 devices.add("device2");
 devices.add("fail");
 ProcessInstance processInstance = runtimeService.startProcessInstanceByKey( //
    "order", //
    Variables.putValue("devices", devices));
 // then the compensation should be triggered three times
 int expected = 3;
 int actual = historyService
  .createHistoricActivityInstanceQuery()
  .activityId("ServiceTask_CompensateConfiguration")
  .list()
  .size();
 assertEquals(expected, actual);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@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"));
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void testPropagateTenantIdToVariableInstanceOnCreateCaseInstance() {
 deploymentForTenant(TENANT_ID, CMMN_FILE);
 VariableMap variables = Variables.putValue("var", "test");
 CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();
 caseService.createCaseInstanceById(caseDefinition.getId(), variables);
 VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
 assertThat(variableInstance, is(notNullValue()));
 // inherit the tenant id from case instance
 assertThat(variableInstance.getTenantId(), is(TENANT_ID));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Deployment
public void testIfPartOnCaseInstanceCreate() {
 // when
 createCaseInstanceByKey("case", Variables.putValue("value", 101));
 // then
 CaseExecution caseExecution = queryCaseExecutionByActivityId("PI_HumanTask_1");
 assertTrue(caseExecution.isActive());
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Deployment
public void testIfPartOnCaseInstanceCreateWithSentry() {
 // when
 createCaseInstanceByKey("case", Variables.putValue("myVar", 101));
 // then
 CaseExecution caseExecution = queryCaseExecutionByActivityId("PI_HumanTask_1");
 assertTrue(caseExecution.isActive());
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testPurgeDatabase() {
 Assert.assertNotNull(processEngine);
 VariableMap variableMap = Variables.putValue("var", "value");
 runtimeService.startProcessInstanceByKey("testDeployProcessArchive", variableMap);
 runtimeService.startProcessInstanceByKey("testDeployProcessArchive", variableMap);
 ManagementServiceImpl managementServiceImpl = (ManagementServiceImpl) managementService;
 managementServiceImpl.purge();
 assertAndEnsureCleanDb(processEngine);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Deployment(resources = { "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskVariablesTest.testExternalTaskVariablesLocal.bpmn20.xml" })
public void testFetchNonExistingLocalVariables() {
 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)
  .variables("globalVar", "nonExistingLocalVar")
  .localVariables()
  .execute();
 assertEquals(1, lockedExternalTasks.size());
 LockedExternalTask lockedExternalTask = lockedExternalTasks.get(0);
 VariableMap variables = lockedExternalTask.getVariables();
 assertEquals(0, variables.size());
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected String createCaseInstance(String tenantId) {
 VariableMap variables = Variables.putValue(VARIABLE_NAME, VARIABLE_VALUE);
 CaseInstanceBuilder builder = caseService.withCaseDefinitionByKey("twoTaskCase").setVariables(variables);
 if (tenantId == null) {
  return builder.create().getId();
 } else {
  return builder.caseDefinitionTenantId(tenantId).create().getId();
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

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));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@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));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void shouldScheduleToNow() {
 // given
 testRule.deploy(PROCESS);
 ClockUtil.setCurrentTime(END_DATE);
 ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY,
  Variables.putValue("aVariableName", Variables.stringValue("aVariableValue")));
 for (int i = 0; i < 5; i++) {
  runtimeService.setVariable(processInstance.getId(), "aVariableName", Variables.stringValue("anotherVariableValue" + i));
 }
 String taskId = taskService.createTaskQuery().singleResult().getId();
 taskService.complete(taskId);
 engineConfiguration.setHistoryCleanupBatchSize(5);
 engineConfiguration.initHistoryCleanup();
 Date removalTime = addDays(END_DATE, 5);
 ClockUtil.setCurrentTime(removalTime);
 // when
 runHistoryCleanup();
 Job job = historyService.findHistoryCleanupJobs().get(0);
 // then
 assertThat(job.getDuedate(), is(removalTime));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void shouldScheduleToLater() {
 // given
 testRule.deploy(PROCESS);
 ClockUtil.setCurrentTime(END_DATE);
 ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(PROCESS_KEY,
  Variables.putValue("aVariableName", Variables.stringValue("aVariableValue")));
 for (int i = 0; i < 5; i++) {
  runtimeService.setVariable(processInstance.getId(), "aVariableName", Variables.stringValue("anotherVariableValue" + i));
 }
 String taskId = taskService.createTaskQuery().singleResult().getId();
 taskService.complete(taskId);
 engineConfiguration.setHistoryCleanupBatchSize(6);
 engineConfiguration.initHistoryCleanup();
 Date removalTime = addDays(END_DATE, 5);
 ClockUtil.setCurrentTime(removalTime);
 // when
 runHistoryCleanup();
 Job job = historyService.findHistoryCleanupJobs().get(0);
 // then
 assertThat(job.getDuedate(), is(addSeconds(removalTime, START_DELAY)));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn")
public void testQueryByCaseActivityId() {
 // given
 caseService.createCaseInstanceByKey("oneTaskCase", Variables.putValue("foo", "bar"));
 CaseExecution caseExecution = caseService
   .createCaseExecutionQuery()
   .activityId("PI_HumanTask_1")
   .singleResult();
 caseService.setVariableLocal(caseExecution.getId(), "bar", "foo");
 // when
 HistoricVariableInstanceQuery query = historyService
   .createHistoricVariableInstanceQuery()
   .caseActivityIdIn("PI_HumanTask_1");
 // then
 assertEquals(1, query.count());
 assertEquals("bar", query.singleResult().getName());
 assertEquals("foo", query.singleResult().getValue());
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void testAsyncStartEventWithChangedVariable() {
 // given a process definition with asynchronous start event
 deployment(Bpmn.createExecutableProcess("testProcess")
  .startEvent()
  .camundaAsyncBefore()
  .endEvent()
  .done());
 // when create an instance with a variable
 ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess",
  Variables.putValue("var", "foo"));
 // and update this variable before the instance is created
 runtimeService.setVariable(processInstance.getId(), "var", "bar");
 executeAvailableJobs();
 assertProcessEnded(processInstance.getId());
 if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) {
  // then the history contains only one entry for the latest update (value = "bar")
  // - the entry for the initial value (value = "foo") is lost because of current limitations
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
  assertEquals(query.count(), 1);
  HistoricVariableInstance variable = query.singleResult();
  assertEquals(variable.getValue(), "bar");
  assertNotNull(variable.getActivityInstanceId());
 }
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

protected void evaluateDecisionWithAuthenticatedUser(String userId) {
 identityService.setAuthenticatedUserId(userId);
 VariableMap variables = Variables.putValue("input1", "test");
 decisionService.evaluateDecisionTableByKey(DECISION_DEFINITION_KEY, variables);
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void testAsyncStartEventWithAddedVariable() {
 // given a process definition with asynchronous start event
 deployment(Bpmn.createExecutableProcess("testProcess")
  .startEvent()
  .camundaAsyncBefore()
  .endEvent()
  .done());
 // when create an instance with a variable
 ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess",
  Variables.putValue("var1", "foo"));
 // and add a variable before the instance is created
 runtimeService.setVariable(processInstance.getId(), "var2", "bar");
 executeAvailableJobs();
 assertProcessEnded(processInstance.getId());
 if (processEngineConfiguration.getHistoryLevel().getId() > ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) {
  // then the history contains one entry for each variable
  HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery();
  assertEquals(query.count(), 2);
  HistoricVariableInstance firstVariable = query.variableName("var1").singleResult();
  assertNotNull(firstVariable);
  assertEquals(firstVariable.getValue(), "foo");
  assertNotNull(firstVariable.getActivityInstanceId());
  HistoricVariableInstance secondVariable = query.variableName("var2").singleResult();
  assertNotNull(secondVariable);
  assertEquals(secondVariable.getValue(), "bar");
  assertNotNull(secondVariable.getActivityInstanceId());
 }
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

public void testPropagateTenantIdToVariableInstanceOnCreateCaseInstance() {
 deploymentForTenant(TENANT_ID, CMMN_FILE);
 VariableMap variables = Variables.putValue("var", "test");
 CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();
 caseService.createCaseInstanceById(caseDefinition.getId(), variables);
 VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
 assertThat(variableInstance, is(notNullValue()));
 // inherit the tenant id from case instance
 assertThat(variableInstance.getTenantId(), is(TENANT_ID));
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Deployment
public void testIfPartOnCaseInstanceCreateWithSentry() {
 // when
 createCaseInstanceByKey("case", Variables.putValue("myVar", 101));
 // then
 CaseExecution caseExecution = queryCaseExecutionByActivityId("PI_HumanTask_1");
 assertTrue(caseExecution.isActive());
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

@Deployment
public void testIfPartOnCaseInstanceCreate() {
 // when
 createCaseInstanceByKey("case", Variables.putValue("value", 101));
 // then
 CaseExecution caseExecution = queryCaseExecutionByActivityId("PI_HumanTask_1");
 assertTrue(caseExecution.isActive());
}

相关文章