BrokenEvent nanotests

com.brokenevent.nanotests
Class XmlAssert

java.lang.Object
  extended by com.brokenevent.nanotests.XmlAssert

public final class XmlAssert
extends java.lang.Object

XML-related asserts helper. These methods can be used directly: XmlAssert.assertElementContent(...), however, they read better if they are referenced through static import:

 import static com.brokenevent.nanotests.XmlAssert.*;
    ...
    assertElementContent(...);
 

Author:
BrokenEvent

Constructor Summary
protected XmlAssert()
          Protect constructor since it is a static only class
 
Method Summary
static void assertElementContent(org.w3c.dom.Document doc, java.lang.String path, java.lang.String expected)
          Asserts that the element text content is equal to the given value.
static void assertElementName(org.w3c.dom.Document doc, java.lang.String path, java.lang.String expected)
          Asserts that the element name is equal to the given value.
static void assertElementsCount(org.w3c.dom.Document doc, java.lang.String path, int expectedCount)
          Asserts that the count of the elements found by given XPath expression if equals to the given value.
static org.w3c.dom.Document loadDocument(java.lang.String content)
          Helper method to load the document from the string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlAssert

protected XmlAssert()
Protect constructor since it is a static only class

Method Detail

loadDocument

public static org.w3c.dom.Document loadDocument(java.lang.String content)
Helper method to load the document from the string.

Parameters:
content - text content of the document
Returns:
Document of the XML DOM model

assertElementContent

public static void assertElementContent(org.w3c.dom.Document doc,
                                        java.lang.String path,
                                        java.lang.String expected)
Asserts that the element text content is equal to the given value. If it isn't, an AssertionError is thrown.

Parameters:
doc - Document to check element from
path - XPath expression to find required element in DOM
expected - expected element's text content

assertElementName

public static void assertElementName(org.w3c.dom.Document doc,
                                     java.lang.String path,
                                     java.lang.String expected)
Asserts that the element name is equal to the given value. If it isn't, an AssertionError is thrown.

Parameters:
doc - Document to check element from
path - XPath expression to find required element in DOM
expected - expected element's name

assertElementsCount

public static void assertElementsCount(org.w3c.dom.Document doc,
                                       java.lang.String path,
                                       int expectedCount)
Asserts that the count of the elements found by given XPath expression if equals to the given value. If it isn't, an AssertionError is thrown.

Parameters:
doc - Document to check element from
path - XPath expression to find required element list in DOM
expectedCount - expected count of the elements

BrokenEvent nanotests