use of org.apache.axiom.om.OMDataSource in project webservices-axiom by apache.
the class TestWrappedTextNodeOMDataSourceFromReader method runTest.
@Override
protected void runTest() throws Throwable {
Random random = new Random();
StringBuilder buffer = new StringBuilder(40000);
for (int i = 0; i < 40000; i++) {
buffer.append((char) (32 + random.nextInt(96)));
}
String testData = buffer.toString();
QName qname = new QName("data");
OMDataSource ds = new WrappedTextNodeOMDataSourceFromReader(qname, new StringReader(testData));
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(ds, qname);
assertEquals(testData, element.getText());
}
use of org.apache.axiom.om.OMDataSource in project webservices-axiom by apache.
the class FirstElementNameWithParserTestCase method runTest.
@Override
protected final void runTest() throws Throwable {
SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
orgEnvelope.getBody().addChild(soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()));
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
SOAPBody body = builder.getSOAPEnvelope().getBody();
runTest(body);
if (supportsOptimization) {
// The expectation is that even after looking at the payload element name, registering
// a custom builder still transforms the element.
((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new CustomBuilder() {
@Override
public OMDataSource create(OMElement element) throws OMException {
try {
element.getXMLStreamReaderWithoutCaching().close();
} catch (XMLStreamException ex) {
throw new OMException(ex);
}
return new AbstractPushOMDataSource() {
@Override
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
xmlWriter.writeEmptyElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
}
@Override
public boolean isDestructiveWrite() {
return false;
}
};
}
});
assertThat(body.getFirstElement()).isInstanceOf(OMSourcedElement.class);
}
}
Aggregations