use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestDeclareNamespaceWithGeneratedPrefix3 method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement(new QName("test"));
OMNamespace ns = element.declareNamespace("urn:ns", null);
assertEquals("urn:ns", ns.getNamespaceURI());
assertNotNull(ns.getPrefix());
assertTrue(ns.getPrefix().length() > 0);
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
OMNamespace ns2 = it.next();
assertEquals(ns, ns2);
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestDiscardDocumentElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><a>text</a></root>")).getDocument();
OMElement element = document.getOMDocumentElement();
element.discard();
assertNull(document.getFirstOMChild());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestPushOMDataSourceExpansion method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
PushOMDataSource ds = new PushOMDataSource();
OMElement element = factory.createOMElement(ds);
Iterator<Map.Entry<String, String>> it = scenario.getNamespaceContext().entrySet().iterator();
if (it.hasNext()) {
Map.Entry<String, String> binding = it.next();
OMElement parent = factory.createOMElement("parent", factory.createOMNamespace(binding.getValue(), binding.getKey()));
while (it.hasNext()) {
binding = it.next();
parent.declareNamespace(factory.createOMNamespace(binding.getValue(), binding.getKey()));
}
parent.addChild(element);
}
scenario.validate(element, true);
assertTrue("Invalid test case: validation didn't expand the OMSourcedElement", ds.isExpanded());
}
use of org.apache.axiom.om.OMFactory 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.om.OMFactory in project webservices-axiom by apache.
the class TestSerializeModifiedOMSEWithNonDestructiveDataSource method runTest.
@Override
protected void runTest() throws Throwable {
OMDataSourceExt ds = new StringOMDataSource("<element><child/></element>");
assertFalse(ds.isDestructiveWrite());
OMFactory f = metaFactory.getOMFactory();
OMElement element = f.createOMElement(ds, "element", null);
element.getFirstElement().setText("TEST");
StringWriter sw = new StringWriter();
element.serialize(sw);
assertTrue(sw.toString().indexOf("TEST") != -1);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
element.serialize(baos);
assertTrue(new String(baos.toByteArray(), "UTF-8").indexOf("TEST") != -1);
assertTrue(element.toString().indexOf("TEST") != -1);
}
Aggregations