本文整理匯總了Java中org.custommonkey.xmlunit.Diff類的典型用法代碼示例。如果您正苦於以下問題:Java Diff類的具體用法?Java Diff怎麽用?Java Diff使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Diff類屬於org.custommonkey.xmlunit包,在下文中一共展示了Diff類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testMergeNodeChildrenMultiple
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
@Test
/**
* Tests that when the source node has multiple nodes with the same name, and the destination has none of that name,
* all instances of that node get appended to the destination
*/
public void testMergeNodeChildrenMultiple() throws Exception {
DocumentNodeMerger merger = new DocumentNodeMerger();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
Document doc1 = documentBuilder.parse(new ByteArrayInputStream("<a></a>".getBytes(StandardCharsets.UTF_8)));
Document doc2 = documentBuilder.parse(new ByteArrayInputStream("<a><b>1</b><b>2</b><b>3</b></a>".getBytes(StandardCharsets.UTF_8)));
Document expected = documentBuilder.parse(new ByteArrayInputStream("<a><b>1</b><b>2</b><b>3</b></a>".getBytes(StandardCharsets.UTF_8)));
merger.mergeNodeChildren(doc1.getDocumentElement(), doc2.getDocumentElement());
Diff diff = XMLUnit.compareXML(expected, doc1);
Assert.assertTrue(buildXmlDiffMessage(diff), diff.similar());
}
示例2: 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());
}
示例3: testConfigurationMerging
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
public void testConfigurationMerging()
throws Exception
{
XMLUnit.setNormalizeWhitespace( true );
InputStream resourceAsStream = getClass().getResourceAsStream( "/components-1.xml" );
transformer.processResource( "components-1.xml", resourceAsStream,
Collections.<Relocator> emptyList() );
resourceAsStream.close();
InputStream resourceAsStream1 = getClass().getResourceAsStream( "/components-2.xml" );
transformer.processResource( "components-1.xml", resourceAsStream1,
Collections.<Relocator> emptyList() );
resourceAsStream1.close();
final InputStream resourceAsStream2 = getClass().getResourceAsStream( "/components-expected.xml" );
Diff diff = XMLUnit.compareXML(
IOUtil.toString( resourceAsStream2, "UTF-8" ),
IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ) );
//assertEquals( IOUtil.toString( getClass().getResourceAsStream( "/components-expected.xml" ), "UTF-8" ),
// IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ).replaceAll("\r\n", "\n") );
resourceAsStream2.close();
XMLAssert.assertXMLIdentical( diff, true );
}
開發者ID:javiersigler,項目名稱:apache-maven-shade-plugin,代碼行數:24,代碼來源:ComponentsXmlResourceTransformerTest.java
示例4: testCreateElement
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
@Test
public void testCreateElement() throws Exception {
final Document document = XmlUtil.newDocument();
final Element top = XmlUtil.createElement(document, "top", Optional.of("namespace"));
top.appendChild(XmlUtil.createTextElement(document, "innerText", "value", Optional.of("namespace")));
top.appendChild(XmlUtil.createTextElementWithNamespacedContent(document, "innerPrefixedText", "pref", "prefixNamespace", "value", Optional.of("namespace")));
top.appendChild(XmlUtil.createTextElementWithNamespacedContent(document, "innerPrefixedText", "pref", "prefixNamespace", "value", Optional.of("randomNamespace")));
document.appendChild(top);
assertEquals("top", XmlUtil.createDocumentCopy(document).getDocumentElement().getTagName());
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setIgnoreWhitespace(true);
final Diff diff = XMLUnit.compareXML(XMLUnit.buildControlDocument(xml), document);
assertTrue(diff.toString(), diff.similar());
}
示例5: testSerializeDeserializeAnyXmlNode
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
@Test
public void testSerializeDeserializeAnyXmlNode() throws Exception {
final ByteArrayInputStream is =
new ByteArrayInputStream("<xml><data/></xml>".getBytes(Charset.defaultCharset()));
final Document parse = UntrustedXML.newDocumentBuilder().parse(is);
final AnyXmlNode anyXmlNode = Builders.anyXmlBuilder()
.withNodeIdentifier(id("anyXmlNode"))
.withValue(new DOMSource(parse))
.build();
final byte[] bytes = SerializationUtils.serializeNormalizedNode(anyXmlNode);
final NormalizedNode<?, ?> deserialized = SerializationUtils.deserializeNormalizedNode(bytes);
final DOMSource value = (DOMSource) deserialized.getValue();
final Diff diff = XMLUnit.compareXML((Document) anyXmlNode.getValue().getNode(),
value.getNode().getOwnerDocument());
Assert.assertTrue(diff.toString(), diff.similar());
}
示例6: assertMetadataEquals
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
private void assertMetadataEquals( String expectedMetadataXml, File actualFile )
throws Exception
{
assertNotNull( "Actual File should not be null.", actualFile );
assertTrue( "Actual file exists.", actualFile.exists() );
StringWriter actualContents = new StringWriter();
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile );
RepositoryMetadataWriter.write( metadata, actualContents );
DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
if ( !detailedDiff.similar() )
{
assertEquals( expectedMetadataXml, actualContents );
}
// assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
}
示例7: writeDeliverResponse
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
@Test
public void writeDeliverResponse() throws Exception {
DeliverResponse deliverResponse = new DeliverResponse();
deliverResponse.setErrorCode(5);
deliverResponse.setErrorMessage("Success");
StringWriter sw = new StringWriter();
SxmpWriter.write(sw, deliverResponse);
logger.debug(sw.toString());
StringBuilder expectedXML = new StringBuilder(200)
.append("<?xml version=\"1.0\"?>\n")
.append("<operation type=\"deliver\">\n")
.append(" <deliverResponse>\n")
.append(" <error code=\"5\" message=\"Success\"/>\n")
.append(" </deliverResponse>\n")
.append("</operation>\n")
.append("");
// compare to actual correct submit response
XMLUnit.setIgnoreWhitespace(true);
Diff myDiff = new Diff(expectedXML.toString(), sw.toString());
DetailedDiff myDetailedDiff = new DetailedDiff(myDiff);
Assert.assertTrue("XML are similar " + myDetailedDiff, myDetailedDiff.similar());
}
示例8: writeDeliveryReportResponse
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
@Test
public void writeDeliveryReportResponse() throws Exception {
DeliveryReportResponse deliveryResponse = new DeliveryReportResponse();
deliveryResponse.setErrorCode(5);
deliveryResponse.setErrorMessage("Success");
StringWriter sw = new StringWriter();
SxmpWriter.write(sw, deliveryResponse);
logger.debug(sw.toString());
StringBuilder expectedXML = new StringBuilder(200)
.append("<?xml version=\"1.0\"?>\n")
.append("<operation type=\"deliveryReport\">\n")
.append(" <deliveryReportResponse>\n")
.append(" <error code=\"5\" message=\"Success\"/>\n")
.append(" </deliveryReportResponse>\n")
.append("</operation>\n")
.append("");
// compare to actual correct submit response
XMLUnit.setIgnoreWhitespace(true);
Diff myDiff = new Diff(expectedXML.toString(), sw.toString());
DetailedDiff myDetailedDiff = new DetailedDiff(myDiff);
Assert.assertTrue("XML are similar " + myDetailedDiff, myDetailedDiff.similar());
}
示例9: testDecryption
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
protected void testDecryption(String fragment, CamelContext context) throws Exception {
MockEndpoint resultEndpoint = context.getEndpoint("mock:decrypted", MockEndpoint.class);
resultEndpoint.setExpectedMessageCount(1);
// verify that the message was encrypted before checking that it is decrypted
testEncryption(fragment, context);
resultEndpoint.assertIsSatisfied(100);
Exchange exchange = resultEndpoint.getExchanges().get(0);
Document inDoc = getDocumentForInMessage(exchange);
if (log.isDebugEnabled()) {
logMessage(exchange, inDoc);
}
Assert.assertFalse("The XML message has encrypted data.", hasEncryptedData(inDoc));
// verify that the decrypted message matches what was sent
Document fragmentDoc = createDocumentfromInputStream(new ByteArrayInputStream(fragment.getBytes()), context);
Diff xmlDiff = XMLUnit.compareXML(fragmentDoc, inDoc);
Assert.assertTrue("The decrypted document does not match the control document.", xmlDiff.identical());
}
示例10: assertModelEqualsFile
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
protected void assertModelEqualsFile(String expectedPath) throws Exception {
File actualFile = tmpFolder.newFile();
Dmn.writeModelToFile(actualFile, modelInstance);
File expectedFile = ReflectUtil.getResourceAsFile(expectedPath);
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document actualDocument = docBuilder.parse(actualFile);
Document expectedDocument = docBuilder.parse(expectedFile);
Diff diff = new Diff(expectedDocument, actualDocument);
if (!diff.similar()) {
diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
DetailedDiff detailedDiff = new DetailedDiff(diff);
String failMsg = "XML differs:\n" + detailedDiff.getAllDifferences() + "\n\nActual XML:\n" + Dmn.convertToString(modelInstance);
fail(failMsg);
}
}
示例11: testExecuteRpcWithXmlResponse
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
@Test
public void testExecuteRpcWithXmlResponse() throws Exception {
RpcCommand rpc = new RpcCommand();
rpc.setContext("FOO");
rpc.setName("BAR");
rpc.getParams().add("baz");
rpc.getParams().add("spaz");
rpc.setFormat("xml");
when(mockRpcTemplate.execute("FOO/BAR", rpc.getParams())).thenReturn(new RpcResponse("<foo><bar>w00t</bar></foo>"));
ModelAndView mav = controller.execute(rpc, new BeanPropertyBindingResult(rpc, "rpc"));
assertThat(mav.getViewName(), is(StringView.DEFAULT_VIEW_NAME));
assertThat((String) mav.getModel().get(StringView.DEFAULT_CONTENT_TYPE_KEY), is("application/xml"));
Diff xmlDiff = new Diff("<?xml version=\"1.0\" encoding=\"utf-8\"?><foo><bar>w00t</bar></foo>", (String) mav.getModel().get(StringView.DEFAULT_MODEL_KEY));
assertTrue(xmlDiff.toString(), xmlDiff.similar());
verify(mockRpcTemplate).execute("FOO/BAR", rpc.getParams());
}
示例12: testMarshalFullEntry
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
@Test
public void testMarshalFullEntry() throws IOException, SAXException {
String expected = FileCopyUtils.copyToString(new InputStreamReader(this.getClass().getResourceAsStream("entry-full.xml")));
Entry entry = new Entry();
entry.setId("http://example.com/blog/1234");
entry.setTitle(new Text("Atom-Powered Robots Run Amok"));
entry.setAuthor(AtomFactory.createPerson("Flintstone, Fred"));
entry.setContent(new Content("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget tortor quam, mollis porta quam. Nam placerat sem consectetur magna semper bibendum. Duis pretium pellentesque nisi, id rhoncus augue porta eget. Nulla facilisi. Nam non augue sed leo auctor pretium. Curabitur et lacus odio, ac mattis velit. In eget dapibus metus. In condimentum, lacus ac fringilla hendrerit, turpis mauris imperdiet nulla, non mattis dolor quam vitae leo. Morbi nec velit sit amet odio commodo consectetur. Mauris semper nulla at mi vulputate malesuada."));
entry.setLink(AtomFactory.createLink("alternate", "/blog/1234"));
entry.setSummary(new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit."));
entry.setUpdated(new PointInTime(1975, 7, 23, 10, 13, 34, 0));
entry.setPublished(new PointInTime(1984, 3, 11, 22, 43, 9));
entry.addToCategories(AtomFactory.createCategory("Foo"));
entry.addToCategories(AtomFactory.createCategory("Bar"));
entry.addToContributors(AtomFactory.createPerson("Flintstone, Wilma"));
entry.addToContributors(AtomFactory.createPerson("Rubble, Barney"));
entry.setRights(AtomFactory.createText("html", "© 1984 Fred Flintstone"));
String xml = new POMXmlMapper().writerWithDefaultPrettyPrinter().writeValueAsString(entry);
Diff xmlDiff = new Diff(expected, xml);
Assert.assertTrue(xmlDiff.toString(), xmlDiff.similar());
}
示例13: compareXmlIgnoringWhitespace
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
/**
* Compares XML documents provided by the two Readers.
*
* @param expected The expected document data.
* @param actual The actual document data.
* @return A DetailedDiff object, describing all differences in documents supplied.
* @throws org.xml.sax.SAXException If a SAXException was raised during parsing of the two Documents.
* @throws IOException If an I/O-related exception was raised while acquiring the data from the Readers.
*/
protected static Diff compareXmlIgnoringWhitespace(final String expected, final String actual) throws SAXException,
IOException {
// Check sanity
org.apache.commons.lang3.Validate.notNull(expected, "Cannot handle null expected argument.");
org.apache.commons.lang3.Validate.notNull(actual, "Cannot handle null actual argument.");
// Ignore whitespace - and also normalize the Documents.
XMLUnit.setNormalize(true);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setNormalize(true);
// Compare and return
return XMLUnit.compareXML(expected, actual);
}
示例14: validateProcessingNodes
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
@Test
public void validateProcessingNodes() {
// Assemble
final String newPrefix = "changedFoo";
final String oldPrefix = "foo";
final String originalXml = getXmlDocumentSample(oldPrefix);
final String changedXml = getXmlDocumentSample(newPrefix);
final NodeProcessor changeNamespacePrefixProcessor = new ChangeNamespacePrefixProcessor(oldPrefix, newPrefix);
// Act
final Document processedDocument = XsdGeneratorHelper.parseXmlStream(new StringReader(originalXml));
XsdGeneratorHelper.process(processedDocument.getFirstChild(), true, changeNamespacePrefixProcessor);
// Assert
final Document expectedDocument = XsdGeneratorHelper.parseXmlStream(new StringReader(changedXml));
final Diff diff = new Diff(expectedDocument, processedDocument, null, new ElementNameAndAttributeQualifier());
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
XMLAssert.assertXMLEqual(processedDocument, expectedDocument);
}
示例15: testMessageWithMultipleTypes
import org.custommonkey.xmlunit.Diff; //導入依賴的package包/類
@Test
public void testMessageWithMultipleTypes() throws SAXException, IOException {
//@formatter:off
String msg = "<Patient xmlns=\"http://hl7.org/fhir\">"
+ "<identifier><label value=\"SSN\" /><system value=\"http://orionhealth.com/mrn\" /><value value=\"PRP1660\" /></identifier>"
+ "</Patient>";
//@formatter:on
Patient patient1 = ourCtx.newXmlParser().parseResource(Patient.class, msg);
String encoded1 = ourCtx.newXmlParser().encodeResourceToString(patient1);
ca.uhn.fhir.testmodel.Patient patient2 = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.testmodel.Patient.class, msg);
String encoded2 = ourCtx.newXmlParser().encodeResourceToString(patient2);
Diff d = new Diff(new StringReader(encoded1), new StringReader(encoded2));
assertTrue(d.toString(), d.identical());
}