use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.
the class CaseServiceTest method testExecuteSetVariableLocalAndVariablesLocal.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testExecuteSetVariableLocalAndVariablesLocal() {
// given:
// a deployed case definition
String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
// an active case instance
String caseInstanceId = caseService.withCaseDefinition(caseDefinitionId).create().getId();
String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("aVariableName", "abc");
variables.put("anotherVariableName", 999);
// when
caseService.withCaseExecution(caseExecutionId).setVariablesLocal(variables).setVariableLocal("aThirdVariable", 123).execute();
// then
// query by caseExecutionId
List<VariableInstance> result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseExecutionId).list();
assertFalse(result.isEmpty());
assertEquals(3, result.size());
for (VariableInstance variable : result) {
assertEquals(caseExecutionId, variable.getCaseExecutionId());
assertEquals(caseInstanceId, variable.getCaseInstanceId());
if (variable.getName().equals("aVariableName")) {
assertEquals("aVariableName", variable.getName());
assertEquals("abc", variable.getValue());
} else if (variable.getName().equals("anotherVariableName")) {
assertEquals("anotherVariableName", variable.getName());
assertEquals(999, variable.getValue());
} else if (variable.getName().equals("aThirdVariable")) {
assertEquals("aThirdVariable", variable.getName());
assertEquals(123, variable.getValue());
} else {
fail("Unexpected variable: " + variable.getName());
}
}
// query by caseInstanceId
result = runtimeService.createVariableInstanceQuery().caseInstanceIdIn(caseInstanceId).list();
assertFalse(result.isEmpty());
assertEquals(3, result.size());
for (VariableInstance variable : result) {
assertEquals(caseExecutionId, variable.getCaseExecutionId());
assertEquals(caseInstanceId, variable.getCaseInstanceId());
if (variable.getName().equals("aVariableName")) {
assertEquals("aVariableName", variable.getName());
assertEquals("abc", variable.getValue());
} else if (variable.getName().equals("anotherVariableName")) {
assertEquals("anotherVariableName", variable.getName());
assertEquals(999, variable.getValue());
} else if (variable.getName().equals("aThirdVariable")) {
assertEquals("aThirdVariable", variable.getName());
assertEquals(123, variable.getValue());
} else {
fail("Unexpected variable: " + variable.getName());
}
}
}
use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.
the class CaseServiceTest method testSetVariableLocal.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testSetVariableLocal() {
// given:
// a deployed case definition
// an active case instance
String caseInstanceId = caseService.withCaseDefinitionByKey("oneTaskCase").create().getId();
String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
// when
caseService.setVariableLocal(caseExecutionId, "aVariableName", "abc");
// then
// query by case instance id
List<VariableInstance> result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseInstanceId).list();
assertTrue(result.isEmpty());
// query by caseExecutionId
result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseExecutionId).list();
assertFalse(result.isEmpty());
assertEquals(1, result.size());
VariableInstance variable = result.get(0);
assertEquals("aVariableName", variable.getName());
assertEquals("abc", variable.getValue());
}
use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.
the class CaseServiceTest method testExecuteSetVariable.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testExecuteSetVariable() {
// given:
// a deployed case definition
String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId();
// an active case instance
String caseInstanceId = caseService.withCaseDefinition(caseDefinitionId).create().getId();
String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
// when
caseService.withCaseExecution(caseExecutionId).setVariable("aVariableName", "abc").setVariable("anotherVariableName", 999).execute();
// then
// query by caseExecutionId
List<VariableInstance> result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseExecutionId).list();
assertTrue(result.isEmpty());
// query by case instance id
result = runtimeService.createVariableInstanceQuery().caseInstanceIdIn(caseInstanceId).list();
assertFalse(result.isEmpty());
assertEquals(2, result.size());
for (VariableInstance variable : result) {
assertEquals(caseInstanceId, variable.getCaseExecutionId());
assertEquals(caseInstanceId, variable.getCaseInstanceId());
if (variable.getName().equals("aVariableName")) {
assertEquals("aVariableName", variable.getName());
assertEquals("abc", variable.getValue());
} else if (variable.getName().equals("anotherVariableName")) {
assertEquals("anotherVariableName", variable.getName());
assertEquals(999, variable.getValue());
} else {
fail("Unexpected variable: " + variable.getName());
}
}
}
use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.
the class CaseServiceTest method testSetVariable.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testSetVariable() {
// given:
// a deployed case definition
// and an active case instance
String caseInstanceId = caseService.withCaseDefinitionByKey("oneTaskCase").create().getId();
String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
// when
caseService.setVariable(caseExecutionId, "aVariableName", "abc");
// then
// query by caseExecutionId
List<VariableInstance> result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseExecutionId).list();
assertTrue(result.isEmpty());
// query by case instance id
result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseInstanceId).list();
assertFalse(result.isEmpty());
assertEquals(1, result.size());
VariableInstance variable = result.get(0);
assertEquals("aVariableName", variable.getName());
assertEquals("abc", variable.getValue());
}
use of org.camunda.bpm.engine.runtime.VariableInstance in project camunda-bpm-platform by camunda.
the class CaseServiceTest method testSetVariables.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testSetVariables() {
// given:
// a deployed case definition
// and an active case instance
String caseInstanceId = caseService.withCaseDefinitionByKey("oneTaskCase").create().getId();
String caseExecutionId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
// when
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("aVariableName", "abc");
variables.put("anotherVariableName", 123);
caseService.setVariables(caseExecutionId, variables);
// then
// query by caseExecutionId
List<VariableInstance> result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseExecutionId).list();
assertTrue(result.isEmpty());
// query by case instance id
result = runtimeService.createVariableInstanceQuery().caseExecutionIdIn(caseInstanceId).list();
assertFalse(result.isEmpty());
assertEquals(2, result.size());
for (VariableInstance variable : result) {
if (variable.getName().equals("aVariableName")) {
assertEquals(caseInstanceId, variable.getCaseExecutionId());
assertEquals(caseInstanceId, variable.getCaseInstanceId());
assertEquals("aVariableName", variable.getName());
assertEquals("abc", variable.getValue());
} else if (variable.getName().equals("anotherVariableName")) {
assertEquals(caseInstanceId, variable.getCaseExecutionId());
assertEquals(caseInstanceId, variable.getCaseInstanceId());
assertEquals("anotherVariableName", variable.getName());
assertEquals(123, variable.getValue());
} else {
fail("Unexpected variable: " + variable.getName());
}
}
}
Aggregations