use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestDTDReader method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = factory.createOMDocument();
factory.createOMDocType(document, "root", "-//MY//DTD", "my.dtd", "<!ELEMENT root (#PCDATA)>");
factory.createOMElement("root", null, document);
XMLStreamReader reader = document.getXMLStreamReader();
// Note that according to the specification of the DTDReader interface, it is
// allowed to look up the extension before reaching the DTD event.
DTDReader dtdReader = (DTDReader) reader.getProperty(DTDReader.PROPERTY);
assertNotNull(dtdReader);
assertEquals(XMLStreamReader.DTD, reader.next());
assertEquals("root", dtdReader.getRootName());
assertEquals("-//MY//DTD", dtdReader.getPublicId());
assertEquals("my.dtd", dtdReader.getSystemId());
assertEquals("<!ELEMENT root (#PCDATA)>", reader.getText());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestAddAttributeMultiple method runTest.
@Override
protected void runTest() throws Throwable {
String expectedXML = "<AttributeTester xmlns:myAttr2NS=\"http://test-attributes-2.org\" " + "xmlns:myAttr1NS=\"http://test-attributes-1.org\" myAttr2NS:attrNumber=\"2\" myAttr1NS:attrNumber=\"1\" />";
OMFactory omFactory = metaFactory.getOMFactory();
OMNamespace attrNS1 = omFactory.createOMNamespace("http://test-attributes-1.org", "myAttr1NS");
OMNamespace attrNS2 = omFactory.createOMNamespace("http://test-attributes-2.org", "myAttr2NS");
OMElement omElement = omFactory.createOMElement("AttributeTester", null);
strategy.addAttribute(omElement, "attrNumber", attrNS1, "1");
strategy.addAttribute(omElement, "attrNumber", attrNS2, "2");
assertAbout(xml()).that(xml(OMElement.class, omElement)).hasSameContentAs(expectedXML);
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestAddAttributeGeneratedPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMNamespace otherNS = factory.createOMNamespace("urn:ns2", "p");
OMElement parent = factory.createOMElement("parent", otherNS);
if (defaultNamespaceInScope) {
parent.declareDefaultNamespace("urn:test");
}
OMElement element = factory.createOMElement("test", otherNS, parent);
OMAttribute attr = element.addAttribute("attr", "value", factory.createOMNamespace("urn:test", null));
OMNamespace ns = attr.getNamespace();
assertTrue(ns.getPrefix().length() > 0);
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
assertEquals(ns, it.next());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestAddAttributeReplace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
// Use same namespace URI but different prefixes
OMNamespace ns1 = factory.createOMNamespace("urn:ns", "p1");
OMNamespace ns2 = factory.createOMNamespace("urn:ns", "p2");
OMElement element = factory.createOMElement(new QName("test"));
OMAttribute att1 = strategy.addAttribute(element, "test", ns1, "value1");
OMAttribute att2 = strategy.addAttribute(element, "test", ns2, "value2");
Iterator<OMAttribute> it = element.getAllAttributes();
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isSameAs(att2);
assertThat(it.hasNext()).isFalse();
assertThat(att1.getOwner()).isNull();
assertThat(att2.getOwner()).isSameAs(element);
assertThat(att1).hasValue("value1");
assertThat(att2).hasValue("value2");
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestAddAttributeReuseExistingPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", null);
OMElement element = factory.createOMElement("element", null, parent);
parent.declareNamespace("urn:test", "p");
OMAttribute attr = element.addAttribute("attr", "test", factory.createOMNamespace("urn:test", null));
assertThat(attr).hasPrefix("p");
assertThat(element).hasNoNamespaceDeclarations();
}
Aggregations