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")
.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)