use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestAddChildWithExistingDocumentElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = factory.createOMDocument();
document.addChild(factory.createOMElement(new QName("root1")));
try {
document.addChild(factory.createOMElement(new QName("root2")));
fail("Expected OMException");
} catch (OMException ex) {
// Expected
}
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestGetOMDocumentElementAfterDetach method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = factory.createOMDocument();
OMElement documentElement = factory.createOMElement("root", null, document);
assertSame(documentElement, document.getOMDocumentElement());
documentElement.detach();
assertNull(document.getOMDocumentElement());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestRootPartStreaming method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
// Programmatically create the message
OMElement orgRoot = factory.createOMElement("root", null);
for (int i = 0; i < 10000; i++) {
factory.createOMElement("child", null, orgRoot).setText("Some text content");
}
// Serialize the message as XOP even if there will be no attachment parts
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
orgRoot.serialize(baos, format);
// Parse the message and monitor the number of bytes read
InstrumentedInputStream in = new InstrumentedInputStream(new ByteArrayInputStream(baos.toByteArray()));
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.DEFAULT, MultipartBody.builder().setInputStream(in).setContentType(format.getContentType()).build());
OMElement root = builder.getDocumentElement();
long count1 = in.getCount();
XMLStreamReader reader = root.getXMLStreamReader(false);
while (reader.hasNext()) {
reader.next();
}
long count2 = in.getCount();
// We expect that after requesting the document element, only a small part (corresponding to
// the size of the parser buffer) should have been read:
assertTrue(count1 < count2 / 2);
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestSetOMDocumentElementNull method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = factory.createOMDocument();
try {
document.setOMDocumentElement(null);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// Expected
}
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestInsertSibling method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", null);
OMText child = factory.createOMText(parent, "test");
OMComment orgSibling = altMetaFactory.getOMFactory().createOMComment(null, "test");
if (before) {
child.insertSiblingBefore(orgSibling);
} else {
child.insertSiblingAfter(orgSibling);
}
OMComment sibling = (OMComment) (before ? child.getPreviousOMSibling() : child.getNextOMSibling());
assertThat(sibling).isNotSameAs(orgSibling);
assertThat(sibling.getValue()).isEqualTo("test");
}
Aggregations