use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestGetTextAsQNameWithExtraWhitespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
element.declareNamespace("urn:test", "ns1");
element.setText(" ns1:test ");
assertEquals(new QName("urn:test", "test"), element.getTextAsQName());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestGetOMDocumentElementWithParser method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!-- comment --><root/><!-- comment -->")).getDocument();
OMElement documentElement = document.getOMDocumentElement();
assertNotNull(documentElement);
assertEquals("root", documentElement.getLocalName());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestRemoveChildren method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<?pi data?><root>text</root>")).getDocument();
if (complete) {
document.build();
}
OMProcessingInstruction firstChild = (OMProcessingInstruction) document.getFirstOMChild();
OMElement documentElement;
if (accessDocumentElement) {
documentElement = document.getOMDocumentElement();
assertEquals(complete, documentElement.isComplete());
} else {
documentElement = null;
}
document.removeChildren();
// Test that the child has been detached correctly.
assertNull(firstChild.getParent());
assertNull(firstChild.getPreviousOMSibling());
assertNull(firstChild.getNextOMSibling());
if (documentElement != null) {
// Test that the child has been detached correctly.
assertNull(documentElement.getParent());
assertNull(documentElement.getPreviousOMSibling());
assertNull(documentElement.getNextOMSibling());
// Test that we can still get the content of the document element.
assertEquals("text", documentElement.getText());
}
// Test that the document is now empty.
assertNull(document.getFirstOMChild());
// Check that the document is in a clean state and that we are able to add
// new children.
document.addChild(factory.createOMElement("newroot", null));
assertAbout(xml()).that(xml(OMDocument.class, document)).hasSameContentAs("<newroot/>");
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestSerializeAndConsumeWithIncompleteDescendant method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement incompleteElement = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocumentElement(true);
OMDocument document = factory.createOMDocument();
OMElement root = factory.createOMElement("root", null, document);
root.addChild(incompleteElement);
StringWriter out = new StringWriter();
document.serializeAndConsume(out);
assertAbout(xml()).that(out.toString()).hasSameContentAs("<root><elem>text</elem></root>");
assertConsumed(incompleteElement);
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestGetDocumentElementWithDiscardDocumentIllFormedEpilog method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root/> there shouldn't be text here!"));
OMElement element = builder.getDocumentElement(true);
try {
element.build();
fail("Expected OMException");
} catch (OMException ex) {
// Expected
}
}
Aggregations