Specify property values

In a simulation, steps properties represent relevant message elements, such as a header, payload, or name. To define these steps properties you can use rules and values. These values can be either static or dynamic.

How can you use values?

This topic shows practical examples on how to use values in your simulations. The examples also explain which steps property you can use with which values.

Use multiline values

YAML uses indentation instead of indicators to mark the structure. This is essential if you use multiline values. Make sure that these values are indented under the property.

Use dynamic date and time values

You can use a dynamic expression to specify date and time values. This allows you, for instance, to define the current date as an identifier for a message.

  • The base date is derived from the Coordinated Universal Time (UTC) and expressed in ISO 8601 format.

  • Define date and time values with one of the step properties Insert, Verify or Trigger.

Use current date and time values

The dynamic expressions DATE and TIME use the current date or the current time as base values.

The examples in the table use January 13, 2022 and 2:18 PM (14:18:00) as base values:

Expression

Description

Example

{DATE}

Full date

2022-01-13

{TIME}

Current date and time

2022-01-13T14:18:00Z

Calculate dates from a base date

You can calculate dynamic date and time values by defining a base date along with deviations.

Syntax: {<EXPRESSION>[<Base date>][<Offset>][<Format>]}

Parameter

Description

Base date

Specify a date value. If you leave the value empty, API simulation uses the current date as the base date. You can also use buffer values as the base date.

Offset

Define what to add or deduct from the base date. Offsets consist of a signed integer and a unit. These are the possible values:

  • d: days

  • M: month

  • y: years

  • h: hours

  • m: minutes

  • s: seconds

Format

Define the date format if the date format of the test object differs from the ISO 8601 format. The default value is yyyy-MM-dd.

To apply the standard behavior to one of the parameters, leave the parameter value empty []. For instance, {DATE} and {DATE[][][]} have the same meaning. API simulation uses the current date without deviations.

Escape special characters

