Expressions

Expressions

Introduction

An expression is used to define how data could be randomly generated. Both mocked SOAP and REST web services supports expressions. An expression always contains five elements:

  • Dollar sign ($)
  • Start bracket
  • Expression name
  • Arguments
  • End bracket

Each type of expression have predefined set of allowed arguments. An argument is always includes a name and a value. There are three types of arguments: Text, Number and Array:

  • Text: The text argument is representing a String value and always starts and ends with a quotation mark.
  • Number: The number argument is representing a Double value.
  • Array: An array can contain multiple values with mixed types.

Expressions

Random Boolean

The Random Boolean expression will generate random boolean value.

${RANDOM_BOOLEAN()}


Random Date

The Random Date expression will generate a random date.

${RANDOM_DATE()}


Random Date time

The Random Date expression will generate a random date time with the following format: yyyy-MM-dd’T’HH:mm:ss.

${RANDOM_DATE()}


Random Decimal

The Random Decimal will generate a random decimal value (Float).

${RANDOM_DECIMAL()}


Random Double

The Random Double will generate a random double value.

Arguments:

  • min: The min bound.
  • max: The max bound.

${RANDOM_DOUBLE(min=0.0,max=10.0)}


Random Email

The Random Email will generate a random email.

Arguments:

  • domain: The domain.
  • min: The min length of username.
  • max: The max length of username.
  • topDomain: The top domain.

${RANDOM_EMAIL(domain="castlemock",min=5,max=10,topDomain"com")}


Random Enum

The Random Email will pick a random enum.

Arguments:

  • values: A text array with the available enum values.

${RANDOM_ENUM(values=["available","pending","sold"])}


Random Float

The Random Float will generate a random float value.

${RANDOM_FLOAT()}


Random Integer

The Random Integer will generate a random interger value.

Arguments:

  • min: The min bound.
  • max: The max bound.

${RANDOM_INTEGER(min=0,max=10)}


Random Long

The Random Long will generate a random long value.

${RANDOM_LONG()}


Random Password

The Random Password will generate a random password.

Arguments:

  • min: The min length of the password.
  • max: The max length of the password.

${RANDOM_PASSWORD(min=0,max=10)}


Random String

The Random String will generate a random string with a length between 5 and 15.

${RANDOM_STRING()}


Random UUID

The Random UUID will generate a random UUID.

${RANDOM_UUID()}

Example

<user>
   <id>${RANDOM_LONG()}</id>
   <name>${RANDOM_STRING()}</name>
   <email>${RANDOM_EMAIL(domain="castlemock",min=5,max=10,topDomain"com")}</email>
   <status>${RANDOM_ENUM(values=["active","inactive","locked"])}</status>
</user>