Adding tests to a condition

You can write standard tests, tests on attribute values, tests on values returned by methods, and tests on values belonging to sets of values. You can write conditions with join tests.

You can add tests to conditions when writing technical rules in IRL.

Add standard tests to a condition

To add standard tests to a condition, use the following pattern:

[variable:] ClassName(<test> [; <test>]*);
not ClassName(<test> [; <test>]*);
collect ClassName(<test> [; <test>]*);
exists ClassName(<test> [; <test>]*);

Example

when {
  account: Account(
         balance > 2000; 
         currency equals Currency.EUR;
         date.compareTo(currentDate) > 0);
}
// this rule will apply to all accounts whose balance is > 2000,
// and currency is EURO and date is greater than current date

Write a test on the attribute value of a condition object

To write a test based on the attribute value of an object bound in the current condition, use the following pattern:

attribute <operator> <value>
attribute booleanmethod <value>
attribute.method (<arguments>)
<operator> <value>

Example

when {
  account: Account(
         balance > 2000; 
         currency equals Currency.EUR;
         date.compareTo(currentDate) > 0);
}
// this rule will apply to all accounts whose balance is > 2000,
// and currency is EURO and date is greater than current date

Write a test on the return value of the method of a condition object

To write a test based on the return value of the method of an object bound in the current condition, use the following pattern:

non-void-method(<arguments>) <operator> <value>
non-void-method(<arguments>) booleanmethod <value>
// only in case of a method with a single argument, returning a Boolean:
attribute.method(<arguments>)<operator> <value> 

Example

when {
  account: Account(
         getBalance()>2000;
         getCurrency() equals Currency.EUR;
         getDate().compareTo(currentDate) > 0);
// this rule will apply to all accounts whose balance is > 2000,
// and currency is EURO and date is greater than current date
// same as a test on attribute values, but with methods instead
}

Write a test on a value belonging (or not) to a set of values

To write a test based on a value belonging (in) or not (!in) to a set of values, use the following pattern:

<value> in|!in <group>
<value> in|!in {value1 [,value]*}

where <group> is a collection or an array.

Example

when { 
    account : Account(getCurrency() in { Currency.EUR, 
                                         Currency.USD});
    contract : Contract( status !in getBlockedStatusList() );
}
// for all accounts whose currency is either EUR or USD, 
// and all contracts whose status does not belong to the list 
// of methods returned, then...

Write a condition with a join test

A join test uses a variable (or several variables) defined in previous conditions.

To write a condition with a join test, use the following pattern:

variable1: ClassName1(<tests>);
variable2: ClassName2(<tests using variable1>);
[variableP: ClassNameP(<tests using variable1, 2, …>);]

Example

when {
   purchase : Purchase(pcurrency : getCurrency());
   contract : Contract(getID() equals 
                       purchase.getContractID());
   Account(getContractID() equals contract.getID(); 
           getCurrency() == pcurrency);
}
// for all purchases related to a contract, 
// and for which an account exists in the same currency
// as the purchase, then...