Selected Accounts

Mock accounts selected for a request can be used to form a response that is specific for this particular account or flow.

For example:

  • The values in the response can be taken from the mock account
  • The response can contain different number of nested items, e.g. order items
  • The response can be made to return an error or fault for some mock accounts
  • The response delay can be made to depend on the used mock account

    Single Account

    The selected account variable ($account for XML, account for JSON) contains one mock account selected for the response.

    If no accounts were selected, $account will have an empty sequence () and account will be null.

    One Account Out of Many

    If more than one account is selected for the response, the value of $account and account is a single, randomly chosen account from the full set of selected accounts.

    Please do not make an assumption about which account from a set becomes $account/account. It can be a different account for each call.

    As XML

    For XML responses, $account contains a sequence of elements named after the properties in the mock account and their text content has the values of those properties.

    For example, for a mock account that contains 3 properties (ban, nag and subid) the variable $account will have the following structure:

          <account>
             <ban>33</ban>
             <nag>3</nag>
             <subid>333</subid>
          </account>
    

    These values can be used in the response, for example:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Header/>
       <soapenv:Body>
         <w:GetAccountsResponse xmlns:w="accounts:store">
             <w:Ban>{$account/*:ban/text()}</w:Ban>
             <w:Nag>{$account/*:nag/text()}</w:Nag>
             <w:Subid>{$account/*:subid/text()}</w:Subid>
         </w:GetAccountsResponse>
       </soapenv:Body>
    </soapenv:Envelope>
    
    Always use the namespace wildcard `*:` when dereferencing an account property. Sometimes, it may work without it but it depends on the response default namespace.

    Note: you do not have to use the full path to a property in the account. You can just use the property name, e.g. {$subid}. Read Simplified Variables for more info.

    As JSON

    For JSON responses, account contains a map of mock account properties and their text content has the values of those properties.

    For example, for a mock account that contains 3 properties (ban, nag and subid) the variable account will have the following structure:

       {
          "ban": "33",
          "nag": "3",
          "subid": "333"
       }
    

    These values can be used in the response, for example:

    {
      "Ban": account.ban,
      "Nag": account.nag,
      "Subid": account.subid
    }
    

    Multi-Values

    When an account contains a multi-value (multiple values for the same property), the format of the variable values changes.

    Imagine an account that has three values for property subid: 100, 200 and 300.

    XML

    When an account contains a multi-value for a property, $account has multiple elements for that property.

          <account>
             <subid>100</subid>
             <subid>200</subid>
             <subid>300</subid>
             <ban>30593002</ban>
             <nag>3059300</nag>
          </account>
    

    The multi-values then can be iterated in the response using XQuery for loop:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Header/>
       <soapenv:Body>
         <w:GetAccountsResponse xmlns:w="accounts:store">
             <w:Ban>{$account/*:ban/text()}</w:Ban>
             <w:Nag>{$account/*:nag/text()}</w:Nag>
             {
               for $subid in $account/*:subid/text()
               return
                 <w:Subid>{$account/*:subid/text()}</w:Subid>
             }
         </w:GetAccountsResponse>
       </soapenv:Body>
    </soapenv:Envelope>
    

    JSON

    The same account, when represented as JSON, has an array value for that property instead of a string:

       {
          "ban": "33",
          "nag": "3",
          "subid": [ "100","200","300" ]
       }
    

    The multi-values can be iterated using a regular Javascript loop:

    output = 
    {
      "Ban": account.ban,
      "Nag": account.nag
    }
    
    for(var i=0; i<account.subid.length; i++ ) {
      var sub = account.subid[i];
      output["Subid"+i] = sub;
    }
    

    Multiple Accounts

    When multiple accounts match the condition in the response, all of them are collected into a set under accounts variable ($accounts for XML, accounts for JSON).

    If no accounts were selected, $accounts will have an empty sequence () and accounts will be an empty array [].

    As XML

    For XML responses, $accounts contains a sequence of account elements that are identical in structure to $account variable. The order of accounts in the sequence is not specified.

    For example:

    <accounts>
        <account>
            <ban>33</ban>
            <nag>3</nag>
            <subid>333</subid>
        </account>
        <account>
            <ban>47</ban>
            <nag>2</nag>
            <subid>8710</subid>
        </account>
    </accounts>
    

    Accounts can be iterated with XQuery for loop, as, for example, in this response payload:

    <GetOrders>
             {
               for $order in $accounts/*:account
               return
                 <Order>
                     <OrderId>{$order/*:id/text()}</Order>
                     <Summary>{$order/*:summary/text()}</Summary>
                     ...
                 </Order>
             }
    </GetOrders>
    

    As JSON

    For JSON responses, accounts contains an array if mock account objects.

    [
       {
          "ban": "33",
          "nag": "3",
          "subid": "333"
       },
       {
          "ban": "47",
          "nag": "2",
          "subid": "8710"
       }
    ]
    

    The accounts can be iterated with Javascript to form a response that contains a number of nested items:

    output = 
    {
      "account": account.id,
      "orders": []
    }
    
    for(var i=0; i<accounts.length; i++ ) {
      var acc = accounts[i];
      
      var order = {
        "id": acc.orderId,
        "summary": acc.summary,
        ...
      };
    
      output.orders.push(order);
    }