Class XmlSnapshot

  • All Implemented Interfaces:
    StructuredDataProvider

    @API(status=STABLE)
    public final class XmlSnapshot
    extends Object
    implements StructuredDataProvider
    StructuredData builder for serializing test results to XML, relying on JAXB and XML-Unit.

    You can either use a pre-configured default instance via xml or use any of the static factory methods to customize the construction.

    Author:
    Simon Taddiken
    • Field Detail

      • xml

        public static final StructuredDataProvider xml
        Simple default StructuredData instance which infers the JAXB context from a test's actual result object.

        If you need control over how the JAXBContext and the Marshaller are being set up, use the static factory methods in XmlSnapshot instead 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 - Use xml() 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 XML StructuredDataProvider which will try to infer the JAXBContext from 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 - Use withJAXBContext(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 given JAXBContext instead 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 the Marshaller which 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 to CompareAssert.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 use CompareAssert.withDifferenceEvaluator(DifferenceEvaluator) here, as your DifferenceEvaluator will always be overridden by the one that is configured in withComparisonRules(Consumer).

        Parameters:
        xmls - Consumes the CompareAssert which 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 ComparisonRuleBuilder must conform to standard XPath syntax.

        Note: This will customize the DifferenceEvaluator that is used. Thus you can not use this method in combination with withComparisonRules(Consumer) if you intend to use an own DifferenceEvaluator.

        Parameters:
        rules - A consumer to which a ComparisonRuleBuilder will be passed.
        Returns:
        This instance.
        Since:
        1.3.0