use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestDiscard method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", null);
OMElement child1 = factory.createOMElement("child1", null, parent);
PullOMDataSource ds = new PullOMDataSource("<root><a/><b/></root>");
OMSourcedElement omse = factory.createOMElement(ds, "root", null);
parent.addChild(omse);
OMElement child2 = factory.createOMElement("child2", null, parent);
expansionStrategy.apply(omse);
omse.discard();
assertThat(child1.getNextOMSibling()).isSameAs(child2);
assertThat(ds.hasUnclosedReaders()).isFalse();
assertThat(ds.getReaderRequestCount()).isEqualTo(expansionStrategy == DONT_EXPAND ? 0 : 1);
}
use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestGetAttributeValue method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root attr='value'/>"), "root", null);
assertThat(element.getAttributeValue(new QName("attr"))).isEqualTo("value");
}
use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestGetDocumentFromBuilder method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDataSource ds = new StringOMDataSource("<root><a/></root>");
OMSourcedElement element = factory.createOMElement(ds);
// Force expansion
element.getFirstOMChild();
OMXMLParserWrapper builder = element.getBuilder();
try {
builder.getDocument();
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException ex) {
// Expected
}
try {
builder.getDocumentElement();
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException ex) {
// Expected
}
}
use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestGetNamespaceNormalized2 method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(new StringOMDataSource("<element>content</element>"), new QName("element"));
assertNull(element.getNamespace());
// Expand the element
element.getFirstOMChild();
assertNull(element.getNamespace());
}
use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestCloneNonDestructive method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDataSource ds = new WrappedTextNodeOMDataSourceFromDataSource(new QName("wrapper"), new ByteArrayDataSource("test".getBytes("utf-8")), Charset.forName("utf-8"));
OMSourcedElement element = factory.createOMElement(ds);
OMCloneOptions options = new OMCloneOptions();
options.setCopyOMDataSources(copyOMDataSources);
OMElement clone = (OMElement) element.clone(options);
if (copyOMDataSources) {
assertTrue(clone instanceof OMSourcedElement);
assertFalse(element.isExpanded());
} else {
assertFalse(clone instanceof OMSourcedElement);
assertTrue(clone.isComplete());
}
assertEquals("test", clone.getText());
assertEquals("wrapper", clone.getLocalName());
}
Aggregations