use of org.apache.axiom.om.OMAttribute in project webservices-axiom by apache.
the class TestGetAllAttributes2 method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<e xmlns:p='urn:test' p:attr='test'/>");
Iterator<OMAttribute> it = element.getAllAttributes();
assertTrue(it.hasNext());
OMAttribute attr = it.next();
assertEquals("urn:test", attr.getNamespace().getNamespaceURI());
assertEquals("attr", attr.getLocalName());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMAttribute 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();
}
use of org.apache.axiom.om.OMAttribute in project webservices-axiom by apache.
the class TestAddAttributeWithoutNamespace method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement("test", "urn:test", "");
// Retrieve the namespace declaration generated by createOMElement
OMNamespace ns = element.getAllDeclaredNamespaces().next();
OMAttribute attr = addAttributeStrategy.addAttribute(element, "test", noNamespaceStrategy.createOMNamespace(factory), "test");
assertNull(attr.getNamespace());
Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
assertTrue(it.hasNext());
assertEquals(ns, it.next());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMAttribute in project webservices-axiom by apache.
the class TestAddAttributeAlreadyOwnedByElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element = factory.createOMElement(new QName("test"));
OMAttribute att = element.addAttribute("test", "test", null);
OMAttribute result = element.addAttribute(att);
assertSame(result, att);
assertSame(element, att.getOwner());
Iterator<OMAttribute> it = element.getAllAttributes();
assertTrue(it.hasNext());
assertSame(att, it.next());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMAttribute in project webservices-axiom by apache.
the class TestAddAttributeAlreadyOwnedByOtherElement method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement element1 = factory.createOMElement(new QName("test"));
OMElement element2 = factory.createOMElement(new QName("test"));
OMAttribute att1 = element1.addAttribute("test", "test", null);
OMAttribute att2 = element2.addAttribute(att1);
assertSame(element1, att1.getOwner());
assertNotSame(att1, att2);
assertSame(element2, att2.getOwner());
}
Aggregations