You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/04/18 23:22:52 UTC
svn commit: r1739823 - in /webservices/axiom/branches/1.2.x: ./ testing/
testing/xml-truth/
testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/
testing/xml-truth/src/site/markdown/
testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/
Author: veithen
Date: Mon Apr 18 21:22:52 2016
New Revision: 1739823
URL: http://svn.apache.org/viewvc?rev=1739823&view=rev
Log:
(Partially) merge r1732654 and r1739812 to the 1.2 branch.
Added:
webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/Parsable.java
- copied unchanged from r1739812, webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/Parsable.java
webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLStreamReaderProvider.java
- copied unchanged from r1739812, webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLStreamReaderProvider.java
webservices/axiom/branches/1.2.x/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/StAXTraverserTest.java
- copied unchanged from r1739812, webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/StAXTraverserTest.java
Modified:
webservices/axiom/branches/1.2.x/ (props changed)
webservices/axiom/branches/1.2.x/testing/ (props changed)
webservices/axiom/branches/1.2.x/testing/xml-truth/ (props changed)
webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXTraverser.java
webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java
webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLTruth.java
webservices/axiom/branches/1.2.x/testing/xml-truth/src/site/markdown/index.md.vm
Propchange: webservices/axiom/branches/1.2.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Apr 18 21:22:52 2016
@@ -14,4 +14,4 @@
/webservices/axiom/branches/maven-site-plugin-3.5:1731125-1732708
/webservices/axiom/branches/namespaceURIInterning:1293148-1293587
/webservices/axiom/branches/osgi-redesign:1180368-1180596
-/webservices/axiom/trunk:1726096,1726101,1726419,1726474-1726475,1726489,1727220,1727422,1727435,1727496,1727541,1727549,1727640,1727660,1727688,1727743,1727755,1727758,1727761,1728022,1728240,1728929,1730261,1730278,1731157,1731314-1731315,1731373,1731376,1731378,1731406,1731522,1731541,1732710,1733743
+/webservices/axiom/trunk:1726096,1726101,1726419,1726474-1726475,1726489,1727220,1727422,1727435,1727496,1727541,1727549,1727640,1727660,1727688,1727743,1727755,1727758,1727761,1728022,1728240,1728929,1730261,1730278,1731157,1731314-1731315,1731373,1731376,1731378,1731406,1731522,1731541,1732710,1733743,1739812
Propchange: webservices/axiom/branches/1.2.x/testing/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Apr 18 21:22:52 2016
@@ -12,4 +12,4 @@
/webservices/axiom/branches/attrs-aspects/testing:1685218-1686663
/webservices/axiom/branches/namespaceURIInterning/testing:1293148-1293587
/webservices/axiom/branches/osgi-redesign/testing:1180368-1180596
-/webservices/axiom/trunk/testing:1726096,1726101,1726474-1726475,1726489,1727220,1727422,1727435,1727496,1727513,1727529,1727549,1727660,1727688,1728022,1728240,1728929,1731373,1731376,1731378,1731406,1731522,1731541,1732710,1733743
+/webservices/axiom/trunk/testing:1726096,1726101,1726474-1726475,1726489,1727220,1727422,1727435,1727496,1727513,1727529,1727549,1727660,1727688,1728022,1728240,1728929,1731373,1731376,1731378,1731406,1731522,1731541,1732710,1733743,1739812
Propchange: webservices/axiom/branches/1.2.x/testing/xml-truth/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Apr 18 21:22:52 2016
@@ -0,0 +1,15 @@
+/webservices/axiom/branches/AXIOM-201/testing/xml-truth:1183599-1433135
+/webservices/axiom/branches/AXIOM-399/testing/xml-truth:1329379-1331100
+/webservices/axiom/branches/AXIOM-412/testing/xml-truth:1311325-1325526
+/webservices/axiom/branches/AXIOM-420/testing/xml-truth:1334121-1336372
+/webservices/axiom/branches/AXIOM-435/testing/xml-truth:1361507-1366198
+/webservices/axiom/branches/AXIOM-437/testing/xml-truth:1364041-1364239
+/webservices/axiom/branches/AXIOM-476/testing/xml-truth:1718738-1718932
+/webservices/axiom/branches/CHECK_PARENT_BUG/testing/xml-truth:1338398-1338886
+/webservices/axiom/branches/CLONE/testing/xml-truth:1337822-1339011
+/webservices/axiom/branches/CLONE_NODE/testing/xml-truth:1346607-1353106
+/webservices/axiom/branches/JAXB2_DS/testing/xml-truth:1366463-1367737
+/webservices/axiom/branches/attrs-aspects/testing/xml-truth:1685218-1686663
+/webservices/axiom/branches/namespaceURIInterning/testing/xml-truth:1293148-1293587
+/webservices/axiom/branches/osgi-redesign/testing/xml-truth:1180368-1180596
+/webservices/axiom/trunk/testing/xml-truth:1726096,1726101,1726474-1726475,1726489,1727220,1727422,1727435,1727496,1727513,1727529,1727549,1727660,1727688,1728022,1728240,1728929,1731373,1731376,1731378,1731406,1731522,1731541,1732654,1732710,1733743,1739812
Modified: webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXTraverser.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXTraverser.java?rev=1739823&r1=1739822&r2=1739823&view=diff
==============================================================================
--- webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXTraverser.java (original)
+++ webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXTraverser.java Mon Apr 18 21:22:52 2016
@@ -34,41 +34,67 @@ import com.google.common.base.Strings;
final class StAXTraverser implements Traverser {
private final XMLStreamReader reader;
+ private int depth;
+ private boolean atStart;
StAXTraverser(XMLStreamReader reader) {
this.reader = reader;
+ switch (reader.getEventType()) {
+ case XMLStreamReader.START_DOCUMENT:
+ depth = -1;
+ break;
+ case XMLStreamReader.START_ELEMENT:
+ depth = 0;
+ atStart = true;
+ break;
+ default:
+ throw new IllegalStateException("The reader must be positioned at a START_DOCUMENT or START_ELEMENT event");
+ }
}
@Override
public Event next() throws TraverserException {
try {
- if (reader.hasNext()) {
- switch (reader.next()) {
- case XMLStreamReader.DTD:
- return Event.DOCUMENT_TYPE;
- case XMLStreamReader.START_ELEMENT:
- return Event.START_ELEMENT;
- case XMLStreamReader.END_ELEMENT:
- return Event.END_ELEMENT;
- case XMLStreamReader.CHARACTERS:
- return Event.TEXT;
- case XMLStreamReader.SPACE:
- return Event.WHITESPACE;
- case XMLStreamReader.ENTITY_REFERENCE:
- return Event.ENTITY_REFERENCE;
- case XMLStreamReader.COMMENT:
- return Event.COMMENT;
- case XMLStreamReader.CDATA:
- return Event.CDATA_SECTION;
- case XMLStreamReader.PROCESSING_INSTRUCTION:
- return Event.PROCESSING_INSTRUCTION;
- case XMLStreamReader.END_DOCUMENT:
- return null;
- default:
- throw new IllegalStateException();
+ int event;
+ if (depth == 0) {
+ if (atStart) {
+ atStart = false;
+ event = XMLStreamReader.START_ELEMENT;
+ } else {
+ event = XMLStreamReader.END_DOCUMENT;
}
} else {
- return null;
+ event = reader.hasNext() ? reader.next() : XMLStreamReader.END_DOCUMENT;
+ }
+ switch (event) {
+ case XMLStreamReader.DTD:
+ return Event.DOCUMENT_TYPE;
+ case XMLStreamReader.START_ELEMENT:
+ if (depth != -1) {
+ depth++;
+ }
+ return Event.START_ELEMENT;
+ case XMLStreamReader.END_ELEMENT:
+ if (depth != -1) {
+ depth--;
+ }
+ return Event.END_ELEMENT;
+ case XMLStreamReader.CHARACTERS:
+ return Event.TEXT;
+ case XMLStreamReader.SPACE:
+ return Event.WHITESPACE;
+ case XMLStreamReader.ENTITY_REFERENCE:
+ return Event.ENTITY_REFERENCE;
+ case XMLStreamReader.COMMENT:
+ return Event.COMMENT;
+ case XMLStreamReader.CDATA:
+ return Event.CDATA_SECTION;
+ case XMLStreamReader.PROCESSING_INSTRUCTION:
+ return Event.PROCESSING_INSTRUCTION;
+ case XMLStreamReader.END_DOCUMENT:
+ return null;
+ default:
+ throw new IllegalStateException();
}
} catch (XMLStreamException ex) {
throw new TraverserException(ex);
Modified: webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java?rev=1739823&r1=1739822&r2=1739823&view=diff
==============================================================================
--- webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java (original)
+++ webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java Mon Apr 18 21:22:52 2016
@@ -18,35 +18,30 @@
*/
package org.apache.axiom.truth.xml;
-import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
import org.apache.axiom.truth.xml.spi.Traverser;
import org.apache.axiom.truth.xml.spi.TraverserException;
import org.apache.axiom.truth.xml.spi.XML;
-import com.ctc.wstx.stax.WstxInputFactory;
+final class StAXXML implements XML {
+ private XMLStreamReaderProvider xmlStreamReaderProvider;
+
+ StAXXML(XMLStreamReaderProvider xmlStreamReaderProvider) {
+ this.xmlStreamReaderProvider = xmlStreamReaderProvider;
+ }
-abstract class StAXXML implements XML {
@Override
public boolean isReportingElementContentWhitespace() {
return true;
}
@Override
- public final Traverser createTraverser(boolean expandEntityReferences) throws TraverserException {
- WstxInputFactory factory = new WstxInputFactory();
- factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.valueOf(expandEntityReferences));
- factory.setProperty(WstxInputFactory.P_AUTO_CLOSE_INPUT, Boolean.TRUE);
- factory.setProperty(WstxInputFactory.P_REPORT_PROLOG_WHITESPACE, Boolean.TRUE);
- factory.setProperty(WstxInputFactory.P_REPORT_CDATA, Boolean.TRUE);
+ public Traverser createTraverser(boolean expandEntityReferences) throws TraverserException {
try {
- return new StAXTraverser(createXMLStreamReader(factory));
+ return new StAXTraverser(xmlStreamReaderProvider.getXMLStreamReader(expandEntityReferences));
} catch (XMLStreamException ex) {
throw new TraverserException(ex);
}
}
-
- abstract XMLStreamReader createXMLStreamReader(XMLInputFactory factory) throws XMLStreamException;
}
Modified: webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLTruth.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLTruth.java?rev=1739823&r1=1739822&r2=1739823&view=diff
==============================================================================
--- webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLTruth.java (original)
+++ webservices/axiom/branches/1.2.x/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLTruth.java Mon Apr 18 21:22:52 2016
@@ -78,12 +78,12 @@ public final class XMLTruth {
@Override
public XML createXML(final InputStream in) {
- return new StAXXML() {
+ return new StAXXML(new Parsable() {
@Override
XMLStreamReader createXMLStreamReader(XMLInputFactory factory) throws XMLStreamException {
return factory.createXMLStreamReader(in);
}
- };
+ });
}
});
factories.add(new XMLFactory<Reader>() {
@@ -94,12 +94,12 @@ public final class XMLTruth {
@Override
public XML createXML(final Reader reader) {
- return new StAXXML() {
+ return new StAXXML(new Parsable() {
@Override
XMLStreamReader createXMLStreamReader(XMLInputFactory factory) throws XMLStreamException {
return factory.createXMLStreamReader(reader);
}
- };
+ });
}
});
factories.add(new XMLFactory<StreamSource>() {
@@ -110,12 +110,12 @@ public final class XMLTruth {
@Override
public XML createXML(final StreamSource source) {
- return new StAXXML() {
+ return new StAXXML(new Parsable() {
@Override
XMLStreamReader createXMLStreamReader(XMLInputFactory factory) throws XMLStreamException {
return factory.createXMLStreamReader(source);
}
- };
+ });
}
});
factories.add(new XMLFactory<InputSource>() {
@@ -189,6 +189,25 @@ public final class XMLTruth {
return new DOMXML(element);
}
});
+ factories.add(new XMLFactory<XMLStreamReader>() {
+ @Override
+ public Class<XMLStreamReader> getExpectedType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ public XML createXML(final XMLStreamReader source) {
+ return new StAXXML(new XMLStreamReaderProvider() {
+ @Override
+ XMLStreamReader getXMLStreamReader(boolean expandEntityReferences) throws XMLStreamException {
+ if (expandEntityReferences) {
+ throw new UnsupportedOperationException("Can't expand entity references on a user supplied XMLStreamReader");
+ }
+ return source;
+ }
+ });
+ }
+ });
for (XMLFactory<?> factory : ServiceLoader.load(
XMLFactory.class, XMLTruth.class.getClassLoader())) {
factories.add(factory);
@@ -235,7 +254,7 @@ public final class XMLTruth {
}
}
if (factory == null) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("No XMLFactory found for type " + object.getClass().getName());
} else {
return createXML0(factory, object);
}
Modified: webservices/axiom/branches/1.2.x/testing/xml-truth/src/site/markdown/index.md.vm
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/1.2.x/testing/xml-truth/src/site/markdown/index.md.vm?rev=1739823&r1=1739822&r2=1739823&view=diff
==============================================================================
--- webservices/axiom/branches/1.2.x/testing/xml-truth/src/site/markdown/index.md.vm (original)
+++ webservices/axiom/branches/1.2.x/testing/xml-truth/src/site/markdown/index.md.vm Mon Apr 18 21:22:52 2016
@@ -42,6 +42,8 @@ supported:
* `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'/>");