use of org.apache.axiom.om.OMSourcedElement 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.om.OMSourcedElement 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.om.OMSourcedElement 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.om.OMSourcedElement 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.om.OMSourcedElement in project webservices-axiom by apache.
the class TestExpand method runTest.
@Override
protected void runTest() throws Throwable {
OMSourcedElement element = TestDocument.DOCUMENT1.createOMSourcedElement(metaFactory.getOMFactory(), false, true);
element.getAllDeclaredNamespaces();
assertEquals("Expanded namespace count error", 1, countItems(element.getAllDeclaredNamespaces()));
assertEquals("Expanded attribute count error", 1, countItems(element.getAllAttributes()));
assertEquals("Expanded attribute value error", "1", element.getAttributeValue(new QName("books")));
OMElement child = element.getFirstElement();
assertEquals("Child element name", "type", child.getLocalName());
assertEquals("Child element namespace", "http://www.sosnoski.com/uwjws/library", child.getNamespace().getNamespaceURI());
OMNode next = child.getNextOMSibling();
assertTrue("Expected child element", next instanceof OMElement);
next = next.getNextOMSibling();
assertTrue("Expected child element", next instanceof OMElement);
child = (OMElement) next;
assertEquals("Child element name", "book", child.getLocalName());
assertEquals("Child element namespace", "http://www.sosnoski.com/uwjws/library", child.getNamespace().getNamespaceURI());
assertEquals("Attribute value error", "xml", child.getAttributeValue(new QName("type")));
}
Aggregations