use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestCloseOnComplete method runTest.
@Override
protected void runTest() throws Throwable {
PullOMDataSource ds = new PullOMDataSource("<root><a/></root>");
OMSourcedElement element = metaFactory.getOMFactory().createOMElement(ds);
OMNode child = element.getFirstOMChild();
assertFalse(element.isComplete());
assertTrue(ds.hasUnclosedReaders());
child.getNextOMSibling();
assertTrue(element.isComplete());
assertFalse(ds.hasUnclosedReaders());
}
use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestDeclareNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root xmlns:p='urn:ns1'><child/></root>"), "root", null);
// Declare a namespace before expansion
element.declareNamespace("urn:ns2", "p");
// Force expansion; this should not overwrite the namespace declaration we just added
assertThat(element.getFirstOMChild()).isNotNull();
OMNamespace ns = element.findNamespaceURI("p");
assertThat(ns).isNotNull();
assertThat(ns.getPrefix()).isEqualTo("p");
assertThat(ns.getNamespaceURI()).isEqualTo("urn:ns2");
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isSameAs(ns);
assertThat(it.hasNext()).isFalse();
}
use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestDetach method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
String xml1 = "<root><a/><b/></root>";
String xml2 = "<child><c/><d/></child>";
OMElement parent = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(xml1)).getDocumentElement();
PullOMDataSource ds = new PullOMDataSource(xml2);
OMSourcedElement omse = factory.createOMElement(ds, "child", null);
parent.getFirstOMChild().insertSiblingBefore(omse);
expansionStrategy.apply(omse);
omse.detach();
assertThat(ds.hasUnclosedReaders()).isEqualTo(expansionStrategy == PARTIAL);
assertThat(ds.getReaderRequestCount()).isEqualTo(expansionStrategy == DONT_EXPAND ? 0 : 1);
assertAbout(xml()).that(xml(OMElement.class, parent)).hasSameContentAs(xml1);
assertAbout(xml()).that(xml(OMElement.class, omse)).hasSameContentAs(xml2);
}
use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestGetAllAttributes method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root attr='value'/>"), "root", null);
Iterator<OMAttribute> attributes = element.getAllAttributes();
assertThat(attributes.hasNext()).isTrue();
OMAttribute attr = attributes.next();
assertThat(attr.getLocalName()).isEqualTo("attr");
assertThat(attributes.hasNext()).isFalse();
}
use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestGetAttribute method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root attr='value'/>"), "root", null);
OMAttribute attr = element.getAttribute(new QName("attr"));
assertThat(attr).isNotNull();
assertThat(attr.getLocalName()).isEqualTo("attr");
}
Aggregations