/**
* Checks equality of two XML documents excluding comment and processing
- * nodes and trimming the text of the elements.
+ * nodes and trimming the text of the elements. In case of problems, it
+ * provides an xpath-like expression describing where the problem is.
*
* @param aMsg
* @param aExpected
/**
* Checks equality of two XML documents excluding comment and processing
- * nodes and trimming the text of the elements.
+ * nodes and trimming the text of the elements. In case of problems, it
+ * provides an xpath-like expression describing where the problem is.
*
* @param aMsg
* @param aExpected
*/
public static void assertEquals(String aMsg, Document aExpected,
Document aActual) {
- assertEquals(aMsg, aExpected.getRootElement(), aActual.getRootElement());
+ assertEquals(aMsg + "/" + aExpected.getRootElement().getName(), aExpected.getRootElement(), aActual.getRootElement());
}
/**
* Checks equality of two XML elements excluding comment and processing
- * nodes and trimming the text of the elements.
+ * nodes and trimming the text of the elements. In case of problems, it
+ * provides an xpath-like expression describing where the problem is.
*
* @param aMsg
* @param aExpected
List<Attribute> actualAttrs = aActual.attributes();
Collections.sort(actualAttrs, new AttributeComparator());
- TestCase.assertEquals(aMsg + "/#attributes", expectedAttrs.size(),
+ TestCase.assertEquals(aMsg + "/count(@*)", expectedAttrs.size(),
actualAttrs.size());
for (int i = 0; i < expectedAttrs.size(); i++) {
String msg = aMsg + "/@" + expectedAttrs.get(i).getName();
// Nested elements.
List<Element> expectedElems = aExpected.elements();
List<Element> actualElems = aActual.elements();
- TestCase.assertEquals(aMsg + "/#elements", expectedElems.size(),
+ TestCase.assertEquals(aMsg + "/count(*)", expectedElems.size(),
actualElems.size());
// determine the how-manyth element of the given name we are at.
+ // Maps element name to the last used index (or null if not yet used)
Map<String, Integer> elementIndex = new TreeMap<String, Integer>();
for (int i = 0; i < expectedElems.size(); i++) {
String elemName = expectedElems.get(i).getName();
index++;
}
elementIndex.put(elemName, index);
- String msg = aMsg + "/" + expectedElems.get(i).getName() + "("
- + index + ")";
+ String msg = aMsg + "/" + expectedElems.get(i).getName() + "["
+ + index + "]";
assertEquals(msg, expectedElems.get(i), actualElems.get(i));
}
}
/**
- * Checks equality of two attributes.
+ * Checks equality of two attributes. In case of problems, it
+ * provides an xpath-like expression describing where the problem is.
*
* @param aMsg
* @param aExpected