use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestSerializeAndConsumeWithIncompleteDescendant method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement incompleteElement = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocumentElement(true);
OMDocument document = factory.createOMDocument();
OMElement root = factory.createOMElement("root", null, document);
root.addChild(incompleteElement);
StringWriter out = new StringWriter();
document.serializeAndConsume(out);
assertAbout(xml()).that(out.toString()).hasSameContentAs("<root><elem>text</elem></root>");
assertConsumed(incompleteElement);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestIOExceptionInGetText method runTest.
@Override
protected void runTest() throws Throwable {
// Construct a stream that will throw an exception in the middle of a text node.
// We need to create a very large document, because some parsers (such as some
// versions of XLXP) have a large input buffer and would throw an exception already
// when the XMLStreamReader is created.
StringBuffer xml = new StringBuffer("<root>");
for (int i = 0; i < 100000; i++) {
xml.append('x');
}
InputStream in = new ExceptionInputStream(new ByteArrayInputStream(xml.toString().getBytes("ASCII")));
XMLStreamReader originalReader = StAXUtils.createXMLStreamReader(in);
InvocationCounter invocationCounter = new InvocationCounter();
XMLStreamReader reader = (XMLStreamReader) invocationCounter.createProxy(originalReader);
OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), reader).getDocumentElement();
try {
element.getNextOMSibling();
fail("Expected exception");
} catch (Exception ex) {
// Expected
}
assertTrue(invocationCounter.getInvocationCount() > 0);
invocationCounter.reset();
try {
element.getNextOMSibling();
fail("Expected exception");
} catch (Exception ex) {
// Expected
}
assertEquals(0, invocationCounter.getInvocationCount());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestDetachWithDOM method runTest.
@Override
protected void runTest() throws Throwable {
Document document = DOMImplementation.XERCES.newDocument();
Element root = document.createElementNS("", "root");
root.appendChild(document.createElementNS("", "a"));
OMXMLParserWrapper builder;
if (useDOMSource) {
builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new DOMSource(root));
} else {
builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), root, false);
}
OMElement omRoot = builder.getDocumentElement();
builder.detach();
root.appendChild(document.createElementNS("", "b"));
assertThat(omRoot).hasNumberOfChildren(1);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetDocumentElement method runTest.
@Override
protected void runTest() throws Throwable {
OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(new StringReader("<!--comment1--><root/><!--comment2-->")));
OMElement element;
if (discardDocument == null) {
element = builder.getDocumentElement();
} else {
element = builder.getDocumentElement(discardDocument.booleanValue());
}
assertNotNull("Document element can not be null", element);
assertEquals("Name of the document element is wrong", "root", element.getLocalName());
if (Boolean.TRUE.equals(discardDocument)) {
if (builderFactory.isDeferredParsing()) {
assertFalse(element.isComplete());
}
assertNull(element.getParent());
// Note: we can't test getNextOMSibling here because this would build the element
assertNull(element.getPreviousOMSibling());
OMElement newParent = element.getOMFactory().createOMElement("newParent", null);
newParent.addChild(element);
if (builderFactory.isDeferredParsing()) {
assertFalse(element.isComplete());
assertFalse(builder.isCompleted());
}
assertAbout(xml()).that(xml(OMElement.class, newParent)).hasSameContentAs("<newParent><root/></newParent>");
assertTrue(element.isComplete());
// Since we discarded the document, the nodes in the epilog will not be accessible.
// Therefore we expect that when the document element changes its completion status,
// the builder will consume the epilog and change its completion status as well.
// This gives the underlying parser a chance to release some resources.
assertTrue(builder.isCompleted());
} else {
// The getDocumentElement doesn't detach the document element from the document:
assertSame(builder.getDocument(), element.getParent());
assertSame(builder.getDocument().getOMDocumentElement(), element);
assertTrue(element.getPreviousOMSibling() instanceof OMComment);
assertTrue(element.getNextOMSibling() instanceof OMComment);
}
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetDocumentElementWithDiscardDocumentIllFormedEpilog method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root/> there shouldn't be text here!"));
OMElement element = builder.getDocumentElement(true);
try {
element.build();
fail("Expected OMException");
} catch (OMException ex) {
// Expected
}
}
Aggregations