本文整理汇总了Java中org.custommonkey.xmlunit.Diff.overrideDifferenceListener方法的典型用法代码示例。如果您正苦于以下问题:Java Diff.overrideDifferenceListener方法的具体用法?Java Diff.overrideDifferenceListener怎么用?Java Diff.overrideDifferenceListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.custommonkey.xmlunit.Diff
的用法示例。
在下文中一共展示了Diff.overrideDifferenceListener方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: thenXMLResponseSimilarToFile
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Then("verify REST-XML response is similar to '$file'")
public void thenXMLResponseSimilarToFile(String file) throws IOException, SAXException {
File fileFromResources = getFileFromResourcesByFilePath(file);
List<String> expected = Files.readLines(fileFromResources, Charset.defaultCharset());
String expectedXml = expected.stream()
.map(StringUtils::chomp)
.map(StringUtils::strip)
.collect(Collectors.joining());
Response response = getVariableValue(KEY);
String actualXml = response.getBody().asString();
Diff diff = new Diff(expectedXml, actualXml);
diff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
StringBuffer stringBuffer = diff.appendMessage(new StringBuffer());
stringBuffer.append("\nExpected: ")
.append(expectedXml)
.append("\n but: ")
.append(actualXml)
.append("\n");
assertTrue(stringBuffer.toString(), diff.similar());
}
示例2: verifyThatResponseIsSimilarToFile
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Then("verify that response is similar to file '$filePath'")
public void verifyThatResponseIsSimilarToFile(String filePath) throws SOAPException, IOException, SAXException {
FileReader expectedResponseXML = new FileReader(getFileFromResourcesByFilePath(filePath));
SOAPMessage rawSoapResponse = (SOAPMessage) Thucydides.getCurrentSession().get(RESPONSE);
String cleanResponse = getXmlPayload(rawSoapResponse);
StringReader actualResponseXML = new StringReader(cleanResponse);
Diff diff = new Diff(expectedResponseXML, actualResponseXML);
diff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
StringBuffer stringBuffer = diff.appendMessage(new StringBuffer());
assertTrue(stringBuffer.toString(), diff.similar());
}
示例3: verifyFileIsSimilarToFile
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Override
public void verifyFileIsSimilarToFile(String filePath, File lastDownloadedFile) throws IOException, SAXException, ParserConfigurationException {
FileReader controlXML = new FileReader(getFileFromResourcesByFilePath(filePath));
FileReader testXML = new FileReader(lastDownloadedFile);
Diff diff = new Diff(controlXML, testXML);
diff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
XMLAssert.assertXMLEqual(diff, true);
}
示例4: assertXMLIgnorePrefix
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
public static void assertXMLIgnorePrefix(String aMessage, Document aExpected, Document aActual) throws Exception {
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreAttributeOrder(true);
Diff diff = new Diff(aExpected, aActual);
diff.overrideDifferenceListener(new DifferenceListener() {
public void skippedComparison(Node aArg0, Node aArg1) {
}
public int differenceFound(Difference aDifference) {
if (aDifference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
}
return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
});
try {
XMLAssert.assertXMLEqual(diff, true);
} catch (Throwable t) {
dump(aActual);
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
fail(sw.toString());
}
}
示例5: testMerge
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Test
public void testMerge() throws Exception {
SwitchYardModel incomplete_switchyard = _puller.pull(INCOMPLETE_XML, getClass());
SwitchYardModel fragment_switchyard = _puller.pull(FRAGMENT_XML, getClass());
SwitchYardModel merged_switchyard = Models.merge(fragment_switchyard, incomplete_switchyard);
XMLUnit.setIgnoreWhitespace(true);
SwitchYardModel complete_switchyard = _puller.pull(COMPLETE_XML, getClass());
Diff diff = XMLUnit.compareXML(complete_switchyard.toString(), merged_switchyard.toString());
diff.overrideDifferenceListener(new SchemaLocationDifferenceListener());
Assert.assertTrue(diff.toString(), diff.identical());
}
示例6: testMerge
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Test
public void testMerge() throws Exception {
CompositeModel incomplete_composite = _puller.pull(INCOMPLETE_XML, getClass());
CompositeModel fragment_composite = _puller.pull(FRAGMENT_XML, getClass());
CompositeModel merged_composite = Models.merge(fragment_composite, incomplete_composite);
CompositeModel complete_composite = _puller.pull(COMPLETE_XML, getClass());
XMLUnit.setIgnoreWhitespace(true);
Diff diff = XMLUnit.compareXML(complete_composite.toString(), merged_composite.toString());
diff.overrideDifferenceListener(new SchemaLocationDifferenceListener());
assertTrue(diff.toString(), diff.identical());
}
示例7: sliceUnitSerializationTest
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Test
public void sliceUnitSerializationTest() throws JAXBException, IOException, SAXException {
UnitResource su = new UnitResource(SLICE_UNIT_NAME);
String serializedXml = SerializationUtils.toXml(su);
String expectedXml = IOUtils.toString(this.getClass().getResourceAsStream(SLICE_FILE_1));
DifferenceListener idComparingDifferenceListener = new IDComparingDifferenceListener();
Diff myDiff = new Diff(expectedXml, serializedXml);
myDiff.overrideDifferenceListener(idComparingDifferenceListener);
Assert.assertTrue("Serialized xml should be equals to the expected one.", myDiff.similar());
}
示例8: checkXMLEqual
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
private void checkXMLEqual(final String expected, final String resultString) throws SAXException, IOException {
Diff diff = XMLUnit.compareXML(expected, resultString);
diff.overrideDifferenceListener(DIFFERENCE_LISTENER);
XMLAssert.assertXMLEqual(diff, true);
}
示例9: testTranslation
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Test
public void testTranslation() throws Exception {
final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(xmlPath);
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schema, containerNode);
xmlParser.parse(reader);
final NormalizedNode<?, ?> built = result.getResult();
assertNotNull(built);
if (expectedNode != null) {
org.junit.Assert.assertEquals(expectedNode, built);
}
final Document document = UntrustedXML.newDocumentBuilder().newDocument();
final DOMResult domResult = new DOMResult(document);
final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
final XMLStreamWriter xmlStreamWriter = outputFactory.createXMLStreamWriter(domResult);
final NormalizedNodeStreamWriter xmlNormalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter
.create(xmlStreamWriter, schema);
final NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(
xmlNormalizedNodeStreamWriter);
normalizedNodeWriter.write(built);
final Document doc = loadDocument(xmlPath);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setNormalize(true);
final String expectedXml = toString(doc.getDocumentElement());
final String serializedXml = toString(domResult.getNode());
final Diff diff = new Diff(expectedXml, serializedXml);
diff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
diff.overrideElementQualifier(new ElementNameAndTextQualifier());
// FIXME the comparison cannot be performed, since the qualifiers supplied by XMlUnit do not work correctly in
// this case
// We need to implement custom qualifier so that the element ordering does not mess the DIFF
// dd.overrideElementQualifier(new MultiLevelElementNameAndTextQualifier(100, true));
// assertTrue(dd.toString(), dd.similar());
//new XMLTestCase() {}.assertXMLEqual(diff, true);
}
示例10: compare
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
public void compare ()
{
// Comparing
try {
output.println("Comparing " + controlFile + " to " + testFile);
final Document controlDoc;
final Document testDoc;
try (InputStream cis = new FileInputStream(controlFile)) {
controlDoc = new PositionalXMLReader().readXML(cis);
}
try (InputStream tis = new FileInputStream(testFile)) {
testDoc = new PositionalXMLReader().readXML(tis);
}
// Tuning
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
XMLUnit.setNormalizeWhitespace(true);
XMLUnit.setIgnoreWhitespace(true);
///XMLUnit.setIgnoreComments(true); NO!!!!!!!!
// The setIgnoreComments triggers the use of XSLT transform
// which 1/ ruins userdata and 2/ fails on xml:space and xml:lang.
// Moreover, comments are actually ignored by Diff
///XMLUnit.setCompareUnmatched(false); NO need
// Customization
Filter filter = (filterFile != null)
? new BasicFilter(new FileInputStream(filterFile))
: null;
Diff diff = new Diff(controlDoc, testDoc, null);
diff.overrideElementQualifier(
new ElementNameAndAttributeQualifier("number"));
diff.overrideDifferenceListener(
new MusicDifferenceListener(filter, output));
output.println("Similar: " + diff.similar());
output.println("Identical: " + diff.identical());
DetailedDiff detDiff = new DetailedDiff(diff);
List differences = detDiff.getAllDifferences();
output.println();
output.println("Physical differences: " + differences.size());
int diffId = 0;
for (Object object : differences) {
Difference difference = (Difference) object;
if (!difference.isRecoverable()
&& ((filter == null) || !filter.canIgnore(difference))) {
diffId++;
output.dump(diffId, difference);
}
}
output.println("Logical differences: " + diffId);
logger.info("Logical differences: {}", diffId);
} catch (ConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}
}
示例11: identical
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
/**
* Compares the two given QueryResults with each other and returns
* <code>true</code> if they are identical, <code>false</code>
* otherwise. If the two instances are not similar, it prints information to
* System.out.
*
* @param expResults
* The expected QueryResults object.
* @param actResults
* The actual QueryResults object.
* @return <code>true</code> if the two given QueryResults objects are
* identical, <code>false</code> otherwise.
*/
public static boolean identical(final QueryResults expResults, final QueryResults actResults) throws IOException {
Document expDoc = QueryResultsParser.queryResultsToDocument(expResults);
Document actDoc = QueryResultsParser.queryResultsToDocument(actResults);
Diff diff = new Diff(expDoc, actDoc);
diff.overrideDifferenceListener(new MyDifferenceLister());
return diff.identical();
}
示例12: testNormalizedNodeToXmlSerialization
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Test
public void testNormalizedNodeToXmlSerialization() throws XMLStreamException, IOException, SAXException {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/baz.yang");
final Document doc = loadDocument("/baz.xml");
final DOMResult domResult = new DOMResult(UntrustedXML.newDocumentBuilder().newDocument());
final XMLOutputFactory factory = XMLOutputFactory.newInstance();
factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(domResult);
final NormalizedNodeStreamWriter xmlNormalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(
xmlStreamWriter, schemaContext);
final NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(
xmlNormalizedNodeStreamWriter);
normalizedNodeWriter.write(buildOuterContainerNode());
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setNormalize(true);
final String expectedXml = toString(doc.getDocumentElement());
final String serializedXml = toString(domResult.getNode());
final Diff diff = new Diff(expectedXml, serializedXml);
final DifferenceListener differenceListener = new IgnoreTextAndAttributeValuesDifferenceListener();
diff.overrideDifferenceListener(differenceListener);
new XMLTestCase() {}.assertXMLEqual(diff, true);
}
示例13: testWrite
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Test
public void testWrite() throws XMLStreamException, IOException, SAXException {
final Document doc = loadDocument("/foobar.xml");
final DOMResult domResult = new DOMResult(UntrustedXML.newDocumentBuilder().newDocument());
final XMLOutputFactory factory = XMLOutputFactory.newInstance();
factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(domResult);
final NormalizedNodeStreamWriter schemalessXmlNormalizedNodeStreamWriter =
XMLStreamNormalizedNodeStreamWriter.createSchemaless(xmlStreamWriter);
final NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(
schemalessXmlNormalizedNodeStreamWriter);
normalizedNodeWriter.write(buildOuterContainerNode());
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setNormalize(true);
final String expectedXml = toString(doc.getDocumentElement());
final String serializedXml = toString(domResult.getNode());
final Diff diff = new Diff(expectedXml, serializedXml);
final DifferenceListener differenceListener = new IgnoreTextAndAttributeValuesDifferenceListener();
diff.overrideDifferenceListener(differenceListener);
XMLAssert.assertXMLEqual(diff, true);
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:32,代码来源:SchemalessXMLStreamNormalizedNodeStreamWriterTest.java