Author: scheu
Date: Tue May 13 13:27:00 2008
New Revision: 655996
URL: http://svn.apache.org/viewvc?rev=655996&view=rev
Log:
Quick Fix.
Contributor:Rich Scheuerle
When I contributed this test I did not realize that other XMLStreamReaders may
interpret javax.xml.stream.isCoalescing differently. So I divided the test
into two new tests...one that uses a parser built om tree, and the other uses a
programatically built tree. The parser built test only has CDATA asserts iff
the parser is woodstox.
Thanks,
Rich
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperTest.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperTest.java?rev=655996&r1=655995&r2=655996&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMStAXWrapperTest.java
Tue May 13 13:27:00 2008
@@ -19,6 +19,7 @@
package org.apache.axiom.om.impl.llom;
import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.util.Arrays;
import javax.xml.stream.XMLInputFactory;
@@ -28,20 +29,54 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
import org.apache.axiom.om.util.StAXUtils;
public class OMStAXWrapperTest extends TestCase {
// Regression test for WSCOMMONS-338 and WSCOMMONS-341
- public void testCDATAEvent() throws Exception {
+ public void testCDATAEvent_FromParser() throws Exception {
// Make sure that the parser is non coalescing (otherwise no CDATA
events will be
// reported). This is not the default for Woodstox (see WSTX-140).
-
StAXUtils.getXMLInputFactory().setProperty(XMLInputFactory.IS_COALESCING,
Boolean.FALSE);
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
// Create an element with a CDATA section.
- XMLStreamReader reader = StAXUtils.createXMLStreamReader(new
ByteArrayInputStream("<test><![CDATA[test]]></test>".getBytes()));
- OMFactory factory = new OMLinkedListImplFactory();
- OMElement element = new StAXOMBuilder(factory,
reader).getDocumentElement();
+ InputStream is = new ByteArrayInputStream("<test><![CDATA[hello
world]]></test>".getBytes());
+ XMLStreamReader reader = factory.createXMLStreamReader(is);
+
+ OMFactory omfactory = new OMLinkedListImplFactory();
+ OMElement element = new StAXOMBuilder(omfactory,
reader).getDocumentElement();
+
+ // Build the element so we have a full StAX tree
+ element.build();
+
+ // Get the XMLStreamReader for the element. This will return an
OMStAXWrapper.
+ XMLStreamReader reader2 = element.getXMLStreamReader();
+ // Check the sequence of events
+ int event = reader2.next();
+ assertEquals(XMLStreamReader.START_ELEMENT, event);
+
+ while (reader2.hasNext() && event != XMLStreamReader.CDATA) {
+ event = reader2.next();
+ }
+
+ // Only woodstox is guaranteed to generate CDATA events if
javax.xml.stream.isCoalescing=false
+ if (reader.toString().contains("wstx")) {
+ assertEquals(XMLStreamReader.CDATA, event);
+ assertEquals("test", reader2.getText()); // WSCOMMONS-341
+ assertTrue(Arrays.equals("hello world".toCharArray(),
reader2.getTextCharacters())); // WSCOMMONS-338
+ assertEquals(XMLStreamReader.END_ELEMENT, reader2.next());
+ }
+ }
+
+ public void testCDATAEvent_FromElement() throws Exception {
+ OMFactory omfactory = new OMLinkedListImplFactory();
+ OMElement element = omfactory.createOMElement("test", null);
+ OMText cdata = omfactory.createOMText("hello world",
OMNode.CDATA_SECTION_NODE);
+ element.addChild(cdata);
+
// Get the XMLStreamReader for the element. This will return an
OMStAXWrapper.
XMLStreamReader reader2 = element.getXMLStreamReader();
// Check the sequence of events
@@ -53,8 +88,8 @@
}
assertEquals(XMLStreamReader.CDATA, event);
- assertEquals("test", reader2.getText()); // WSCOMMONS-341
- assertTrue(Arrays.equals("test".toCharArray(),
reader2.getTextCharacters())); // WSCOMMONS-338
+ assertEquals("hello world", reader2.getText()); // WSCOMMONS-341
+ assertTrue(Arrays.equals("hello world".toCharArray(),
reader2.getTextCharacters())); // WSCOMMONS-338
assertEquals(XMLStreamReader.END_ELEMENT, reader2.next());
}
}