Meta Variables

Meta values are not related to request or accounts but do contain data about the execution itself.

They are gathered under mockmeta variable.

Service Statistics

Mockmeta contains the number of calls that the current service received and how many of them were errors.

It can be used for debug information but also for simulating services where the client has to obtain a ticket after a number of calls or model an endpoint which is prone to failure once in a while.

Response Statistics

Similar stats (number of calls and errors) are available for the currently executed response.

Again, it can be used to alter the response behaviour once in a number of calls.

Date and Time Values

To simplify obtaining some common date and time values, MockMotor provides them in the mockmeta as well.

Variable XML Path JavaScript Path Example Value
Milliseconds since epoch $mockmeta/*:epochMs/text() mockmeta.epochMs 1491520976452

Random Values

To simplify implementing mocks where a random value is required, MockMotor provides some random values in the mockmeta variable.

Variable XML Path JavaScript Path Example Value
Random value in 0..1 range $mockmeta/*:random/text() mockmeta.random 0.765237627863
Random UUID $mockmeta/*:randomUUID/text() mockmeta.randomUUID 015d27a4-45b8-470d-ae91-b79d3331d76c

Mockmeta Examples

XML

   <meta>
      <environment>
         <calls>15</calls>
         <errors>0</errors>
      </environment>
      <service>
         <calls>15</calls>
         <errors>0</errors>
      </service>
      <response>
         <calls>14</calls>
         <errors>0</errors>
      </response>
      <random>0.8440466800253926</random>
      <randomUUID>cf68d2cc-900e-403b-b98b-c184df7b34c2</randomUUID>
      <epochMs>1494197982826</epochMs>
   </meta>

JSON

{
   "response":    {
      "errors": 0,
      "calls": 13
   },
   "environment":    {
      "errors": 0,
      "calls": 28
   },
   "randomUUID": "cbccd579-4399-4d2f-b2f7-7581aaa752da",
   "service":    {
      "errors": 0,
      "calls": 28
   },
   "random": 0.5014546023803725,
   "epochMs": 1494198022337
}

Use Examples

Here are simple examples of how to use mockmeta values in the responses.

XML

Generate unique order identifier value:

<s:Envelope xmlns:s="...">
<s:Body>
  <t:GenerateOrderIdResponse xmlns:t="order">
    <t:OrderId>{$mockmeta/*:randomUUID/text()}</t:OrderId>
  </t:GenerateOrderIdResponse>
</s:Body>
</s:Enveloper>

JSON

Setting UUID as a response id:

{
  "id": mockmeta.randomUUID,
  ...
}