If you want to use the special characters },],{, [ and " as text in your simulations, first you must escape them. You can escape either individual characters or entire strings.

To do this, use double quotation marks (") before and after the individual character or string.

Syntax: "<special characters>"

The special character " requires an additional quotation mark to indicate that the subsequent " is part of the actual string and not the end of an escaped string.

Use buffered values

If you need values of message elements within your virtual service more than once, use the property Buffer to temporarily save them. You can read out these buffer values within the virtual service and insert them into another message element.

Create buffer values

To buffer a value, you need two things:

  • A buffer name in order to find the buffer values again. Buffer names are not case-sensitive.

  • A buffer with the step property buffer.

Read out buffered values

To specify a buffered value for a message element, use the following syntax:

Syntax: {B[<buffer name>]}

  • Use buffered values with the step property Insert.

Read out buffered values into the payload of a message

Typically, buffered values require a clear path to locate the section of the message you want to read. This can be a challenge with complex payloads, especially those with many special characters. You can use the following syntax to read a buffered value and insert it directly into the payload of a message.

Syntax: %{<buffer name>}

  • Use buffered values within the payload property of a message.

Use split buffers

To split the value of a message element based on a separator, you can define a split buffer.

Create split buffer values

To split a value and store it as a buffer, you'll need three things:

  • A buffer name to find the buffer values again.

  • A separator to identify the individual parts of a value.

  • A buffer with the buffer step property.

Syntax: {SPLITBUFFER[<Separator>]}

When buffering, API simulation creates a separate buffer with consecutive numbers for each partial value.

Read out buffered values

To specify a buffered value for a message element, use the buffer name along with the corresponding buffer value number:

Syntax: {B[<Buffer name><number>]}

  • Use buffered values with the step property Insert.

Use XBuffers

With an XBuffer you can save a dynamic value within a static string in a buffer.

Create XBuffer values

To buffer a value within a string you'll need two things:

  • A buffer name to find the buffer values again.

  • A buffer with the buffer step property.

Syntax: <string>{XB[<Buffer name>]}<string>

Read out buffered values

Specify XBuffer values in the same way as buffer values.

Generate random text

You can create a random text of uppercase letters as a value for a message element. Specify the length of the text with a parameter.

Syntax: {RANDOMTEXT[<Length of random text>]}

  • Define a random text with the step property Insert.

Generate random number

You can create random numbers as a value for a message element.

  • You can specify a random number with one of the following parameters:

    To define the length of a random number, enter {RND[<Length of random number>]}. You can have a maximum of 19 digits.

    To define an upper and lower limit of a random number, enter {RND[<Lower limit>][<Upper limit>]}. The lower limit must be less than the upper limit, and negative values are possible. The generated integer is a value that lies between the upper and lower limit and includes boundaries.

  • Define a random number with the step property Insert

Generate unique IDs

You can create a unique ID as a value for a message element. Unique IDs are generated consecutively, and each ID is assigned only once. Specify the length of the unique ID with a parameter.

Syntax: {UNIQUEID[<length of uniqueID>]}

  • Define a unique ID with the step property Insert.

If there are not enough IDs available and the system cannot generate new IDs, an error occurs. Restart the environment to reset the unique IDs, or increase the length of the unique IDs.

Use regular expressions

Use regular expressions to compare whether a searched value contains a string that matches the regular expression.

API simulation uses the .NET Framework syntax for regular expressions.

Syntax: {REGEX["<regular expression>"]}

  • Define regular expressions with the Verify or Trigger step properties.

Generate random strings with regular expressions

You can generate random character strings that are limited by regular expressions. You must specify the regular expressions within double quotation marks.

Syntax: {RANDOMREGEX["<Regular expression>"]}

  • Generate random strings with regular expressions with the Insert step property.

Perform calculations

You can perform calculations with the MATH expression.

Syntax: {MATH[<Operand 1><Operator><Operand 2>..<Operator><Operand n>]}

  • Perform calculations with the Insert or Verify step properties.

  • Use numerical values and scientific notations as operands.

  • Operators are processed according to the PEMDAS rule. However, you can modify this behavior by using brackets.

You have to separate decimal places with a decimal point.

API simulation supports the following operators:

Operator

Description

+, -, *, /

basic arithmetic operations

%

Modulo operation

^

potentiation

==

equals

!=

not equal

<

less than

>

greater than

<=

less or equal

>=

greater than or equal to

Use confidential data

To use confidential data in your simulations you can store them in variables as:

This allows you to easily reference this data in the simulation files and prevent other users, who have access to these files, from viewing sensitive information.

Set variables

If you set environment variables in your system, it's important that you use the prefix Simulator__Variables__ with the variable name, for example Simulator__Variables__My Secret Password.

If you set the variables in the appsettings.yml file, make sure you have administrator rights and follow these steps:

  1. Open the appsettings.yml file.

  1. Enter your variables in the Simulator settings under Variables with the following syntax: <Variable name>: <Value>.

Appsettings.yml example entry.

Fetch data from variables

To fetch data from variables use the dynamic expression VAR .

Syntax: '{VAR[<Variable name>]}'

  • Use variables with the step properties Insert or Verify.

Read data from a resource

You can work with resources to share data at runtime between different running simulations. The FROM expression is a way to use data from a resource.

Syntax: {FROM[resource name][column][condition]}

Parameter

Description

Resource name

Specify the name of the resource that contains the data you want to use.

Column

Specify the column in which you want to search.

Condition

Define a SQL WHERE clause to narrow the value you want to use.

  • Use the expression with the step properties Insert, Verify or Trigger.

Use replacement value

You can use the TRY dynamic expression to enter a replacement value for a property if a specific dynamic value can't be found. For example, if you want to read a buffered value that doesn't exist and don't want an exception, use the replacement value.

Syntax: {TRY[<dynamic expression>][<replacement>]}

  • Specify a TRY expression with the Insert step property.

Specify a time stamp

The dynamic expression TIMESTAMP returns the number of milliseconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970.

Syntax: {TIMESTAMP}

  • Specify a time stamp with the step property Insert.

Use a counter

Use the dynamic expression COUNTER for instance, to set how many times a specified message should be sent or received before proceeding to the next step.

Syntax: {COUNTER}

  • Use a counter with the step property Insert.