use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestGetName method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement root = factory.createOMElement("root", null);
OMSourcedElement el = factory.createOMElement(new PullOMDataSource("<p:el xmlns:p='urn:ns'>content</p:el>"), "el", factory.createOMNamespace("urn:ns", null));
root.addChild(el);
XMLStreamReader reader = root.getXMLStreamReader();
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
QName name = reader.getName();
assertEquals("p", name.getPrefix());
assertEquals("urn:ns", name.getNamespaceURI());
assertEquals("el", name.getLocalPart());
}
use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestSerialize method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = TestDocument.DOCUMENT1.createOMSourcedElement(factory, push, destructive);
OMDataSource ds = element.getDataSource();
OMContainer parent = elementContext.wrap(element);
boolean parentComplete = parent != null && parent.isComplete();
expansionStrategy.apply(element);
boolean consuming = expansionStrategy.isConsumedAfterSerialization(push, destructive, serializationStrategy);
for (int iteration = 0; iteration < count; iteration++) {
boolean expectException = iteration != 0 && (consuming || serializeParent && !serializationStrategy.isCaching() && !parentComplete);
XML result;
try {
result = serializationStrategy.serialize(serializeParent ? parent : element);
if (expectException) {
fail("Expected exception");
}
} catch (Exception ex) {
if (!expectException) {
throw ex;
} else {
continue;
}
}
InputSource expectedXML = new InputSource(new StringReader(TestDocument.DOCUMENT1.getContent()));
if (serializeParent) {
expectedXML = elementContext.getControl(expectedXML);
}
assertAbout(xml()).that(result.getInputSource()).hasSameContentAs(expectedXML);
// the sourced element should be expanded.
if (expansionStrategy.isExpandedAfterSerialization(push, destructive, serializationStrategy)) {
assertTrue(element.isExpanded());
assertEquals("OMSourcedElement completion status", !consuming, element.isComplete());
} else {
assertFalse(element.isExpanded());
}
if (parent != null && !serializeParent) {
// Operations on the OMSourcedElement should have no impact on the parent
assertEquals("Parent completion status", parentComplete, parent.isComplete());
}
}
if (ds instanceof PullOMDataSource) {
assertFalse(((PullOMDataSource) ds).hasUnclosedReaders());
}
}
use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestName1DefaultPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory f = metaFactory.getOMFactory();
// Create OMSE with an unknown prefix
OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", null);
OMElement element = f.createOMElement(new PullOMDataSource(TestDocument.DOCUMENT1.getContent()), "library", ns);
OMElement root = f.createOMElement("root", rootNS);
root.addChild(element);
// Test getting the local name and namespace URI. This should used not result in expansion
assertTrue(element.getLocalName().equals("library"));
assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
// Serialize and cache. This should cause expansion. The prefix should be updated to match the testDocument string
StringWriter writer = new StringWriter();
root.serialize(writer);
String result = writer.toString();
assertTrue(element.getLocalName().equals("library"));
assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
assertTrue(element.getNamespace().getPrefix().equals(""));
assertTrue(element.getDefaultNamespace() != null);
assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
// Serialize again
writer = new StringWriter();
root.serialize(writer);
result = writer.toString();
assertTrue(element.getLocalName().equals("library"));
assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
assertTrue(element.getNamespace().getPrefix().equals(""));
assertTrue(element.getDefaultNamespace() != null);
assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
}
use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestSetLocalName method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<p:root xmlns:p='urn:test'><child/></p:root>"), "root", factory.createOMNamespace("urn:test", "p"));
if (expand) {
element.getFirstOMChild();
}
element.setLocalName("newroot");
assertAbout(xml()).that(element.toString()).hasSameContentAs("<p:newroot xmlns:p='urn:test'><child/></p:newroot>");
}
use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.
the class TestAddAttribute method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root attr='orgvalue'><child/></root>"), "root", null);
// Add an attribute before expansion
OMAttribute attr = strategy.addAttribute(element, "attr", null, "newvalue");
// Force expansion; this should not overwrite the attribute we just added
assertThat(element.getFirstOMChild()).isNotNull();
OMAttribute attr2 = element.getAttribute(new QName("attr"));
assertThat(attr2).isSameAs(attr);
assertThat(attr2.getAttributeValue()).isEqualTo("newvalue");
Iterator<OMAttribute> it = element.getAllAttributes();
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isSameAs(attr);
assertThat(it.hasNext()).isFalse();
}
Aggregations