use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestIsCompleteAfterAddingIncompleteChild method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement incompleteElement = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocumentElement(true);
OMElement root = factory.createOMElement("root", null);
assertTrue(root.isComplete());
root.addChild(incompleteElement);
assertFalse(root.isComplete());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestRemoveAttribute method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", null);
OMAttribute attr1 = element.addAttribute("attr1", "value1", null);
OMAttribute attr2 = element.addAttribute("attr2", "value2", null);
element.removeAttribute(attr1);
assertNull(attr1.getOwner());
Iterator<OMAttribute> it = element.getAllAttributes();
assertTrue(it.hasNext());
assertSame(attr2, it.next());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestMultipleDefaultNS method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory omFactory = metaFactory.getOMFactory();
OMNamespace defaultNS1 = omFactory.createOMNamespace("http://defaultNS1.org", null);
OMNamespace defaultNS2 = omFactory.createOMNamespace("http://defaultNS2.org", null);
OMElement omElementOne = omFactory.createOMElement("DocumentElement", omFactory.createOMNamespace("http://defaultNS1.org", ""));
OMElement omElementOneChild = omFactory.createOMElement("ChildOne", null, omElementOne);
OMElement omElementTwo = omFactory.createOMElement("Foo", defaultNS2, omElementOne);
omElementTwo.declareDefaultNamespace("http://defaultNS2.org");
OMElement omElementTwoChild = omFactory.createOMElement("ChildOne", null, omElementTwo);
OMElement omElementThree = omFactory.createOMElement("Bar", defaultNS1, omElementTwo);
omElementThree.declareDefaultNamespace("http://defaultNS1.org");
OMNamespace omElementOneChildNS = omElementOneChild.getNamespace();
OMNamespace omElementTwoChildNS = omElementTwoChild.getNamespace();
// TODO: LLOM's and DOOM's behaviors are slightly different here; need to check if both are allowed
assertTrue(omElementOneChildNS == null || "".equals(omElementOneChildNS.getNamespaceURI()));
assertTrue(omElementTwoChildNS == null || "".equals(omElementTwoChildNS.getNamespaceURI()));
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestGetChildrenWithName3 method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMNamespace testNamespace = factory.createOMNamespace("http://test.ws.org", "test");
OMElement documentElement = factory.createOMElement("Employees", testNamespace);
documentElement.declareNamespace(testNamespace);
factory.createOMText(documentElement, " ");
OMElement e = factory.createOMElement("Employee", testNamespace, documentElement);
e.setText("Apache Developer");
Iterator<OMElement> childrenIter = documentElement.getChildrenWithName(new QName("http://test.ws.org", "Employee", "test"));
// should walk past OMText
OMElement employee = childrenIter.next();
assertEquals("Employee test was incorrect", employee.getText(), "Apache Developer");
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class TestGetChildrenWithName4 method runTest.
@Override
protected void runTest() throws Throwable {
// Create a document with 2 children, each named "sample" but
// have different namespaces.
OMFactory factory = metaFactory.getOMFactory();
OMNamespace a = factory.createOMNamespace(NS_A, "a");
OMNamespace b = factory.createOMNamespace(NS_B, "b");
OMElement documentElement = factory.createOMElement("Document", a);
factory.createOMElement("sample", a, documentElement);
factory.createOMElement("sample", b, documentElement);
// Test for fully qualified names
QName qName = new QName(NS_A, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
qName = new QName(NS_B, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
qName = new QName(NS_C, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
// Test for QName with no namespace.
// Axiom 1.2.x implemented a legacy behavior where an empty namespace URI was interpreted
// as a wildcard (see AXIOM-11). In Axiom 1.3.x, the matching is always strict.
qName = new QName("", "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
// Now add an unqualified sample element to the documentElement
factory.createOMElement("sample", null, documentElement);
// Repeat the tests
qName = new QName(NS_A, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
qName = new QName(NS_B, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
qName = new QName(NS_C, "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(0);
// Since there actually is an unqualified element child, the most accurate
// interpretation of getChildrenWithName should be to return this one
// child
qName = new QName("", "sample");
assertThat(getChildrenCount(documentElement.getChildrenWithName(qName))).isEqualTo(1);
}
Aggregations