X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Ftest%2Forg%2Fwamblee%2Fxml%2FXmlUtils.java;h=638d64e4e98e79e789893221acac89fb30c0c39e;hb=07cedd3f0730646ea35a7f668b3e1e872a4605d9;hp=12292469e06178012a5010af4d636294135eaa23;hpb=f3f910cc373067d03c8f221b5e2deec65378bb75;p=utils diff --git a/support/test/org/wamblee/xml/XmlUtils.java b/support/test/org/wamblee/xml/XmlUtils.java index 12292469..638d64e4 100644 --- a/support/test/org/wamblee/xml/XmlUtils.java +++ b/support/test/org/wamblee/xml/XmlUtils.java @@ -43,7 +43,8 @@ public final class XmlUtils { /** * 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 @@ -57,7 +58,8 @@ public final class XmlUtils { /** * 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 @@ -65,12 +67,13 @@ public final class XmlUtils { */ 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 @@ -93,7 +96,7 @@ public final class XmlUtils { List actualAttrs = aActual.attributes(); Collections.sort(actualAttrs, new AttributeComparator()); - TestCase.assertEquals(aMsg + "/#attributes", expectedAttrs.size(), + TestCase.assertEquals("count(" + aMsg + "/@*)", expectedAttrs.size(), actualAttrs.size()); for (int i = 0; i < expectedAttrs.size(); i++) { String msg = aMsg + "/@" + expectedAttrs.get(i).getName(); @@ -103,9 +106,10 @@ public final class XmlUtils { // Nested elements. List expectedElems = aExpected.elements(); List actualElems = aActual.elements(); - TestCase.assertEquals(aMsg + "/#elements", expectedElems.size(), + TestCase.assertEquals("count(" + aMsg + "/*)", 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 elementIndex = new TreeMap(); for (int i = 0; i < expectedElems.size(); i++) { String elemName = expectedElems.get(i).getName(); @@ -116,15 +120,16 @@ public final class XmlUtils { 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