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.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.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.
-
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.
-
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.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
-
-