Class XmlSnapshot
- java.lang.Object
-
- de.skuzzle.test.snapshots.data.xml.XmlSnapshot
-
- All Implemented Interfaces:
StructuredDataProvider
@API(status=STABLE) public final class XmlSnapshot extends Object implements StructuredDataProvider
StructuredDatabuilder for serializing test results to XML, relying on JAXB and XML-Unit.You can either use a pre-configured default instance via
xmlor use any of the static factory methods to customize the construction.- Author:
- Simon Taddiken
-
-
Field Summary
Fields Modifier and Type Field Description static StructuredDataProviderxmlSimple defaultStructuredDatainstance which infers the JAXB context from a test's actual result object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description StructuredDatabuild()XmlSnapshotcompareUsing(Consumer<org.xmlunit.assertj.CompareAssert> xmls)Defines which Xml-Assert assertion method will actually be used.static XmlSnapshotinferJaxbContext()Deprecated, for removal: This API element is subject to removal in a future version.Since 1.4.0 - Usexml()instead.static XmlSnapshotwith(javax.xml.bind.JAXBContext jaxbContext)Deprecated, for removal: This API element is subject to removal in a future version.Since 1.4.0 - UsewithJAXBContext(JAXBContext)instead.XmlSnapshotwithComparisonRules(Consumer<ComparisonRuleBuilder> rules)Allows to specify extra comparison rules that are applied to certain paths within the xml snapshots.XmlSnapshotwithEnableXPathDebugging(boolean enableXPathDebugging)Enables a simple debug output to System.out for the xpaths that are used inwithComparisonRules(Consumer).XmlSnapshotwithJAXBContext(javax.xml.bind.JAXBContext jaxbContext)Uses the givenJAXBContextinstead of trying to infer it from the test result.XmlSnapshotwithMarshaller(de.skuzzle.test.snapshots.data.xml.XmlSnapshot.MarshallerSupplier marshallerSupplier)Supplies theMarshallerwhich will be used to serialize the snapshot to xml.XmlSnapshotwithPrettyPrintStringXml(boolean prettyPrintStringXml)Only taken into account if you directly pass a String into the snapshot test which is already a XML is does not need to be serialized.static XmlSnapshotxml()Creates a new XMLStructuredDataProviderwhich will try to infer theJAXBContextfrom the actual test result.
-
-
-
Field Detail
-
xml
public static final StructuredDataProvider xml
Simple defaultStructuredDatainstance which infers the JAXB context from a test's actual result object.If you need control over how the
JAXBContextand theMarshallerare being set up, use the static factory methods inXmlSnapshotinstead of this static constant.- See Also:
xml()
-
-
Method Detail
-
inferJaxbContext
@Deprecated(since="1.4.0", forRemoval=true) @API(status=DEPRECATED, since="1.4.0") public static XmlSnapshot inferJaxbContext()
Deprecated, for removal: This API element is subject to removal in a future version.Since 1.4.0 - Usexml()instead.Tries to infer the JAXBContext from the passed in actual test result.- Returns:
- A builder for building
StructuredData.
-
xml
@API(status=STABLE, since="1.4.0") public static XmlSnapshot xml()Creates a new XMLStructuredDataProviderwhich will try to infer theJAXBContextfrom the actual test result.- Returns:
- A builder for building
StructuredData. - Since:
- 1.4.0
-
with
@Deprecated(since="1.4.0", forRemoval=true) @API(status=DEPRECATED, since="1.4.0") public static XmlSnapshot with(javax.xml.bind.JAXBContext jaxbContext)
Deprecated, for removal: This API element is subject to removal in a future version.Since 1.4.0 - UsewithJAXBContext(JAXBContext)instead.Uses the given JAXBContext as entry point for serializing snapshots.- Parameters:
jaxbContext- The JAXBContext to use.- Returns:
- A builder for building
StructuredData.
-
withJAXBContext
public XmlSnapshot withJAXBContext(javax.xml.bind.JAXBContext jaxbContext)
Uses the givenJAXBContextinstead of trying to infer it from the test result.- Parameters:
jaxbContext- The JAXBContext to use.- Returns:
- This builder instance.
-
withMarshaller
public XmlSnapshot withMarshaller(de.skuzzle.test.snapshots.data.xml.XmlSnapshot.MarshallerSupplier marshallerSupplier)
Supplies theMarshallerwhich will be used to serialize the snapshot to xml.- Parameters:
marshallerSupplier- The supplier.- Returns:
- This builder instance.
-
withPrettyPrintStringXml
@API(status=EXPERIMENTAL, since="1.6.0") public XmlSnapshot withPrettyPrintStringXml(boolean prettyPrintStringXml)Only taken into account if you directly pass a String into the snapshot test which is already a XML is does not need to be serialized. In this case, you can advise the framework to pretty print the passed in string before persisting it as a snapshot.For non-xml input (java classes that need to be serialized), pretty printing can be controlled via cusomization of the marshaller using
withMarshaller(MarshallerSupplier).Defaults to true.
- Parameters:
prettyPrintStringXml- Whether to pretty print XML strings.- Returns:
- This build instance.
- Since:
- 1.6.0
-
compareUsing
@API(status=EXPERIMENTAL) public XmlSnapshot compareUsing(Consumer<org.xmlunit.assertj.CompareAssert> xmls)
Defines which Xml-Assert assertion method will actually be used. Defaults toCompareAssert.areIdentical().You can also use this to apply further customizations to the CompareAssert. Consult the xml-unit documentation for further information.
Note: if you also use
withComparisonRules(Consumer), you can not useCompareAssert.withDifferenceEvaluator(DifferenceEvaluator)here, as your DifferenceEvaluator will always be overridden by the one that is configured in withComparisonRules(Consumer).- Parameters:
xmls- Consumes theCompareAssertwhich compares the actual and expected xml.- Returns:
- This builder instance.
-
withEnableXPathDebugging
@API(status=EXPERIMENTAL, since="1.6.0") public XmlSnapshot withEnableXPathDebugging(boolean enableXPathDebugging)Enables a simple debug output to System.out for the xpaths that are used inwithComparisonRules(Consumer). This will print out all the nodes that are matched by the xpaths that are used in custom comparison rules.Note that this method must be called before calling
withComparisonRules(Consumer).- Parameters:
enableXPathDebugging- Whether to enable debug output for xpaths used inwithComparisonRules(Consumer).- Returns:
- This instance.
- Since:
- 1.6.0
-
withComparisonRules
@API(status=EXPERIMENTAL, since="1.3.0") public XmlSnapshot withComparisonRules(Consumer<ComparisonRuleBuilder> rules)Allows to specify extra comparison rules that are applied to certain paths within the xml snapshots.Paths on the
ComparisonRuleBuildermust conform to standard XPath syntax. You can enable debug output for xpath expressions usingwithEnableXPathDebugging(boolean). Note that debug output must be enabled before calling this method.Note: This will customize the
DifferenceEvaluatorthat is used. Thus you can not use this method in combination withwithComparisonRules(Consumer)if you intend to use an ownDifferenceEvaluator.- Parameters:
rules- A consumer to which aComparisonRuleBuilderwill be passed.- Returns:
- This instance.
- Since:
- 1.3.0
-
build
public StructuredData build()
- Specified by:
buildin interfaceStructuredDataProvider
-
-