C - Expert 3 - Calculations within collections

Purpose Purpose of the section is to introduce calculation within collections

Description

  1. Adding a rule which compares the value of NbOfTxs to the amount of Tx occurrences within file
  2. Testing

Instructions

1: Adding a rule which compares the value of NbOfTxs to the amount of Tx occurrences within file

When we are comparing a value of an element to a number of occurrences of another element, we first have to find a shared context for both of these elements and keep in mind that we most likely are comparing a string value to an integer value, depending on the type defined in the schema.

In this rule, we can start by making a rule from scratch. We should select NumberOfTransactions from the tree, but this time choosing plus icon instead of a dropdown. Following empty modal should now be visible.

 

 

We now have to fill every mandatory text box manually.

First common type of the relevant elements has to be "Message", and OCL code will be as follows:

self.Header.NumberOfTransactions = self.Transaction->size()

->size() will return an integer of the amount of Transaction elements.

2: Testing

Testing should include both valid and invalid amounts.