Step rules

Define rules in your simulation file to automatically select the messages that your service sends or receives. For example, you can set a rule that checks a value and matches it to the correct service.

You always use rules together with a step. Each rule evaluates to either true or false. You can use rules in the step properties trigger, buffer, verify, insert, and save.

This topic lists all rules properties and includes an example that shows how to use them.

Rules property

Description

Example

count

Use this rule together with the jsonPath or xPath properties. If a message contains multiple elements with a specific path,API simulation verifies that the number of elements matches the defined value.

5

dataType

Defines the data type of the value property. Use the data types Boolean, Date, Numeric, Password, or String.

String

exists

Indicates whether the element that you verify exists. Set the value to True if it exists, or to False if it doesn't.

True

file

Defines the path, file name, and file extension of the file where the simulation saves the payload or other message property values.

/path/to/file.txt

index

If an element occurs more than once, define an index to determine which element to use. For example, if there are 2 headers with the same name and you want to use the second one, set the index to 2.

2

jsonPath

Use this property to find an element in a message that is in JSON format. Enter the path to the element. Define the value of the element in the property value.

x.store.book[0].title

key

Use this property to find specific message elements. Enter the name of the element. Define the type of the message element with the type property. If you want to insert the key, you also need to add and define the value property.

myHeader

name

Defines the name of the rule property.

myBuffer

operator

Use this property to find specific property value ranges, such as 'greater than' or 'less than'. Use one of the following operators: Equal, NotEqual, Less, LessOrEqual, Greater, GreaterOrEqual, or In.

Greater

property

References a connection or message property to define a rule. For example, Endpoint, Path, or Queue.

Endpoint

range

Use this property to select a specific part of a value. We use the C# range operator specification. You define a range with 2 index operands. You can omit either operand. Counting starts at 0. The left index is inclusive and the right index is exclusive:

  • <Index>..<Index> defines the range from a specific character to a specific character.

  • ..<Index> defines the range from the first character to a specific character.

  • <Index>.. defines the range from a specific character to the last character.

Use the hat (^) operator with the index to count from the end. For example, ..^4 takes all characters up to the last 4 characters. ^4.. starts after the last 4 characters and ends with the last character.

Example text

..3 gives Exa

3..^3 gives mple t

^3.. gives ext

tree

Defines a JSON or XML tree structure as the value of a payload element.

Copy
{
  "name": "Root",
  "children": [
    { "name": "Child 1" },
    { "name": "Child 2" }
  ]
}

type

Specifies which part of a message to steer. Possible types are Header, MessagingProperty, Query, Path, or Multipart.

For all types except Path, add the key property to find these specific message elements.

Header

uri

Defines the URI, or a part of it, to use as the value for a rule.

/wait/for/me

value

Defines the value of a rule property. This can be any text or a Boolean value.

myValue

valueBase64

Use this property to provide a BASE64-encoded value if the original content contains special characters that aren't allowed in YAML.

SGVsbG8gJiBnb29kYnll

xPath

Use this property to find an element in a message that is in XPath format. Enter the path to the element. Define the value of the element in the property value.

/bookstore/book[price>35]/price