Service steps
Use service steps in your simulation file to define what your virtual service does and in which order.
This topic lists all steps properties and includes examples that show how to use them.
|
Steps property |
Description |
Example |
|---|---|---|
|
Collection of rules that save values from messages in buffers. |
||
|
Defines the connection that the step uses to send or receive messages. Use the connection properties to configure it. |
||
|
counter |
Defines how many times the step sends or receives the specified message before the simulation proceeds to the next step. |
5 |
|
description |
Description of what the step does. |
contract verification |
|
Defines whether the step sends or receives messages. To send messages, enter the value Out. To receive messages, enter the value In. If you leave the value blank, the simulation derives the direction logically (implicit). The simulation assumes that the first step is In, the next step Out, and so on. |
Out |
|
|
Reference a connection by its name to receive messages. To use this property, set the direction property to In. |
myConnection |
|
|
Collection of rules that insert values. |
||
|
message |
Defines the message to send. Use the message properties to configure it. |
|
|
Name of the step. |
step 1 |
|
|
order |
Defines whether the step receives messages in a specific order. Enter STRICT to use the specified order or ANY to accept any order. The default value is STRICT. |
STRICT |
|
resource |
In your simulation file, you can reference a resource, such as a data structure. To define what happens to this resource, use a rule with a resource steps property. |
Example |
|
Collection of rules to store message payloads or other properties of a message in a specific file. Use the file property to set the file name and file extension. |
||
|
Reference a connection by its name to send messages. To use this property, set the direction property to Out. |
myConnection |
|
|
Collection of rules that start a service. If all rules apply, API simulation starts the service. |
||
|
References predefined services that you set as templates. You can reuse these services in other service steps. |
OAuth template |
|
|
Collection of rules for message verification. If the verification fails, API simulation logs a warning. |
Examples
The following examples show how to use the insert, save, trigger, and verify properties.
This example shows how to insert values:
-
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!'
This example shows how to save message payloads:
-
The inbound step property trigger waits for a message that contains any value in the uri property.
-
The inbound step property save saves the incoming message that meets this condition in a file named request.dat.
-
After the simulation saves the incoming message, the outbound step property insert writes the value Request saved successfully to the payload of a service.
schema: SimV1
name: default
services:
- name: Service01
steps:
- direction: In
trigger:
- uri: '*'
save:
- file: request.dat
- direction: Out
insert:
- value: Request saved successfully
This is an example of how a virtual service could look like. It specifies the following:
-
The name of the virtual service is Service01 and it is a request response pair.
-
The inbound step 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 property message sends the value Hello world! to a service with the connection port 54545.
schema: SimV1
name: default
services:
- name: Service01
steps:
- direction: In
trigger:
- uri: '*'
- direction: Out
message:
payload: Hello world!
connections:
- port: 54545
This example shows how to verify message rules:
-
The inbound step property trigger waits for a message that contains any value in the uri property.
-
The inbound step property verify verifies that the uri property has the value /test/content.
-
The outbound step property insert writes the value ok to the payload of the service.
schema: SimV1
name: default
services:
- name: Service01
steps:
- direction: In
trigger:
- uri: '*'
verify:
- uri: /test/content
- direction: Out
message:
payload: ok