Adding contain verification points

With contain verification points, you can check that one or several elements of the XML content returned by a service match the XML fragment that is specified in the verification point.

About this task

When you add verification points, the results from a service response are compared with the expected content that is specified in the verification point test element. Equal or contain verification points enable you to directly compare the XML contents that the service returns.
  • Contain verification points return a Pass status when the response XML contents contain the expected XML fragment.
  • Equal verification points return a Pass status when the response XML contents match exactly the entire expected XML content.

Complex service requests or verification points might have empty XML elements that are not needed in a test script. When playing back the test, you can skip such empty XML elements. In Window > Preferences > Test > Test editor > Service test ensure that the Display the 'Skip if empty' column in XML tree viewer check box is selected. This option displays a Skip if empty column in the tree view of the request. You can then choose the XML elements to skip.

Procedure

  1. Open the test editor, and select a service response element.
  2. In the Test Element Details area, click the Message tab and select the Form or Tree view.
  3. Expand the envelope line, right click the element that you want to check, and then click Create Contain Verification Point. This action creates a contain verification point that includes the XML element from the recorded response.
    Note: You can also create a contain verification point with the message response by selecting the message response in the Test Contents pane and clicking Add > Contain Verification Point. However, the result is effectively the same as an equal verification point because the verification point contains the entire XML content of the message response.
  4. Select the verification point, and in the Test Element Details pane, type a name for the verification point.
  5. Select the verification options:
    • Select the Test using XML namespaces check box to perform the verification on the qualified structure of the XML document, including the namespace tagging, instead of the simple name. Disable this option to check only the simple name of the element and the final return value.
    • Select the Test XML text nodes check box to include the content of text elements in the verification.
    • Select the Test XML attributes check box to include the content of attributes in the verification.
  6. If necessary, select the Form, Tree, or Source views to edit the expected XML fragment.

    For an equal verification point, the expected XML data contains the XML document from the response test element. If necessary, you can edit the expected XML data.

    You can specify standard Java regular expressions in the Tree view. Select the Regular expression column on the line of an attribute or text value and type the regular expression in the Value column. For example, the following regular expression checks for a correctly formatted email address: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/

    When using regular expressions, the number of XML nodes or XML fragments in the verification point must match the number of expected nodes. The verification point returns a Pass status when all regular expressions in the XML fragment are matched.

Example

You can use a contain verification point to check that the message response contains only a specific element with a specific value. For example, consider the following message response:
<s:Envelope
 xmlns:a="http://www.w3.org/2005/08/addressing"
 xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Header>
    <a:Action
     s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
    <a:RelatesTo>uuid:ed9bc447-d739-452f-989d-cd48344d494a</a:RelatesTo>
  </s:Header>
  <s:Body>
    <s:Fault>
      <s:Code>
        <s:Value>s:Sender</s:Value>
        <s:Subcode>
          <s:Value
           xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</s:Value>
        </s:Subcode>
      </s:Code>
      <s:Reason>
        <s:Text
         xml:lang="en-US">The message could not be processed. This is most likely because the action &apos;http://Samples.ICalculator/Add&apos; is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint&apos;s binding.</s:Text>
      </s:Reason>
      <s:Node>http://www.w3.org/1999/xlink</s:Node>
      <s:Role>http://www.w3.org/1999/xlink</s:Role>
      <s:Detail
       xmlns:tns0="http://schemas.com/2003/10/Serialization/"
       xmlns:tns15="http://Samples.Windows"
       tns0:Id="id"
       tns0:Ref="idref">
        <tns15:GetCallerIdentityResponse>
          <tns15:GetCallerIdentityResult>str</tns15:GetCallerIdentityResult>
        </tns15:GetCallerIdentityResponse>
      </s:Detail>
    </s:Fault>
  </s:Body>
</s:Envelope>
To check for the Subcode element, the expected content of the contain verification point is the following XML fragment:
<s:Subcode
  xmlns:a="http://www.w3.org/2005/08/addressing"
  xmlns:s="http://www.w3.org/2003/05/soap-envelope">
   <s:Value
   xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</s:Value>
</s:Subcode>
By default, the contain verification point checks whether an element named Subcode contains one element named Value. You can use the following options:
  • Test using XML namespaces: With this option, the verification point checks whether an element named "http://www.w3.org/2003/05/soap-envelope":SubCode contains one element named "http://www.w3.org/2003/05/soap-envelope":Value.
  • Test XML text node: With this option, the verification point also checks whether the element named Value contains the text a:BadContextToken.
  • Test XML attributes: With this option, the verification point also checks that the attributes match the expected XML fragment. In this example, the Test XML attributes option is not necessary because the Subcode element does not have any attributes.
To check that the Detail element properly returns a specific value for GetCallerIdentityResult, the expected content of the contain verification point is the following XML fragment:
<s:Detail
 xmlns:a="http://www.w3.org/2005/08/addressing"
 xmlns:s="http://www.w3.org/2003/05/soap-envelope"
 xmlns:tns0="http://schemas.com/2003/10/Serialization/"
 xmlns:tns15="http://Samples.Windows"
 tns0:Id="regular_expression"
 tns0:Ref="idref">
  <tns15:GetCallerIdentityResponse>
    <tns15:GetCallerIdentityResult>IdentityValue</tns15:GetCallerIdentityResult>
  </tns15:GetCallerIdentityResponse>
</s:Detail>
You can use the following options:
  • Test XML text node: With this option, the verification point also checks whether the element named GetCallerIdentityResult contains the text IdentityValue.
  • Test XML attributes: With this option, the verification point also checks that the attribute Id referred to by tns0:Id has the expected value. You can specify a regular expression for this value by using the Regular expression column in the Tree view of the verification point. For example, tns0:Id="[a-zA-Z]" checks that the value does not contains numbers.

What to do next

You can enable or disable each verification point by right-clicking the verification point in the test editor and clicking Enable or Disable.