use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestExceptionDuringSerialization method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory omFactory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
DocumentBean object = new DocumentBean();
object.setId("test");
OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, object));
XMLStreamException exception = new XMLStreamException("TEST");
try {
element.serialize(new ExceptionXMLStreamWriterWrapper(StAX.createNullXMLStreamWriter(), exception));
fail("Expected XMLStreamException");
} catch (XMLStreamException ex) {
assertSame(exception, ex);
}
}
use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestGetNameFromPlainObject method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory omFactory = metaFactory.getOMFactory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, new DocumentBean()));
assertEquals("http://ws.apache.org/axiom/test/jaxb", element.getNamespaceURI());
assertEquals("document", element.getLocalName());
assertFalse(element.isExpanded());
// Force expansion so that OMSourcedElement compares the namespace URI and local name
// provided by JAXBOMDataSource with the actual name of the element
element.getFirstOMChild();
}
use of org.apache.axiom.om.OMSourcedElement 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.OMSourcedElement in project webservices-axiom by apache.
the class TestWriteTextToWithNonDestructiveOMDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
DataSource ds = new RandomDataSource(665544, 32, 128, 20000000);
QName qname = new QName("a");
OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, Charset.forName("ascii")), qname);
Reader in = new InputStreamReader(ds.getInputStream(), "ascii");
Writer out = new CharacterStreamComparator(in);
// cache doesn't matter here
element.writeTextTo(out, true);
out.close();
assertFalse(element.isExpanded());
}
Aggregations