use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestInsertSiblingBefore method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory fac = metaFactory.getOMFactory();
OMElement parent = fac.createOMElement("test", null);
OMText text1 = fac.createOMText("text1");
OMText text2 = fac.createOMText("text2");
parent.addChild(text1);
text1.insertSiblingBefore(text2);
assertSame(parent, text2.getParent());
assertSame(text2, parent.getFirstOMChild());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestGetDescendants method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMContainer root = containerFactory.create(factory);
OMElement child1 = factory.createOMElement("child", null, root);
OMProcessingInstruction child2 = factory.createOMProcessingInstruction(root, "test", "data");
OMText grandchild1 = factory.createOMText(child1, "text");
OMComment grandchild2 = factory.createOMComment(child1, "text");
Iterator<? extends OMSerializable> it = root.getDescendants(includeSelf);
if (includeSelf) {
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(root);
}
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(child1);
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(grandchild1);
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(grandchild2);
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isEqualTo(child2);
assertThat(it.hasNext()).isFalse();
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestReadAttachmentBeforeRootPartComplete method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
// Programmatically create the message
OMElement orgRoot = factory.createOMElement("root", null);
OMElement orgChild1 = factory.createOMElement("child1", null, orgRoot);
DataSource ds = new RandomDataSource(54321, 4096);
orgChild1.addChild(factory.createOMText(new DataHandler(ds), true));
// Create a child with a large text content and insert it after the binary node.
// If we don't do this, then the root part may be buffered entirely by the parser,
// and the test would not be effective.
OMElement orgChild2 = factory.createOMElement("child2", null, orgRoot);
String s = RandomUtils.randomString(128 * 1024);
orgChild2.setText(s);
// Serialize the message
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
orgRoot.serialize(out, format);
out.close();
// Parse the message
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.NON_COALESCING, MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build());
OMElement root = builder.getDocumentElement();
OMElement child1 = (OMElement) root.getFirstOMChild();
OMText text = (OMText) child1.getFirstOMChild();
assertTrue(text.isBinary());
// Access the DataHandler
DataHandler dh = text.getDataHandler();
IOTestUtils.compareStreams(ds.getInputStream(), dh.getInputStream());
OMElement child2 = (OMElement) child1.getNextOMSibling();
assertFalse(child2.isComplete());
assertEquals(s, child2.getText());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestSetTextWithExistingChildren method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
// Add some children of various types
factory.createOMText(element, "some text");
factory.createOMText(element, "cdata section", OMNode.CDATA_SECTION_NODE);
factory.createOMComment(element, "comment");
factory.createOMProcessingInstruction(element, "piTarget", "piData");
factory.createOMElement("child", null, element);
// Set the text; this should remove all child nodes
element.setText("test");
// Check that OMElement#getText() returns a matching value
assertEquals("Text value mismatch", "test", element.getText());
// Check that OMElement#setText() has created the expected nodes
OMNode child = element.getFirstOMChild();
assertTrue(child instanceof OMText);
assertSame(element, child.getParent());
assertEquals("test", ((OMText) child).getText());
assertNull(child.getNextOMSibling());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestBase64StreamingWithSerialize method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement elem = factory.createOMElement("test", null);
// Create a data source that would eat up all memory when loaded. If the test
// doesn't fail with an OutOfMemoryError, we know that the OMText implementation
// supports streaming.
DataSource ds = new TestDataSource('A', Runtime.getRuntime().maxMemory());
OMText text = factory.createOMText(new DataHandler(ds), false);
elem.addChild(text);
elem.serialize(new NullOutputStream());
}
Aggregations