Example: Creating simple message bodies for subscription

In this example, you create a message structure with the more powerful features of the field editor, namely, the ability to validate the structure of a message when it is received and the ability to capture field values and save them to tags. Validation is a key aspect of deciding whether a test passes or fails.

About this task

To learn more about the power of validation, see Validating scalar fields and Validating message fields

For our example, we can assume that validity is fulfilled if the message that arrives meets the following requirements:

  • Having at least the four parts: name, age, position, and otherData -> creditRating.
  • The value in the creditRating field must be greater or equal to 10.

The full course of validation features is available only within the context of tests. Therefore, we start by creating a subscriber action within the test steps of a Test (For more information, see Test Factory.)

Procedure

  1. Begin by creating a new Subscribe action and set its transport, formatter, and message header to be the same as our Publish action.
  2. Next, create the same body structure, except for libraryCardNo and carRegistration, as we are not interested in these fields.
  3. Double-click the first name (String) element (Peter Thompson) to open the field editor. Click the Validate tab and clear the Equality and Type options, since we are only interested in validating the attributes name. Field editor
  4. Click OK to save the changes and repeat the same step for the age and position elements. If wanted, you can disable the Equality and Type actions in the Actions pane (if displayed), beneath the message body.
  5. Now open the creditRating element (under otherData) in the field editor and select the Validate tab.

    We want to accept messages where this field's value is 10 or greater. A convenient way of doing so is by specifying a regular expression. Select the Equality action and change its Action Type to Regex. Next, enter [1-9][0-9]+ in the empty value field. Which is a Perl regular expression, which accepts numbers from 10 upwards.

    Field editor