ca.intelliware.amakihi.validator
Class SampleReturnValueValidator

java.lang.Object
  |
  +--ca.intelliware.amakihi.validator.BaseReturnValueValidator
        |
        +--ca.intelliware.amakihi.validator.SampleReturnValueValidator
All Implemented Interfaces:
ResponseValidationStrategy

public class SampleReturnValueValidator
extends BaseReturnValueValidator

Implement a validation strategy that compares a sample of the returned data. Consider the following example:

Example

Imagine that the following output is returned by the communication handler:

  <Service>
    <returnValue>
      <foo>
        <a1>simpleText a1</a1>
        <a2>simpleText a2</a2>
        <a3>simpleText a3</a3>
      </foo>
    </returnValue>
  </Service>
 

Now, imagine that a script has been written with the following output block:

  <output>
    <returnValue format="sample">
      <foo>
        <a1>simpleText a1</a1>
        <a3>simpleText a3</a3>      
      </foo>     
    </returnValue>
  </output>
 

This script is a valid sample of the returned data. For each of the expected elements we can say that:

  1. the values of any child text nodes are correct;
  2. they are found in the right order; and
  3. they are in the right relative depth compared to their parent elements (for example, <a1> is located immediately after <foo>).

Note that the third condition implies that the expected output block must start at the highest-level node (in this case, <foo>.

Version:
$Revision: 1.2 $
Author:
Intelliware Development

Inner classes inherited from class ca.intelliware.amakihi.validator.BaseReturnValueValidator
BaseReturnValueValidator.MatchResult, BaseReturnValueValidator.NonMatchResult, BaseReturnValueValidator.PerfectMatchResult
 
Fields inherited from class ca.intelliware.amakihi.validator.BaseReturnValueValidator
containsTextRule, PRECEDENCE_ALL_MATCH, PRECEDENCE_CHILD_ELEMENT_COUNT_DOESNT_MATCH, PRECEDENCE_ELEMENT_AND_ATTRIBUTES_MATCH_BUT_TEXT_DOESNT, PRECEDENCE_ELEMENT_DOESNT_MATCH, PRECEDENCE_ELEMENT_MATCH_BUT_ATTRIBUTE_DOESNT, RULE_CONTAINS_TEXT, RULE_DONT_START_AT_TOP, RULE_DONT_VALIDATE_ATTRIBUTES, RULE_EXACT_TEXT, RULE_START_AT_TOP, RULE_VALIDATE_ATTRIBUTES
 
Constructor Summary
SampleReturnValueValidator()
           
 
Method Summary
protected  BaseReturnValueValidator.MatchResult elementsAreEqual(org.w3c.dom.Element expected, org.w3c.dom.Element actual)
          Check to see if two nodes are equal.
protected  BaseReturnValueValidator.MatchResult findMatchingActualNode(org.w3c.dom.Element actualNode, org.w3c.dom.Element expectedNode)
           
protected  BaseReturnValueValidator.MatchResult findMatchingActualNode(org.w3c.dom.Node actualNode, org.w3c.dom.Node expectedNode)
          Determines whether or not the expected value is a sample of the actualNode, or one of its following siblings and returns the matching node.
protected  BaseReturnValueValidator.MatchResult findMatchingActualTextNode(org.w3c.dom.Text actualNode, org.w3c.dom.Text expectedNode)
          Find a text node match.
protected  BaseReturnValueValidator.MatchResult findMatchingChildNodes(org.w3c.dom.Element actualNode, org.w3c.dom.Element expectedNode)
           
 
Methods inherited from class ca.intelliware.amakihi.validator.BaseReturnValueValidator
addRule, createBranchSummary, createBranchSummary, findUnmatchedAttributesIfRequired, isElementNodeOrNonWhiteSpaceTextNode, isRequiredSimplyToContainText, isRequiredToStartAtTop, isRequiredToValidateAttributes, renderAsStringExcludingTopNode, setRequiredSimplyToContainText, setRequiredToStartAtTop, setRequiredToValidateAttributes, validate, validateOutputStartAnywhere, validateOutputStartAtTop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampleReturnValueValidator

public SampleReturnValueValidator()
Method Detail

elementsAreEqual

protected BaseReturnValueValidator.MatchResult elementsAreEqual(org.w3c.dom.Element expected,
                                                                org.w3c.dom.Element actual)
Check to see if two nodes are equal. We define nodes to be sample equal if:
  1. the tag names in the expected node are found in the actual node
  2. the text values in the expected node are found in the actual node (excluding leading and/or trailing white space)
  3. all sub-elements in the expected node are found in the actual node and in the same order
Overrides:
elementsAreEqual in class BaseReturnValueValidator

findMatchingActualNode

protected BaseReturnValueValidator.MatchResult findMatchingActualNode(org.w3c.dom.Node actualNode,
                                                                      org.w3c.dom.Node expectedNode)

Determines whether or not the expected value is a sample of the actualNode, or one of its following siblings and returns the matching node.


findMatchingActualNode

protected BaseReturnValueValidator.MatchResult findMatchingActualNode(org.w3c.dom.Element actualNode,
                                                                      org.w3c.dom.Element expectedNode)

findMatchingChildNodes

protected BaseReturnValueValidator.MatchResult findMatchingChildNodes(org.w3c.dom.Element actualNode,
                                                                      org.w3c.dom.Element expectedNode)

findMatchingActualTextNode

protected BaseReturnValueValidator.MatchResult findMatchingActualTextNode(org.w3c.dom.Text actualNode,
                                                                          org.w3c.dom.Text expectedNode)

Find a text node match. Text nodes have no child nodes so we say that two text nodes match if their text data matches.



Copyright 2002 Intelliware Development. All Rights Reserved.