use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestBuilderDetach method runTest.
@Override
protected void runTest() throws Throwable {
MTOMSample sample = MTOMSample.SAMPLE1;
InstrumentedInputStream in = new InstrumentedInputStream(sample.getInputStream());
MultipartBody mb = MultipartBody.builder().setInputStream(in).setContentType(sample.getContentType()).build();
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb);
SOAPEnvelope envelope = builder.getSOAPEnvelope();
long countBeforeDetach = in.getCount();
builder.detach();
assertThat(in.getCount()).isGreaterThan(countBeforeDetach);
assertThat(in.isClosed()).isFalse();
int binaryCount = 0;
for (Iterator<OMNode> it = envelope.getDescendants(false); it.hasNext(); ) {
OMNode node = it.next();
if (node instanceof OMText) {
OMText text = (OMText) node;
if (text.isBinary()) {
IOTestUtils.compareStreams(sample.getPart(text.getContentID()), text.getDataHandler().getInputStream());
binaryCount++;
}
}
}
assertThat(binaryCount).isGreaterThan(0);
in.close();
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestCreateStAXOMBuilderFromFragment method runTest.
@Override
protected void runTest() throws Throwable {
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<a><b>text</b></a>"));
// Position the reader on the event for <b>
while (reader.getEventType() != XMLStreamReader.START_ELEMENT || !reader.getLocalName().equals("b")) {
reader.next();
}
// Check that the builder only builds the part of the document corresponding to <b>text</b>
OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), reader).getDocumentElement();
assertEquals("b", element.getLocalName());
OMNode child = element.getFirstOMChild();
assertTrue(child instanceof OMText);
assertNull(element.getNextOMSibling());
// Check that the original reader is now positioned on the event just following </b>
assertEquals(XMLStreamReader.END_ELEMENT, reader.getEventType());
assertEquals("a", reader.getLocalName());
}
use of org.apache.axiom.om.OMText 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");
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestCreateOMTextCDATASectionWithParent method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("test", null);
OMText text = factory.createOMText(parent, "cdata section content", OMNode.CDATA_SECTION_NODE);
assertTrue(text instanceof CDATASection);
}
use of org.apache.axiom.om.OMText 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