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 |
|
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 |
|
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 |
|
|
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 |
|
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 |
|
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:
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
|
|
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 |
|
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 |
|
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 |
This example shows how to insert a value:
-
The inbound step property trigger waits for a message with a uri property that contains any value. If an incoming message meets this condition, API simulation sends a response.
-
The outbound step property insert writes the value Hello world! to the payload of a service.
schema: SimV1
name: default
services:
- name: Service01
steps:
- direction: In
trigger:
- uri: '*'
- direction: Out
insert:
- value: 'Hello world!'