本文整理汇总了Java中org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener类的典型用法代码示例。如果您正苦于以下问题:Java IgnoreTextAndAttributeValuesDifferenceListener类的具体用法?Java IgnoreTextAndAttributeValuesDifferenceListener怎么用?Java IgnoreTextAndAttributeValuesDifferenceListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IgnoreTextAndAttributeValuesDifferenceListener类属于org.custommonkey.xmlunit包,在下文中一共展示了IgnoreTextAndAttributeValuesDifferenceListener类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: thenXMLResponseSimilarToFile
import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; //导入依赖的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.IgnoreTextAndAttributeValuesDifferenceListener; //导入依赖的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.IgnoreTextAndAttributeValuesDifferenceListener; //导入依赖的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: testTranslation
import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; //导入依赖的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);
}
示例5: testEjbJar
import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; //导入依赖的package包/类
/**
* TODO Doesn't seem there are any asserts here
*
* @throws Exception
*/
public void testEjbJar() throws Exception {
final String fileName = "ejb-jar-example1.xml";
final Event test = Event.start("Test");
final URL resource = this.getClass().getClassLoader().getResource(fileName);
final String expected = IO.slurp(resource);
final Event ejbJarJAXBCreate = Event.start("EjbJarJAXBCreate");
ejbJarJAXBCreate.stop();
final Event unmarshalEvent = Event.start("unmarshal");
final Object value;
final EjbJar$JAXB jaxbType = new EjbJar$JAXB();
value = Sxc.unmarshalJavaee(resource, jaxbType);
unmarshalEvent.stop();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Event marshall = Event.start("marshall");
Sxc.marshall(jaxbType, value, baos);
marshall.stop();
final String result = new String(baos.toByteArray(), "UTF-8");
XMLUnit.setIgnoreComments(Boolean.TRUE);
XMLUnit.setIgnoreWhitespace(Boolean.TRUE);
XMLUnit.setIgnoreAttributeOrder(Boolean.TRUE);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(Boolean.TRUE);
final Diff diff = new Diff(expected.trim(), result.trim());
final Diff myDiff = new DetailedDiff(diff);
final AtomicInteger differenceNumber = new AtomicInteger(0); // just to get an int wrapper for the test
myDiff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener() {
@Override
public int differenceFound(final Difference difference) {
if (!difference.isRecoverable()) {
differenceNumber.incrementAndGet();
System.err.println(">>> " + difference.toString());
}
return 0;
}
});
assertTrue("Files are not identical", myDiff.identical());
test.stop();
}
示例6: testNormalizedNodeToXmlSerialization
import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; //导入依赖的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);
}
示例7: testWrite
import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; //导入依赖的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