Skip to content

Commit 857a8c6

Browse files
committed
fix #101 - (cherry-pick 4f3ee44) use XMLUnit assertXMLEqual to overcome an issue with XML element attribute names out of order
(cherry picked from commit 4f3ee44)
1 parent 8f028e7 commit 857a8c6

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/test/java/com/marklogic/client/test/StructuredQueryBuilderTest.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515
*/
1616
package com.marklogic.client.test;
1717

18+
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
1819
import static org.junit.Assert.assertEquals;
1920

21+
import org.custommonkey.xmlunit.XpathEngine;
22+
import org.custommonkey.xmlunit.SimpleNamespaceContext;
23+
import org.custommonkey.xmlunit.XMLUnit;
24+
2025
import java.io.ByteArrayInputStream;
2126
import java.io.FileInputStream;
2227
import java.io.IOException;
2328
import java.io.InputStream;
29+
import java.util.HashMap;
2430

2531
import javax.xml.XMLConstants;
2632
import javax.xml.parsers.ParserConfigurationException;
@@ -30,6 +36,7 @@
3036
import javax.xml.validation.Schema;
3137
import javax.xml.validation.SchemaFactory;
3238

39+
import org.junit.BeforeClass;
3340
import org.junit.Test;
3441
import org.xml.sax.SAXException;
3542
import org.xml.sax.SAXParseException;
@@ -42,6 +49,30 @@
4249
import com.marklogic.client.util.EditableNamespaceContext;
4350

4451
public class StructuredQueryBuilderTest {
52+
static private XpathEngine xpather;
53+
54+
@BeforeClass
55+
public static void beforeClass() {
56+
XMLUnit.setIgnoreAttributeOrder(true);
57+
XMLUnit.setIgnoreWhitespace(true);
58+
XMLUnit.setNormalize(true);
59+
XMLUnit.setNormalizeWhitespace(true);
60+
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
61+
62+
HashMap<String,String> namespaces = new HashMap<String, String>();
63+
namespaces.put("rapi", "http://marklogic.com/rest-api");
64+
namespaces.put("prop", "http://marklogic.com/xdmp/property");
65+
namespaces.put("xs", "http://www.w3.org/2001/XMLSchema");
66+
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
67+
namespaces.put("search", "http://marklogic.com/appservices/search");
68+
69+
70+
SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces);
71+
72+
xpather = XMLUnit.newXpathEngine();
73+
xpather.setNamespaceContext(namespaceContext);
74+
}
75+
4576
// remove dependency on org.apache.tools.ant.filters.StringInputStream
4677
static class StringInputStream extends ByteArrayInputStream {
4778
StringInputStream(String input) {
@@ -508,7 +539,7 @@ public void testBuilder() throws IOException, SAXException, ParserConfigurationE
508539
xml = new StringInputStream(q);
509540
parser.parse(xml, handler);
510541

511-
assertEquals(
542+
assertXMLEqual("Geospatial query malformed",
512543
"<query xmlns=\"http://marklogic.com/appservices/search\" "
513544
+ "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" "
514545
+ "xmlns:search=\"http://marklogic.com/appservices/search\" "

0 commit comments

Comments
 (0)