diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
/** * Extended constructor for multiple qualifying attribute names * @param attrNames the array of values to use to qualify whether two * elements can be compared further for differences */ public ElementNameAndAttributeQualifier(String[] attrNames) { this.qualifyingAttrNames = new String[attrNames.length]; System.arraycopy(attrNames, 0, qualifyingAttrNames, 0, attrNames.length); selector = matchesAllAttributes(attrNames) ? ElementSelectors.byNameAndAllAttributes : ElementSelectors.byNameAndAttributesControlNS(attrNames); }
/** * Determine whether two elements qualify for further Difference comparison. * @param differenceEngine the DifferenceEngine instance wanting to * determine if the elements are comparable * @param control * @param test * @return true if the two elements qualify for further comparison based on * both the superclass qualification (namespace URI and non- namespaced tag * name), and the presence of qualifying attributes with the same values; * false otherwise */ public boolean qualifyForComparison(Element control, Element test) { if (super.qualifyForComparison(control, test)) { return areAttributesComparable(control, test); } return false; }
Attr[] qualifyingAttributes; NamedNodeMap namedNodeMap = control.getAttributes(); if (matchesAllAttributes(qualifyingAttrNames)) { qualifyingAttributes = new Attr[namedNodeMap.getLength()]; for (int n=0; n < qualifyingAttributes.length; ++n) {
Diff diff = new Diff(control, test, null, new ElementNameAndAttributeQualifier("name"));
Attr[] qualifyingAttributes; NamedNodeMap namedNodeMap = control.getAttributes(); if (matchesAllAttributes(qualifyingAttrNames)) { qualifyingAttributes = new Attr[namedNodeMap.getLength()]; for (int n=0; n < qualifyingAttributes.length; ++n) {
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier())
Diff diff = new Diff(doc1, doc2); diff.overrideElementQualifier(new ElementNameAndAttributeQualifier()); XMLAssert.assertXMLEqual(diff, Boolean.TRUE);
Diff diff = new Diff(controlXml, responseXml); diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
private boolean compareContents(InputStream expectedData, ByteArrayInputStream neo4jGraphMlRepresentation) { try { configureXmlUnit(); Diff diff = new Diff(new InputSource(neo4jGraphMlRepresentation), new InputSource(expectedData)); diff.overrideElementQualifier(new ElementNameAndAttributeQualifier()); if (diff.similar()) { return true; } else { String differenceMessage = buildDifferenceMessage(diff); throw FailureHandler.createFailure(differenceMessage); } } catch (SAXException e) { throw new IllegalArgumentException(e); } catch (IOException e) { throw new IllegalArgumentException(e); } }
private boolean compareContents(InputStream expectedData, ByteArrayInputStream neo4jGraphMlRepresentation) { try { configureXmlUnit(); Diff diff = new Diff(new InputSource(neo4jGraphMlRepresentation), new InputSource(expectedData)); diff.overrideElementQualifier(new ElementNameAndAttributeQualifier()); if (diff.similar()) { return true; } else { String differenceMessage = buildDifferenceMessage(diff); throw FailureHandler.createFailure(differenceMessage); } } catch (SAXException e) { throw new IllegalArgumentException(e); } catch (IOException e) { throw new IllegalArgumentException(e); } }
/** * Constructor of XmlUnit Diff with ElementNameAndAttributeQualifier * * @param controlDocument XML document that contains expected results * @param testedDocument XML document which is being tested */ public DiffWithAttributeQualifier(Document controlDocument, Document testedDocument) { super(controlDocument, testedDocument); this.overrideElementQualifier(new ElementNameAndAttributeQualifier()); this.overrideDifferenceListener(new DifferenceListenerIgnoreWhitespace()); }
/** * Constructor of XmlUnit Diff with ElementNameAndAttributeQualifier * * @param controlDocument String containing XML document that contains * expected results * @param testedDocument String containing XML document which is being * tested * @throws java.io.IOException * @throws org.xml.sax.SAXException */ public DiffWithAttributeQualifier(String controlDocument, String testedDocument) throws IOException, SAXException { super(controlDocument, testedDocument); this.overrideElementQualifier(new ElementNameAndAttributeQualifier()); this.overrideDifferenceListener(new DifferenceListenerIgnoreWhitespace()); } }
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
private boolean isdifferent(Document testDoc, Document controlDoc) { boolean isdifferent = false; XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.setNormalize(true); Diff myDiff = new Diff(controlDoc, testDoc); DetailedDiff myComparisonController = new DetailedDiff(myDiff); DifferenceEngine engine = new DifferenceEngine(myComparisonController); XmlDifferenceListener listener = new XmlDifferenceListener(); ElementNameAndAttributeQualifier myElementQualifier = new ElementNameAndAttributeQualifier(); try { //debug engine.compare(controlDoc.getDocumentElement(), testDoc.getDocumentElement(), listener, myElementQualifier); } catch (NullPointerException ne) { LOG.error(ne); } isdifferent =listener.called(); return isdifferent; } }
public void testSerialize() throws Exception { ServerConfiguration config = new ServerConfigurationParser(new FileInputStream(FCFG_BASE)) .parse(); ByteArrayOutputStream out = new ByteArrayOutputStream(); config.serialize(out); Document original = builder.parse(FCFG_BASE); Document generated = builder.parse(new ByteArrayInputStream(out.toByteArray())); XMLUnit.setIgnoreWhitespace(true); Diff diff = new Diff(original, generated); diff.overrideElementQualifier(new ElementNameAndAttributeQualifier()); assertXMLEqual(diff, true); }
public void testRoundTrip() throws Exception { StringWriter sw = new StringWriter(); InputStream original = getClass().getClassLoader().getResourceAsStream("testmodel_data.xml"); XMLUnit.setIgnoreWhitespace(true); Collection<FastPathObject> unmarshalled = (Collection<FastPathObject>) binding.unmarshal(original); setIds(unmarshalled); binding.marshal(unmarshalled, sw); // System.out.println(sw.toString()); String expected = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("testmodel_data.xml")); Diff diff = new Diff(expected, sw.toString()); DetailedDiff detail = new DetailedDiff(diff); detail.overrideElementQualifier(new ElementNameAndAttributeQualifier()); assertTrue(detail.getAllDifferences().toString() + ": Original: " + expected + ", Generated: " + sw.toString(), detail.similar()); }
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());