use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.
the class VariableListenerTest method testVariableListenerWithProcessTask.
@Deployment(resources = { "org/camunda/bpm/engine/test/cmmn/listener/VariableListenerTest.testVariableListenerWithProcessTask.cmmn", "org/camunda/bpm/engine/test/cmmn/listener/VariableListenerTest.testVariableListenerWithProcessTask.bpmn20.xml" })
public void testVariableListenerWithProcessTask() {
CaseInstance caseInstance = caseService.createCaseInstanceByKey("case");
CaseExecution processTask = caseService.createCaseExecutionQuery().activityId("PI_ProcessTask_1").singleResult();
String processTaskId = processTask.getId();
caseService.withCaseExecution(processTaskId).manualStart();
// then the listener is invoked
assertEquals(1, LogVariableListener.getInvocations().size());
DelegateVariableInstanceSpec.fromCaseExecution(caseInstance).sourceExecution(processTask).event(VariableListener.CREATE).name("aVariable").value("aValue").matches(LogVariableListener.getInvocations().get(0));
LogVariableListener.reset();
}
use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.
the class VariableListenerTest method testAnyEventListenerByClass.
@Deployment
public void testAnyEventListenerByClass() {
CaseInstance caseInstance = caseService.withCaseDefinitionByKey("case").create();
CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
assertNotNull(taskExecution);
// when i set a variable on a higher scope
caseService.withCaseExecution(caseInstance.getId()).setVariable("anInstanceVariable", "anInstanceValue").execute();
// then the listener is not invoked
assertTrue(LogVariableListener.getInvocations().isEmpty());
// when i set a variable on the human task (ie the source execution matters although the variable ends up in the same place)
caseService.withCaseExecution(taskExecution.getId()).setVariableLocal("aTaskVariable", "aTaskValue").execute();
// then the listener is invoked
assertEquals(1, LogVariableListener.getInvocations().size());
DelegateVariableInstanceSpec.fromCaseExecution(taskExecution).event(VariableListener.CREATE).name("aTaskVariable").value("aTaskValue").matches(LogVariableListener.getInvocations().get(0));
LogVariableListener.reset();
// when i update the variable on the human task
caseService.withCaseExecution(taskExecution.getId()).setVariable("aTaskVariable", "aNewTaskValue").execute();
// then the listener is invoked
assertEquals(1, LogVariableListener.getInvocations().size());
DelegateVariableInstanceSpec.fromCaseExecution(taskExecution).event(VariableListener.UPDATE).name("aTaskVariable").value("aNewTaskValue").activityInstanceId(taskExecution.getId()).matches(LogVariableListener.getInvocations().get(0));
LogVariableListener.reset();
// when i remove the variable from the human task
caseService.withCaseExecution(taskExecution.getId()).removeVariable("aTaskVariable").execute();
// then the listener is invoked
assertEquals(1, LogVariableListener.getInvocations().size());
DelegateVariableInstanceSpec.fromCaseExecution(taskExecution).event(VariableListener.DELETE).name("aTaskVariable").value(null).activityInstanceId(taskExecution.getId()).matches(LogVariableListener.getInvocations().get(0));
LogVariableListener.reset();
}
use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.
the class VariableListenerTest method testVariableListenerByDelegateExpressionWithFieldExpressions.
@Deployment
public void testVariableListenerByDelegateExpressionWithFieldExpressions() {
beans.put("listener", new LogInjectedValuesListener());
caseService.withCaseDefinitionByKey("case").create();
CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
assertNotNull(taskExecution);
// when i set a variable
caseService.withCaseExecution(taskExecution.getId()).setVariableLocal("testVariable", "value1").execute();
// then the field expressions are resolved
assertEquals(1, LogInjectedValuesListener.getResolvedStringValueExpressions().size());
assertEquals("injectedValue", LogInjectedValuesListener.getResolvedStringValueExpressions().get(0));
assertEquals(1, LogInjectedValuesListener.getResolvedJuelExpressions().size());
assertEquals("cam", LogInjectedValuesListener.getResolvedJuelExpressions().get(0));
LogInjectedValuesListener.reset();
}
use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.
the class VariableListenerTest method testUpdateEventListenerByClass.
@Deployment
public void testUpdateEventListenerByClass() {
caseService.withCaseDefinitionByKey("case").create();
CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
assertNotNull(taskExecution);
// when i create a variable on the human task
caseService.withCaseExecution(taskExecution.getId()).setVariableLocal("aTaskVariable", "aTaskValue").execute();
// then the listener is not invoked
assertTrue(LogVariableListener.getInvocations().isEmpty());
// when i update the variable on the human task
caseService.withCaseExecution(taskExecution.getId()).setVariable("aTaskVariable", "aNewTaskValue").execute();
// then the listener is invoked
assertEquals(1, LogVariableListener.getInvocations().size());
DelegateVariableInstanceSpec.fromCaseExecution(taskExecution).event(VariableListener.UPDATE).name("aTaskVariable").value("aNewTaskValue").activityInstanceId(taskExecution.getId()).matches(LogVariableListener.getInvocations().get(0));
LogVariableListener.reset();
// when i remove the variable from the human task
caseService.withCaseExecution(taskExecution.getId()).removeVariable("aTaskVariable").execute();
// then the listener is not invoked
assertTrue(LogVariableListener.getInvocations().isEmpty());
}
use of org.camunda.bpm.engine.runtime.CaseExecution in project camunda-bpm-platform by camunda.
the class VariableListenerTest method testVariableListenerInvokedFromSourceScope.
@Deployment
public void testVariableListenerInvokedFromSourceScope() {
CaseInstance caseInstance = caseService.withCaseDefinitionByKey("case").create();
CaseExecution taskExecution = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult();
assertNotNull(taskExecution);
// when i create a variable on the case instance
caseService.withCaseExecution(caseInstance.getId()).setVariable("aTaskVariable", "aTaskValue").execute();
// then the listener is not invoked
assertEquals(0, LogVariableListener.getInvocations().size());
// when i update the variable from the task execution
caseService.withCaseExecution(taskExecution.getId()).setVariable("aTaskVariable", "aTaskValue").execute();
// then the listener is invoked
assertEquals(1, LogVariableListener.getInvocations().size());
DelegateVariableInstanceSpec.fromCaseExecution(caseInstance).sourceExecution(taskExecution).event(VariableListener.UPDATE).name("aTaskVariable").value("aTaskValue").activityInstanceId(caseInstance.getId()).matches(LogVariableListener.getInvocations().get(0));
LogVariableListener.reset();
}
Aggregations