public void testCreateEventListenerByClass() {
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 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 not invoked
assertTrue(LogVariableListener.getInvocations().isEmpty());
// 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());
}