}
@Test
@Deployment(resources = "org/camunda/bpm/engine/cdi/test/api/BusinessProcessBeanTest.test.bpmn20.xml")
public void testFlushVariableCache() {
BusinessProcess businessProcess = getBeanInstance(BusinessProcess.class);
// cannot flush variable cache in absence of an association:
try {
businessProcess.flushVariableCache();
fail("exception expected!");
} catch (ProcessEngineCdiException e) {
assertEquals("Cannot flush variable cache: neither a Task nor an Execution is associated.", e.getMessage());
}
businessProcess.startProcessByKey("businessProcessBeanTest");
// set a variable
businessProcess.setVariable("aVariableName", "aVariable");
// the variable is not yet present in the execution:
assertNull(runtimeService.getVariable(businessProcess.getExecutionId(), "aVariableName"));
// set a local variable
businessProcess.setVariableLocal("aVariableLocalName", "aVariableLocal");
// the local variable is not yet present in the execution:
assertNull(runtimeService.getVariable(businessProcess.getExecutionId(), "aVariableLocalName"));
// flush the cache
businessProcess.flushVariableCache();
// the variable is flushed to the execution
assertNotNull(runtimeService.getVariable(businessProcess.getExecutionId(), "aVariableName"));
// the local variable is flushed to the execution
assertNotNull(runtimeService.getVariable(businessProcess.getExecutionId(), "aVariableLocalName"));
// the cache is empty
assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableCache());
// the cache is empty
assertEquals(Collections.EMPTY_MAP, businessProcess.getVariableLocalCache());
}