use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestCloneBinary method runTest.
@Override
protected void runTest() throws Throwable {
DataHandler dh = new DataHandler(new RandomDataSource(600613L, 4096));
StringReader rootPart = new StringReader("<root><xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include' href='cid:123456@example.org'/></root>");
DummyAttachmentAccessor attachmentAccessor = new DummyAttachmentAccessor("123456@example.org", dh);
OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StreamSource(rootPart), attachmentAccessor).getDocumentElement();
OMText text = (OMText) root.getFirstOMChild();
OMCloneOptions options = new OMCloneOptions();
options.setFetchDataHandlers(fetch);
OMText clone = (OMText) text.clone(options);
assertTrue(clone.isBinary());
assertEquals(fetch, attachmentAccessor.isLoaded());
assertSame(dh, clone.getDataHandler());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestGetNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("element", null);
element.declareNamespace("urn:ns", "p");
OMText text = factory.createOMText(element, "p:value");
OMNamespace ns = text.getNamespace();
assertEquals("urn:ns", ns.getNamespaceURI());
assertEquals("p", ns.getPrefix());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class TestSetOptimize method runTest.
@Override
protected void runTest() throws Throwable {
InputStream in = XOP_SPEC_SAMPLE.getInputStream();
try {
OMDocument document = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, MultipartBody.builder().setInputStream(in).setContentType(XOP_SPEC_SAMPLE.getContentType()).build()).getDocument();
for (Iterator<OMSerializable> it = document.getDescendants(false); it.hasNext(); ) {
OMSerializable node = it.next();
if (node instanceof OMText) {
OMText text = (OMText) node;
if (text.isBinary()) {
text.setOptimize(optimize);
}
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
document.serialize(out, format);
Multipart mp = new MimeMultipart(new ByteArrayDataSource(out.toByteArray(), format.getContentType()));
assertThat(mp.getCount()).isEqualTo(optimize ? 3 : 1);
} finally {
in.close();
}
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class WriteCharactersCharArrayScenario method validate.
@Override
public void validate(OMElement element, boolean dataHandlersPreserved) {
OMNode child = element.getFirstOMChild();
Assert.assertTrue(child instanceof OMText);
Assert.assertEquals("test", ((OMText) child).getText());
child = child.getNextOMSibling();
Assert.assertTrue(child instanceof OMText);
Assert.assertEquals("case", ((OMText) child).getText());
Assert.assertNull(child.getNextOMSibling());
}
use of org.apache.axiom.om.OMText in project webservices-axiom by apache.
the class WriteDataHandlerProviderScenario method validate.
@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
OMText child = (OMText) element.getFirstOMChild();
if (dataHandlersPreserved) {
Assert.assertTrue(child.isBinary());
Assert.assertSame(dh, child.getDataHandler());
} else {
child.setBinary(true);
IOTestUtils.compareStreams(dh.getInputStream(), child.getDataHandler().getInputStream());
}
}
Aggregations