use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetDataHandlerFromElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
RandomDataSource orgDS = new RandomDataSource(64 * 1024);
OMElement orgRoot = factory.createOMElement(new QName("root"));
OMElement orgChild = factory.createOMElement(new QName("child"), orgRoot);
orgChild.addChild(factory.createOMText(new DataHandler(orgDS), false));
OMElement root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(orgRoot.toString())).getDocumentElement();
XMLStreamReader reader = root.getXMLStreamReader(cache);
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
DataSource ds = XMLStreamReaderUtils.getDataHandlerFromElement(reader).getDataSource();
IOTestUtils.compareStreams(orgDS.getInputStream(), ds.getInputStream());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetElementTextFromParser method runTest.
@Override
protected void runTest() throws Throwable {
// Note: We test getElementText on a child element ("b") of the element from which we request
// the XMLStreamReader ("a"). This is to make sure that the XMLStreamReader implementation actually
// delegates to the underlying parser (which is not necessarily the case on "a").
OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(new StringReader("<a><b>AB<!--comment text-->CD</b></a>")));
OMElement element = builder.getDocumentElement();
// Build a certain number of descendants. This is used to test scenarios where the XMLStreamReader
// needs to switch to pull through mode in the middle of the element from which we attempt to
// get the text.
Iterator<OMNode> it = element.getDescendants(true);
for (int i = 0; i < build; i++) {
it.next();
}
XMLStreamReader reader = element.getXMLStreamReader(cache);
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals("ABCD", reader.getElementText());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetNamespaceContext method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<a xmlns='urn:ns1' xmlns:ns2='urn:ns2'><b xmlns:ns3='urn:ns3'/></a>");
XMLStreamReader stream = cache ? element.getXMLStreamReader() : element.getXMLStreamReaderWithoutCaching();
stream.next();
assertEquals(XMLStreamReader.START_ELEMENT, stream.next());
assertEquals("b", stream.getLocalName());
NamespaceContext context = stream.getNamespaceContext();
assertEquals("urn:ns1", context.getNamespaceURI(""));
assertEquals("urn:ns2", context.getNamespaceURI("ns2"));
assertEquals("urn:ns3", context.getNamespaceURI("ns3"));
assertEquals("ns2", context.getPrefix("urn:ns2"));
element.close(false);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestSerializeAndConsumePartiallyBuilt method runTest.
@Override
protected void runTest() throws Throwable {
String xml = "<root><child><grandchild1>text</grandchild1></child><child><grandchild2>text</grandchild2></child></root>";
OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader(xml)).getDocumentElement();
// Partially build the tree
root.getFirstElement().getFirstElement();
StringWriter out = new StringWriter();
root.serializeAndConsume(out);
assertEquals(xml, out.toString());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestSetText method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = metaFactory.getOMFactory().createOMElement("test", null);
String text = "The quick brown fox jumps over the lazy dog";
element.setText(text);
// Check that OMElement#getText() returns a matching value
assertEquals("Text value mismatch", text, element.getText());
// Check that OMElement#setText() has created the expected nodes
OMNode child = element.getFirstOMChild();
assertTrue(child instanceof OMText);
assertSame(element, child.getParent());
assertEquals(text, ((OMText) child).getText());
assertNull(child.getNextOMSibling());
}
Aggregations