Search in sources :

Example 1 with WrappedTextNodeStreamReader

use of org.apache.axiom.util.stax.WrappedTextNodeStreamReader in project webservices-axiom by apache.

the class WrappedTextNodeStreamReaderTest method testUsingBuilder.

//
// Tests that construct the Axiom tree and check the result
//
private void testUsingBuilder(QName wrapperElementName, String testString, int chunkSize) {
    StringReader reader = new StringReader(testString);
    XMLStreamReader xmlStreamReader = new WrappedTextNodeStreamReader(wrapperElementName, reader, chunkSize);
    OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(xmlStreamReader).getDocumentElement();
    assertEquals(wrapperElementName, element.getQName());
    assertEquals(wrapperElementName.getPrefix(), element.getQName().getPrefix());
    assertEquals(testString, element.getText());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) WrappedTextNodeStreamReader(org.apache.axiom.util.stax.WrappedTextNodeStreamReader)

Example 2 with WrappedTextNodeStreamReader

use of org.apache.axiom.util.stax.WrappedTextNodeStreamReader in project webservices-axiom by apache.

the class WrappedTextNodeStreamReaderTest method testUsingSerializeAndConsume.

//
// Tests that construct the Axiom tree, serialize it using serializeAndConsume and
// compare with the expected result.
//
private void testUsingSerializeAndConsume(QName wrapperElementName, String testString, int chunkSize, String expectedXML) throws Exception {
    StringReader reader = new StringReader(testString);
    XMLStreamReader xmlStreamReader = new WrappedTextNodeStreamReader(wrapperElementName, reader, chunkSize);
    OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(xmlStreamReader).getDocumentElement();
    StringWriter writer = new StringWriter();
    element.serializeAndConsume(writer);
    assertAbout(xml()).that(writer.toString()).hasSameContentAs(expectedXML);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) WrappedTextNodeStreamReader(org.apache.axiom.util.stax.WrappedTextNodeStreamReader)

Aggregations

StringReader (java.io.StringReader)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 OMElement (org.apache.axiom.om.OMElement)2 WrappedTextNodeStreamReader (org.apache.axiom.util.stax.WrappedTextNodeStreamReader)2 StringWriter (java.io.StringWriter)1