Benefits of using globals
In Chapter 5, Understanding KIE Sessions, global variables were introduced as a way of interacting with external services. Even if the chapter never explicitly stated this, its tests showed another important benefit of using global
: different implementations of the same global may be provided, depending on the context. Right now, the particular context that we are interested in is the testing context.
When testing, mock versions of the global variables requiring interaction with external services, can be provided. These mock variables will immensely reduce the complexity and boiler-plate code required by our tests.
Let's take the following example from the code bundle of Chapter 5, Human Readable Rules:
global AuditService auditService; rule "Send Suspicious Operation to Audit Service" when $so: SuspiciousOperation() then auditService.notifySuspiciousOperation($so); end
The preceding rule uses a global
to interact with an audit service and notify it about suspicious...