public class DefaultComparisonFormatter extends Object implements ComparisonFormatter
Comparison
Object.Constructor and Description |
---|
DefaultComparisonFormatter() |
public String getDescription(Comparison difference)
In general the String will look like "Expected X 'Y' but was 'Z' - comparing A to B" where A and B are the
result of invoking getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
on the target and XPath of the control and test details of the
comparison. A is the description of the comparison and B and C are the control and test values (passed through
getValue(java.lang.Object, org.xmlunit.diff.ComparisonType)
) respectively.
For missing attributes the string has a slightly different format.
getDescription
in interface ComparisonFormatter
difference
- the comparison to describeprotected Object getValue(Object value, ComparisonType type)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
based on the comparison type.
This implementation returns value
unless it is a comparison of node types in which case the numeric
value (one of the constants defined in the Node
class) is mapped to a more useful String.
value
- the value to displaytype
- the comparison typeprotected String getShortString(Node node, String xpath, ComparisonType type)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
that describes the "thing" that has been compared so
users know how to locate it.
Examples are "<bar ...> at /foo[1]/bar[1]" for a comparison of elements or "<!-- Comment Text --> at /foo[2]/comment()[1]" for a comment.
This implementation dispatches to several appendX
methods based on the comparison type or the type of
the node.
node
- the node to describexpath
- xpath of the node if applicabletype
- the comparison typeprotected void appendXPath(StringBuilder sb, String xpath)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
if present.sb
- the builder to append toxpath
- the xpath to append, if anyprotected boolean appendDocumentXmlDeclaration(StringBuilder sb, Document doc)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
or appendFullDocumentHeader(java.lang.StringBuilder, org.w3c.dom.Document)
if it contains
non-default values.sb
- the builder to append toprotected void appendDocumentElementIndication(StringBuilder sb, Document doc)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append todoc
- the XML document nodeprotected boolean appendDocumentType(StringBuilder sb, DocumentType type)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
or appendFullDocumentHeader(java.lang.StringBuilder, org.w3c.dom.Document)
if present.sb
- the builder to append totype
- the document typeprotected void appendProcessingInstruction(StringBuilder sb, ProcessingInstruction instr)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toinstr
- the processing instructionprotected void appendComment(StringBuilder sb, Comment aNode)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toaNode
- the commentprotected void appendText(StringBuilder sb, Text aNode)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toaNode
- the text or CDATA nodeprotected void appendElement(StringBuilder sb, Element aNode)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toaNode
- the elementprotected void appendAttribute(StringBuilder sb, Attr aNode)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toaNode
- the attributepublic String getDetails(Comparison.Detail difference, ComparisonType type, boolean formatXml)
Comparison.Detail.getTarget()
as formatted String.
Delegates to getFullFormattedXml(org.w3c.dom.Node, org.xmlunit.diff.ComparisonType, boolean)
unless the Comparison.Detail
's target
is null.
getDetails
in interface ComparisonFormatter
difference
- The Comparison.getControlDetails()
or Comparison.getTestDetails()
.type
- the implementation can return different details depending on the ComparisonType.formatXml
- set this to true if the Comparison was generated with DiffBuilder.ignoreWhitespace()
- this affects the indentation of the generated output.protected String getFullFormattedXml(Node node, ComparisonType type, boolean formatXml)
The implementation outputs the document prolog and start element for Document
and DocumentType
nodes and may elect to format the node's parent element rather than just the node depending on the node and
comparison type. It delegates to appendFullDocumentHeader(java.lang.StringBuilder, org.w3c.dom.Document)
or getFormattedNodeXml(org.w3c.dom.Node, boolean)
.
node
- the node to formattype
- the comparison typeformatXml
- true if the Comparison was generated with DiffBuilder.ignoreWhitespace()
- this affects the indentation of the generated outputprotected void appendFullDocumentHeader(StringBuilder sb, Document doc)
getFullFormattedXml(org.w3c.dom.Node, org.xmlunit.diff.ComparisonType, boolean)
.sb
- the builder to append todoc
- the document to formatprotected String getFormattedNodeXml(Node nodeToConvert, boolean formatXml)
nodeToConvert
- the node to formatformatXml
- true if the Comparison was generated with DiffBuilder.ignoreWhitespace()
- this affects the indentation of the generated outputprotected Transformer createXmlTransformer(int numberOfBlanksToIndent) throws TransformerConfigurationException
numberOfBlanksToIndent
- the number of spaces which is used for indent the XML-structureTransformerConfigurationException
Copyright © 2001–2019 XMLUnit. All rights reserved.