类 XpathExpectationsHelper

java.lang.Object
cn.taketoday.test.util.XpathExpectationsHelper

public class XpathExpectationsHelper extends Object
A helper class for applying assertions via XPath expressions.
从以下版本开始:
4.0
作者:
Rossen Stoyanchev
  • 字段详细资料

    • expression

      private final String expression
    • xpathExpression

      private final XPathExpression xpathExpression
    • hasNamespaces

      private final boolean hasNamespaces
  • 构造器详细资料

  • 方法详细资料

    • compileXpathExpression

      private static XPathExpression compileXpathExpression(String expression, @Nullable Map<String,String> namespaces) throws XPathExpressionException
      抛出:
      XPathExpressionException
    • getXpathExpression

      protected XPathExpression getXpathExpression()
      Return the compiled XPath expression.
    • assertNode

      public void assertNode(byte[] content, @Nullable String encoding, 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>.
      抛出:
      Exception
    • assertNodeList

      public void assertNodeList(byte[] content, @Nullable String encoding, org.hamcrest.Matcher<? super NodeList> matcher) throws Exception
      Parse the content, evaluate the XPath expression as a NodeList, and assert it with the given Matcher<NodeList>.
      抛出:
      Exception
      从以下版本开始:
      4.0
    • exists

      public void exists(byte[] content, @Nullable String encoding) throws Exception
      Apply the XPath expression and assert the resulting content exists.
      抛出:
      Exception - if content parsing or expression evaluation fails
    • doesNotExist

      public void doesNotExist(byte[] content, @Nullable String encoding) throws Exception
      Apply the XPath expression and assert the resulting content does not exist.
      抛出:
      Exception - if content parsing or expression evaluation fails
    • assertNodeCount

      public void assertNodeCount(byte[] content, @Nullable String encoding, org.hamcrest.Matcher<? super Integer> matcher) throws Exception
      Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.
      抛出:
      Exception - if content parsing or expression evaluation fails
    • assertNodeCount

      public void assertNodeCount(byte[] content, @Nullable String encoding, int expectedCount) throws Exception
      Apply the XPath expression and assert the resulting content as an integer.
      抛出:
      Exception - if content parsing or expression evaluation fails
    • assertString

      public void assertString(byte[] content, @Nullable String encoding, org.hamcrest.Matcher<? super String> matcher) throws Exception
      Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.
      抛出:
      Exception - if content parsing or expression evaluation fails
    • assertString

      public void assertString(byte[] content, @Nullable String encoding, String expectedValue) throws Exception
      Apply the XPath expression and assert the resulting content as a String.
      抛出:
      Exception - if content parsing or expression evaluation fails
    • assertNumber

      public void assertNumber(byte[] content, @Nullable String encoding, org.hamcrest.Matcher<? super Double> matcher) throws Exception
      Apply the XPath expression and assert the resulting content with the given Hamcrest matcher.
      抛出:
      Exception - if content parsing or expression evaluation fails
    • assertNumber

      public void assertNumber(byte[] content, @Nullable String encoding, Double expectedValue) throws Exception
      Apply the XPath expression and assert the resulting content as a Double.
      抛出:
      Exception - if content parsing or expression evaluation fails
    • assertBoolean

      public void assertBoolean(byte[] content, @Nullable String encoding, boolean expectedValue) throws Exception
      Apply the XPath expression and assert the resulting content as a Boolean.
      抛出:
      Exception - if content parsing or expression evaluation fails
    • evaluateXpath

      @Nullable public <T> T evaluateXpath(byte[] content, @Nullable String encoding, Class<T> targetClass) throws Exception
      Evaluate the XPath and return the resulting value.
      参数:
      content - the content to evaluate against
      encoding - the encoding to use (optionally)
      targetClass - the target class, one of Number, String, Boolean, org.w3c.Node, or NodeList
      抛出:
      Exception - if content parsing or expression evaluation fails
      从以下版本开始:
      4.0
    • parseXmlByteArray

      protected Document parseXmlByteArray(byte[] xml, @Nullable String encoding) throws Exception
      Parse the given XML content to a Document.
      参数:
      xml - the content to parse
      encoding - optional content encoding, if provided as metadata (e.g. in HTTP headers)
      返回:
      the parsed document
      抛出:
      Exception
    • evaluateXpath

      @Nullable protected <T> T evaluateXpath(Document document, QName evaluationType, Class<T> expectedClass) throws XPathExpressionException
      Apply the XPath expression to given document.
      抛出:
      XPathExpressionException - if expression evaluation failed
    • toQName

      private <T> QName toQName(Class<T> expectedClass)