XpathExpectationsHelper (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.test.util

## Class XpathExpectationsHelper

- java.lang.Object
- - org.springframework.test.util.XpathExpectationsHelper

-     public class XpathExpectationsHelper
      extends Object

  A helper class for applying assertions via XPath expressions.
  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `XpathExpectationsHelper(String expression, Map<String,String> namespaces, Object... args)` Class constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `assertBoolean(String content, boolean expectedValue)` Apply the XPath expression and assert the resulting content as a Boolean.
    `void` | `assertNode(String content, org.hamcrest.Matcher<? super Node> matcher)` Parse the content, evaluate the XPath expression as a `Node`, and assert it with the given `Matcher<Node>`.
    `void` | `assertNodeCount(String content, int expectedCount)` Apply the XPath expression and assert the resulting content as an integer.
    `void` | `assertNodeCount(String content, org.hamcrest.Matcher<Integer> matcher)` Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.
    `void` | `assertNumber(String content, Double expectedValue)` Apply the XPath expression and assert the resulting content as a Double.
    `void` | `assertNumber(String content, org.hamcrest.Matcher<? super Double> matcher)` Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.
    `void` | `assertString(String content, org.hamcrest.Matcher<? super String> matcher)` Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.
    `void` | `assertString(String content, String expectedValue)` Apply the XPath expression and assert the resulting content as a String.
    `void` | `doesNotExist(String content)` Apply the XPath expression and assert the resulting content does not exist.
    `protected <T> T` | `evaluateXpath(Document document, QName evaluationType, Class<T> expectedClass)` Apply the XPath expression to given document.
    `void` | `exists(String content)` Apply the XPath expression and assert the resulting content exists.
    `protected XPathExpression` | `getXpathExpression()`
    `protected Document` | `parseXmlString(String xml)` Parse the given XML content to a `Document`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### XpathExpectationsHelper

          public XpathExpectationsHelper(String expression,
                                 Map<String,String> namespaces,
                                 Object... args)
                                  throws XPathExpressionException

      Class constructor.
      Parameters:
        `expression` - the XPath expression
        `namespaces` - XML namespaces referenced in the XPath expression, or `null`
        `args` - arguments to parameterize the XPath expression with using the formatting specifiers defined in `String.format(String, Object...)`
      Throws:
        `XPathExpressionException`

  - ### Method Detail

    - #### getXpathExpression

          protected XPathExpression getXpathExpression()

      Returns:
        the compiled XPath expression.

    - #### assertNode

          public void assertNode(String content,
                        org.hamcrest.Matcher<? super Node> matcher)
                          throws Exception

      Parse the content, evaluate the XPath expression as a `Node`, and assert it with the given `Matcher<Node>`.
      Throws:
        `Exception`

    - #### parseXmlString

          protected Document parseXmlString(String xml)
                                     throws Exception

      Parse the given XML content to a `Document`.
      Parameters:
        `xml` - the content to parse
      Returns:
        the parsed document
      Throws:
        `Exception` - in case of errors

    - #### evaluateXpath

          protected <T> T evaluateXpath(Document document,
                            QName evaluationType,
                            Class<T> expectedClass)
                             throws XPathExpressionException

      Apply the XPath expression to given document.
      Throws:
        `XPathExpressionException`

    - #### exists

          public void exists(String content)
                      throws Exception

      Apply the XPath expression and assert the resulting content exists.
      Throws:
        `Exception` - if content parsing or expression evaluation fails

    - #### doesNotExist

          public void doesNotExist(String content)
                            throws Exception

      Apply the XPath expression and assert the resulting content does not exist.
      Throws:
        `Exception` - if content parsing or expression evaluation fails

    - #### assertNodeCount

          public void assertNodeCount(String content,
                             org.hamcrest.Matcher<Integer> matcher)
                               throws Exception

      Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.
      Throws:
        `Exception` - if content parsing or expression evaluation fails

    - #### assertNodeCount

          public void assertNodeCount(String content,
                             int expectedCount)
                               throws Exception

      Apply the XPath expression and assert the resulting content as an integer.
      Throws:
        `Exception` - if content parsing or expression evaluation fails

    - #### assertString

          public void assertString(String content,
                          org.hamcrest.Matcher<? super String> matcher)
                            throws Exception

      Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.
      Throws:
        `Exception` - if content parsing or expression evaluation fails

    - #### assertString

          public void assertString(String content,
                          String expectedValue)
                            throws Exception

      Apply the XPath expression and assert the resulting content as a String.
      Throws:
        `Exception` - if content parsing or expression evaluation fails

    - #### assertNumber

          public void assertNumber(String content,
                          org.hamcrest.Matcher<? super Double> matcher)
                            throws Exception

      Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.
      Throws:
        `Exception` - if content parsing or expression evaluation fails

    - #### assertNumber

          public void assertNumber(String content,
                          Double expectedValue)
                            throws Exception

      Apply the XPath expression and assert the resulting content as a Double.
      Throws:
        `Exception` - if content parsing or expression evaluation fails

    - #### assertBoolean

          public void assertBoolean(String content,
                           boolean expectedValue)
                             throws Exception

      Apply the XPath expression and assert the resulting content as a Boolean.
      Throws:
        `Exception` - if content parsing or expression evaluation fails