| ## |
| ## Licensed to the Apache Software Foundation (ASF) under one |
| ## or more contributor license agreements. See the NOTICE file |
| ## distributed with this work for additional information |
| ## regarding copyright ownership. The ASF licenses this file |
| ## 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. |
| ## |
| |
| Introduction |
| ------------ |
| |
| This `xml-truth` module provides a [Google Truth](https://github.com/google/truth) extension to |
| compare XML data. It can be used as an alternative to [XMLUnit](http://www.xmlunit.org/). The basic |
| usage is as follows: |
| |
| assertAbout(xml()).that(actual).hasSameContentAs(expected); |
| |
| This relies on the following static imports being present: |
| |
| import static com.google.common.truth.Truth.assertAbout; |
| import static org.apache.axiom.truth.xml.XMLTruth.xml; |
| |
| `actual` and `expected` are objects that represent XML data. The following types are currently |
| supported: |
| |
| * `InputStream`, `Reader`, `String` and `byte[]` with XML data to be parsed |
| |
| * `javax.xml.transform.stream.StreamSource` and `org.xml.sax.InputSource` |
| |
| * DOM `Document` or `Element` nodes |
| |
| * `java.net.URL` |
| |
| * `javax.xml.stream.XMLStreamReader` |
| |
| By default, comparison is strict. E.g. the following assertion would fail: |
| |
| assertAbout(xml()).that("<p:a xmlns:p='urn:ns'/>").hasSameContentAs("<a xmlns='urn:ns'/>"); |
| |
| To control how the comparison is performed, use the relevant methods on the |
| [`XMLSubject`](apidocs/org/apache/axiom/truth/xml/XMLSubject.html) object returned by `that()`: |
| |
| <!-- MACRO{snippet|id=sample|file=${project.basedir}/src/test/java/org/apache/axiom/truth/xml/XMLSubjectTest.java} --> |