org.xmlunit.builder.DifferenceEngineConfigurer Maven / Gradle / Ivy
/*
This file is licensed to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xmlunit.builder;
import java.util.Map;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
import org.xmlunit.diff.ComparisonController;
import org.xmlunit.diff.ComparisonControllers;
import org.xmlunit.diff.ComparisonFormatter;
import org.xmlunit.diff.ComparisonListener;
import org.xmlunit.diff.ComparisonResult;
import org.xmlunit.diff.DifferenceEngine;
import org.xmlunit.diff.DifferenceEvaluator;
import org.xmlunit.diff.DifferenceEvaluators;
import org.xmlunit.diff.NodeMatcher;
import org.xmlunit.util.Predicate;
/**
* Subset of the configuration options available for a {@link DifferenceEngine}.
* @since 2.6.0
*/
public interface DifferenceEngineConfigurer> {
/**
* Sets the strategy for selecting nodes to compare.
*
* Example with {@link org.xmlunit.diff.DefaultNodeMatcher}:
*
* .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
*
*
* This overwrites any {@link NodeMatcher} set via earlier invocations of {@code withNodeMatcher}.
*
* @see org.xmlunit.diff.DifferenceEngine#setNodeMatcher(NodeMatcher)
* @param nodeMatcher the NodeMatcher to use
* @return this
*/
D withNodeMatcher(NodeMatcher nodeMatcher);
/**
* Provide your own custom {@link DifferenceEvaluator} implementation.
* This overwrites the Default DifferenceEvaluator.
*
* If you want use your custom DifferenceEvaluator in
* combination with the default or another DifferenceEvaluator you
* should use {@link
* DifferenceEvaluators#chain(DifferenceEvaluator...)} or {@link
* DifferenceEvaluators#first(DifferenceEvaluator...)} to combine
* them:
*
*
* .withDifferenceEvaluator(
* DifferenceEvaluators.chain(
* DifferenceEvaluators.Default,
* new MyCustomDifferenceEvaluator()))
* ....
*
*
* This overwrites any {@link DifferenceEvaluator} set via earlier invocations of {@code
* withDifferenceEvaluator}.
*
* @param differenceEvaluator the DifferenceEvaluator to use
* @return this
*/
D withDifferenceEvaluator(DifferenceEvaluator differenceEvaluator);
/**
* Replace the {@link ComparisonControllers#Default} with your own ComparisonController.
*
* Example use:
*
* .withComparisonController(ComparisonControllers.StopWhenDifferent)
*
*
* This overwrites any {@link ComparisonController} set via earlier invocations of {@code withComparisonController}.
*
* @param comparisonController ComparisonController to use
* @return this
*/
D withComparisonController(ComparisonController comparisonController);
/**
* Registers listeners that are notified of each comparison.
*
* @see org.xmlunit.diff.DifferenceEngine#addComparisonListener(ComparisonListener)
*
* This overwrites any {@link ComparisonListener}s set via earlier invocations of {@code withComparisonListeners}.
*
* @param comparisonListeners ComparisonListeners to use
* @return this
*/
D withComparisonListeners(ComparisonListener... comparisonListeners);
/**
* Registers listeners that are notified of each comparison with
* outcome other than {@link ComparisonResult#EQUAL}.
*
* This overwrites any {@link ComparisonListener}s set via earlier invocations of {@code withDifferenceListeners}.
*
* @see org.xmlunit.diff.DifferenceEngine#addDifferenceListener(ComparisonListener)
*
* @param comparisonListeners ComparisonListeners to use
* @return this
*/
D withDifferenceListeners(ComparisonListener... comparisonListeners);
/**
* Establish a namespace context that will be used in {@link
* org.xmlunit.diff.Comparison.Detail#getXPath Comparison.Detail#getXPath}.
*
* Without a namespace context (or with an empty context) the
* XPath expressions will only use local names for elements and
* attributes.
*
* This overwrites any {@link Map} set via earlier invocations of {@code withNamespaceContext}.
*
* @param prefix2Uri mapping between prefix and namespace URI
* @return this
*/
D withNamespaceContext(Map prefix2Uri);
/**
* Registers a filter for attributes.
*
* Only attributes for which the predicate returns true are
* part of the comparison. By default all attributes are
* considered.
*
* The "special" namespace, namespace-location and
* schema-instance-type attributes can not be ignored this way.
* If you want to suppress comparison of them you'll need to
* implement {@link DifferenceEvaluator}.
*
* This overwrites any {@link Predicate} set via earlier invocations of {@code withAttributeFilter}.
*
* @param attributeFilter attribute filter to use
* @return this
*/
D withAttributeFilter(Predicate attributeFilter);
/**
* Registers a filter for nodes.
*
* Only nodes for which the predicate returns true are part of
* the comparison. By default nodes that are not document types
* are considered.
*
* This overwrites any {@link Predicate} set via earlier invocations of {@code withNodeFilter}.
*
* @param nodeFilter node filter to use
* @return this
*/
D withNodeFilter(Predicate nodeFilter);
/**
* Sets a non-default formatter for the differences found.
*
* This overwrites any {@link ComparisonFormatter} set via earlier invocations of {@code
* withComparisonFormatter}.
*
* @param formatter formatter to use
* @return this
*/
D withComparisonFormatter(ComparisonFormatter formatter);
}