@Test public void testAddOrSetAttributeAttributesImplNode() throws ParserConfigurationException { final AttributesImpl atts = new AttributesImpl(); final DOMImplementation dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation(); final Document doc = dom.createDocument(null, "foo", null); doc.getDocumentElement().setAttribute("foo", "foo"); final Attr att = (Attr) doc.getDocumentElement().getAttributeNode("foo"); XMLUtils.addOrSetAttribute(atts, att); final int i = atts.getIndex(NULL_NS_URI, "foo"); assertEquals(NULL_NS_URI, atts.getURI(i)); assertEquals("foo", atts.getQName(i)); assertEquals("foo", atts.getLocalName(i)); assertEquals("foo", atts.getValue(i)); doc.getDocumentElement().setAttributeNS(XML_NS_URI, "xml:lang", "en"); final Attr lang = (Attr) doc.getDocumentElement().getAttributeNodeNS(XML_NS_URI, "lang"); XMLUtils.addOrSetAttribute(atts, lang); final int l = atts.getIndex(XML_NS_URI, "lang"); assertEquals(XML_NS_URI, atts.getURI(l)); assertEquals("xml:lang", atts.getQName(l)); assertEquals("lang", atts.getLocalName(l)); assertEquals("en", atts.getValue(l)); }
@Test public void testAddOrSetAttributeAttributesImplStringString() { final AttributesImpl atts = new AttributesImpl(); XMLUtils.addOrSetAttribute(atts, "foo", "foo"); assertEquals(1, atts.getLength()); XMLUtils.addOrSetAttribute(atts, "bar", "bar"); assertEquals(2, atts.getLength()); XMLUtils.addOrSetAttribute(atts, "foo", "bar"); assertEquals(2, atts.getLength()); }
@Test public void testRemoveAttribute() { final AttributesImpl atts = new AttributesImpl(); XMLUtils.addOrSetAttribute(atts, "foo", "foo", "foo", "CDATA", "foo"); assertEquals(1, atts.getLength()); XMLUtils.removeAttribute(atts, "foo"); assertEquals(0, atts.getLength()); }