@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; XmlNode other = (XmlNode) obj; return target.isEqualNode(other.target); }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Element elem1; Element elem2; NodeList employeeList; boolean isEqual; doc = (Document) load("hc_staff", false); employeeList = doc.getElementsByTagName("em"); elem1 = (Element) employeeList.item(0); elem2 = (Element) employeeList.item(1); isEqual = elem1.isEqualNode(elem2); assertFalse("nodeisequalnode10", isEqual); }
public void testXmlAttribute() throws Exception { User user = getUser(userDao, "testuser"); CollectionItem root = (CollectionItem) contentDao.getRootItem(user); ContentItem item = generateTestContent(); org.w3c.dom.Element testElement = createTestElement(); org.w3c.dom.Element testElement2 = createTestElement(); testElement2.setAttribute("foo", "bar"); Assert.assertFalse(testElement.isEqualNode(testElement2)); XmlAttribute xmlAttr = new HibXmlAttribute(new HibQName("xmlattribute"), testElement); item.addAttribute(xmlAttr); ContentItem newItem = contentDao.createContent(root, item); clearSession(); ContentItem queryItem = contentDao.findContentByUid(newItem.getUid()); Attribute attr = queryItem.getAttribute(new HibQName("xmlattribute")); Assert.assertNotNull(attr); Assert.assertTrue(attr instanceof XmlAttribute); org.w3c.dom.Element element = (org.w3c.dom.Element) attr.getValue(); Assert.assertEquals(DomWriter.write(testElement), DomWriter.write(element)); Date modifyDate = attr.getModifiedDate(); // Sleep a couple millis to make sure modifyDate doesn't change Thread.sleep(2); contentDao.updateContent(queryItem); clearSession(); queryItem = contentDao.findContentByUid(newItem.getUid()); attr = queryItem.getAttribute(new HibQName("xmlattribute")); // Attribute shouldn't have been updated Assert.assertEquals(modifyDate, attr.getModifiedDate()); attr.setValue(testElement2); // Sleep a couple millis to make sure modifyDate doesn't change Thread.sleep(2); modifyDate = attr.getModifiedDate(); contentDao.updateContent(queryItem); clearSession(); queryItem = contentDao.findContentByUid(newItem.getUid()); attr = queryItem.getAttribute(new HibQName("xmlattribute")); Assert.assertNotNull(attr); Assert.assertTrue(attr instanceof XmlAttribute); // Attribute should have been updated Assert.assertTrue(modifyDate.before(attr.getModifiedDate())); element = (org.w3c.dom.Element) attr.getValue(); Assert.assertEquals(DomWriter.write(testElement2), DomWriter.write(element)); }