当前位置: 首页>>代码示例>>Java>>正文


Java Diff类代码示例

本文整理汇总了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());

}
 
开发者ID:Accuity,项目名称:xml-document-merge,代码行数:23,代码来源:DocumentNodeMergerTest.java

示例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());
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:21,代码来源:RestXMLOnlySteps.java

示例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());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:XmlUtilTest.java

示例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());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:SerializationUtilsTest.java

示例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 );
}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:20,代码来源:MetadataTransferTest.java

示例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());
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:27,代码来源:SxmpWriterTest.java

示例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());
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:27,代码来源:SxmpWriterTest.java

示例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());            
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:TestHelper.java

示例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);
  }
}
 
开发者ID:camunda,项目名称:camunda-dmn-model,代码行数:20,代码来源:DmnModelTest.java

示例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());
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:21,代码来源:RpcControllerTests.java

示例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", "&copy; 1984 Fred Flintstone"));

    String xml = new POMXmlMapper().writerWithDefaultPrettyPrinter().writeValueAsString(entry);
    Diff xmlDiff = new Diff(expected, xml);
    Assert.assertTrue(xmlDiff.toString(), xmlDiff.similar());
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:24,代码来源:EntryXmlSerializationTests.java

示例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);
}
 
开发者ID:mojohaus,项目名称:jaxb2-maven-plugin,代码行数:25,代码来源:AbstractSourceCodeAwareNodeProcessingTest.java

示例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);
}
 
开发者ID:mojohaus,项目名称:jaxb2-maven-plugin,代码行数:22,代码来源:XsdGeneratorHelperTest.java

示例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());

}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:20,代码来源:XmlParserTest.java


注:本文中的org.custommonkey.xmlunit.Diff类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。