use of org.custommonkey.xmlunit.ElementNameQualifier in project ddf by codice.
the class TestCswFilterDelegate method testRelative.
@Test
public void testRelative() throws JAXBException, SAXException, IOException {
long duration = 92000000000L;
CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, effectiveDateMapping, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
Map<String, Object> propMap = new HashMap<>();
propMap.put("extendedComparisonOp", "relative");
propMap.put("duration", new Long(duration));
String xml = getXmlProperty(localCswFilterDelegate, propertyNameModified, BETWEEN, testStartDate.toCalendar(null).getTime(), testEndDate.toCalendar(null).getTime(), propMap);
String durationCompare = duringXml.replace(REPLACE_START_DATE, "").replace(REPLACE_END_DATE, "").replace(REPLACE_TEMPORAL_PROPERTY, modifiedDateMapping);
String pattern = "(?i)(<ns.:Literal>)(.+?)(</ns.:Literal>)";
String compareXml = xml.replaceAll(pattern, "<ogc:Literal xmlns:ogc=\"http://www.opengis.net/ogc\"></ogc:Literal>");
Diff xmlDiff = new Diff(durationCompare, compareXml);
xmlDiff.overrideElementQualifier(new ElementNameQualifier() {
@Override
protected boolean equalsNamespace(Node control, Node test) {
return true;
}
});
xmlDiff.overrideDifferenceListener(new DifferenceListener() {
@Override
public int differenceFound(Difference diff) {
if (diff.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
}
return RETURN_ACCEPT_DIFFERENCE;
}
@Override
public void skippedComparison(Node arg0, Node arg1) {
}
});
assertXMLIdentical(xmlDiff, true);
}
use of org.custommonkey.xmlunit.ElementNameQualifier in project gate-core by GateNLP.
the class TestCreoleAnnotationHandler method testCreoleAnnotationHandler.
/**
* Take a skeleton creole.xml file, process the annotations on the classes it
* mentions and compare the resulting XML to the expected result.
*/
public void testCreoleAnnotationHandler() throws Exception {
URL originalUrl = new URL(TestDocument.getTestServerName() + "tests/creole-annotation-handler/initial-creole.xml");
org.jdom.Document creoleXml = jdomBuilder.build(originalUrl.openStream());
CreoleAnnotationHandler processor = new CreoleAnnotationHandler(new Plugin.Directory(new URL(TestDocument.getTestServerName() + "tests/creole-annotation-handler/")));
processor.processAnnotations(creoleXml);
URL expectedURL = new URL(TestDocument.getTestServerName() + "tests/creole-annotation-handler/expected-creole.xml");
// XMLUnit requires the expected and actual results as W3C DOM rather than
// JDOM
DocumentBuilder docBuilder = jaxpFactory.newDocumentBuilder();
org.w3c.dom.Document targetXmlDOM = docBuilder.parse(expectedURL.openStream());
org.w3c.dom.Document actualXmlDOM = jdom2dom.output(creoleXml);
Diff diff = XMLUnit.compareXML(targetXmlDOM, actualXmlDOM);
// compare parameter elements with the same NAME, resources with the same
// CLASS, and all other elements that have the same element name
diff.overrideElementQualifier(new ElementNameQualifier() {
@Override
public boolean qualifyForComparison(Element control, Element test) {
if ("PARAMETER".equals(control.getTagName()) && "PARAMETER".equals(test.getTagName())) {
return control.getAttribute("NAME").equals(test.getAttribute("NAME"));
} else if ("RESOURCE".equals(control.getTagName()) && "RESOURCE".equals(test.getTagName())) {
String controlClass = findClass(control);
String testClass = findClass(test);
return (controlClass == null) ? (testClass == null) : controlClass.equals(testClass);
} else {
return super.qualifyForComparison(control, test);
}
}
private String findClass(Element resource) {
Node node = resource.getFirstChild();
while (node != null && !"CLASS".equals(node.getNodeName())) {
node = node.getNextSibling();
}
if (node != null) {
return node.getTextContent();
} else {
return null;
}
}
});
// do the comparison!
boolean match = diff.similar();
if (!match) {
// if comparison failed, output the "actual" result document for
// debugging purposes
System.err.println("---------actual-----------");
new XMLOutputter(Format.getPrettyFormat()).output(creoleXml, System.err);
}
assertTrue("XML produced by annotation handler does not match expected: " + diff.toString(), match);
}
use of org.custommonkey.xmlunit.ElementNameQualifier in project ddf by codice.
the class CswFilterDelegateTest method testRelative.
@Test
public void testRelative() throws JAXBException, SAXException, IOException {
long duration = 92000000000L;
CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, false, CswConstants.CSW_TYPE, effectiveDateMapping, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
CswFilterDelegate localCswFilterDelegate = createCswFilterDelegate(cswSourceConfiguration);
Map<String, Object> propMap = new HashMap<>();
propMap.put("extendedComparisonOp", "relative");
propMap.put("duration", new Long(duration));
String xml = getXmlProperty(localCswFilterDelegate, propertyNameModified, BETWEEN, testStartDate.toCalendar(null).getTime(), testEndDate.toCalendar(null).getTime(), propMap);
String durationCompare = duringXml.replace(REPLACE_START_DATE, "").replace(REPLACE_END_DATE, "").replace(REPLACE_TEMPORAL_PROPERTY, modifiedDateMapping);
String pattern = "(?i)(<ns.:Literal>)(.+?)(</ns.:Literal>)";
String compareXml = xml.replaceAll(pattern, "<ogc:Literal xmlns:ogc=\"http://www.opengis.net/ogc\"></ogc:Literal>");
Diff xmlDiff = new Diff(durationCompare, compareXml);
xmlDiff.overrideElementQualifier(new ElementNameQualifier() {
@Override
protected boolean equalsNamespace(Node control, Node test) {
return true;
}
});
xmlDiff.overrideDifferenceListener(new DifferenceListener() {
@Override
public int differenceFound(Difference diff) {
if (diff.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
}
return RETURN_ACCEPT_DIFFERENCE;
}
@Override
public void skippedComparison(Node arg0, Node arg1) {
}
});
assertXMLIdentical(xmlDiff, true);
}
Aggregations