use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class CloneTestCase method identityCheck.
/**
* Check the identity of each object in the tree
* @param source
* @param target
* @param depth
*/
protected void identityCheck(OMNode source, OMNode target, String depth) {
// System.out.println(depth + source.getClass().getName());
if (source instanceof OMElement) {
if (source instanceof OMSourcedElement) {
assertTrue("Source = " + source.getClass().getName() + "Target = " + target.getClass().getName(), target instanceof OMSourcedElement);
assertEquals(((OMSourcedElement) source).isExpanded(), ((OMSourcedElement) target).isExpanded());
if (((OMSourcedElement) source).isExpanded()) {
Iterator<OMNode> i = ((OMElement) source).getChildren();
Iterator<OMNode> j = ((OMElement) target).getChildren();
while (i.hasNext() && j.hasNext()) {
OMNode sourceChild = i.next();
OMNode targetChild = j.next();
identityCheck(sourceChild, targetChild, depth + " ");
}
assertEquals("Source and Target have different number of children", i.hasNext(), j.hasNext());
}
} else {
assertEquals(source.getClass(), target.getClass());
Iterator<OMNode> i = ((OMElement) source).getChildren();
Iterator<OMNode> j = ((OMElement) target).getChildren();
while (i.hasNext() && j.hasNext()) {
OMNode sourceChild = i.next();
OMNode targetChild = j.next();
identityCheck(sourceChild, targetChild, depth + " ");
}
assertEquals("Source and Target have different number of children", i.hasNext(), j.hasNext());
}
} else {
assertEquals(source.getClass(), target.getClass());
}
}
use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestGetNextOMSiblingIncomplete method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement omse = factory.createOMElement(new StringOMDataSource("<sourcedelement/>"));
OMElement parent = factory.createOMElement(new QName("parent"));
parent.addChild(omse);
// Cause expansion of the sourced element without building it completely
omse.getLocalName();
assertTrue(omse.isExpanded());
assertFalse(omse.isComplete());
// Call getNextOMSibling(); this should not build the element
omse.getNextOMSibling();
assertFalse(omse.isComplete());
}
use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestGetTextAsStreamWithNonDestructiveOMDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
DataSource ds = new RandomDataSource(445566, 32, 128, 20000000);
QName qname = new QName("a");
Charset cs = Charset.forName("ascii");
OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, cs), qname);
Reader in = element.getTextAsStream(true);
assertFalse(in instanceof StringReader);
IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), cs), in);
assertFalse(element.isExpanded());
}
use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestRemoveChildrenUnexpanded method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(new StringOMDataSource("<element attr='value'><a/></element>"));
element.removeChildren();
// Check that the attribute has been added
Iterator<OMAttribute> it = element.getAllAttributes();
assertTrue(it.hasNext());
OMAttribute attr = it.next();
assertEquals("attr", attr.getLocalName());
assertEquals("value", attr.getAttributeValue());
assertFalse(it.hasNext());
// Check that the element is empty
assertNull(element.getFirstOMChild());
}
use of org.apache.axiom.om.OMSourcedElement in project webservices-axiom by apache.
the class TestSetDataSourceOnAlreadyExpandedElement method runTest.
@Override
protected void runTest() throws Throwable {
OMSourcedElement element = TestDocument.DOCUMENT1.createOMSourcedElement(metaFactory.getOMFactory(), false, true);
// Make sure the OMSourcedElement is expanded
element.getFirstOMChild();
assertTrue(element.isExpanded());
// Now set a new data source
element.setDataSource(new PullOMDataSource(TestDocument.DOCUMENT2.getContent()));
assertFalse(element.isExpanded());
// getNextOMSibling should not expand the element
assertNull(element.getNextOMSibling());
assertFalse(element.isExpanded());
}
Aggregations