org.xmlunit.diff.Diff类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中org.xmlunit.diff.Diff类的一些代码示例,展示了Diff类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Diff类的具体详情如下:
包路径:org.xmlunit.diff.Diff
类名称:Diff

Diff介绍

[英]The Diff-Object is the result of two comparisons.
[中]Diff对象是两个比较的结果。

代码示例

代码示例来源:origin: jamesdbloom/mockserver

public boolean matches(final HttpRequest context, NottableString matched) {
  boolean result = false;
  if (diffBuilder != null) {
    try {
      Diff diff = diffBuilder.withTest(Input.fromString(normaliseXmlString(matched.getValue()))).build();
      result = !diff.hasDifferences();
      if (!result) {
        mockServerLogger.trace("Failed to match [{}] with schema [{}] because [{}]", matched, this.matcher, diff.toString());
      }
    } catch (Exception e) {
      mockServerLogger.trace(context, "Failed to match [{}] with schema [{}] because [{}]", matched, this.matcher, e.getMessage());
    }
  }
  return matcher.isNot() != (not != result);
}

代码示例来源:origin: spring-projects/spring-framework

public boolean hasDifferences() {
  return this.diff.hasDifferences();
}

代码示例来源:origin: org.xmlunit/xmlunit-core

public String toString(ComparisonFormatter formatter) {
  if (!hasDifferences()) {
    return "[identical]";
  }
  return getDifferences().iterator().next().getComparison().toString(formatter);
}

代码示例来源:origin: org.xmlunit/xmlunit-matchers

@Override
public void describeTo(Description description) {
  if (diffResult == null || !diffResult.hasDifferences()) {
    description.appendText(" is ")
      .appendText(checkFor == ComparisonResult.EQUAL ? "equal" : "similar")
      .appendText(" to the control document");
    return;
  }
  final Comparison difference = firstComparison();
  final String reason = createReasonPrefix(diffResult.getControlSource().getSystemId(), difference);
  final String testString = comparisonFormatter.getDetails(difference.getControlDetails(), difference.getType(),
    formatXml);
  description.appendText(String.format("%s:\n%s", reason, testString));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public String toString() {
  return this.diff.toString();
}

代码示例来源:origin: org.xmlunit/xmlunit-matchers

private Comparison firstComparison() {
    return diffResult.getDifferences().iterator().next().getComparison();
  }
}

代码示例来源:origin: org.xmlunit/xmlunit-core

? new Diff(controlSource, testSource, collectResultsListener.getDifferences())
: new Diff(controlSource, testSource, formatter,
      collectResultsListener.getDifferences());

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

public boolean hasDifferences() {
  return this.diff.hasDifferences();
}

代码示例来源:origin: org.xmlunit/xmlunit-core

@Override
public String toString() {
  return toString(formatter);
}

代码示例来源:origin: io.github.valters/xsdiff

public void run( final HtmlContentOutput output, final SemanticDiffFormatter semanticDiff ) {
  this.output = output;
  this.semanticDiff = semanticDiff;
  for( final Difference diff : diffs.getDifferences() ) {
    final Comparison comparison = diff.getComparison();
    if( isAdded( comparison ) ) {
      printAddedNode( comparison );
    }
    else if( isDeleted( comparison ) ) {
      printDeletedNode( comparison );
    }
    else {
      printModifiedNode( comparison );
    }
  }
}

代码示例来源:origin: nl.vpro.shared/vpro-shared-test

public static void similar(InputStream input, InputStream expected) throws IOException, SAXException {
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  IOUtils.copy(input, bytes);
  ByteArrayOutputStream expectedBytes = new ByteArrayOutputStream();
  IOUtils.copy(expected, expectedBytes);
  Diff diff = DiffBuilder
    .compare(expected)
    .withTest(input)
    .checkForSimilar()
    .build();
  if (diff.hasDifferences()) {
    throw new ComparisonFailure(diff.toString(), expectedBytes.toString(), bytes.toString());
  }
}

代码示例来源:origin: stackoverflow.com

import org.w3c.dom.Element;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.util.Nodes;
import org.xmlunit.diff.*;

public class Test {

  public static void main(String[] args) {
    Diff d = DiffBuilder.compare("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                   "<response>\n" +
                   "<bih-metadata>\n" +
                   "<result>Error</result>\n" +
                   "<correlation-id>ID:925977d0-83cd-11e6-b94d-c135e6c73218</correlation-id>\n" +
                   "<error-message>SAXParseException: The entity name must immediately follow the '&amp;' in the entity reference.</error-message>\n" +
                   "</bih-metadata>\n" +
                   "</response>")
      .withTest("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
           "<response>\n" +
           "<bih-metadata>\n" +
           "<result>Error</result>\n" +
           "<correlation-id>ID:134345d0-83cd-11e6-b94d-c135e6c73218</correlation-id>\n" +
           "<error-message>SAXParseException: The entity name must immediately follow the '&amp;' in the entity reference.</error-message>\n" +
           "</bih-metadata>\n" +
           "</response>")
      .withNodeFilter(n -> !(n instanceof Element && "correlation-id".equals(Nodes.getQName(n).getLocalPart())))
      .build();
    System.err.println("Different? " + d.hasDifferences());
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

@Override
public String toString() {
  return this.diff.toString();
}

代码示例来源:origin: com.github.tomakehurst/wiremock-jre8

Joiner.on("\n").join(diff.getDifferences())
);

代码示例来源:origin: nl.vpro.shared/vpro-shared-test

public static void similar(InputStream input, String expected) throws IOException, SAXException {
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  Diff diff = DiffBuilder
    .compare(expected)
    .withTest(input)
    .ignoreComments()
    .checkForSimilar()
    .build();
  if (diff.hasDifferences()) {
    throw new ComparisonFailure(diff.toString(), expected, bytes.toString());
  }
}

代码示例来源:origin: org.xmlunit/xmlunit-matchers

@Override
public boolean matches(Object item) {
  if (checkFor == ComparisonResult.EQUAL) {
    diffBuilder.withComparisonController(ComparisonControllers.StopWhenSimilar);
  } else if (checkFor == ComparisonResult.SIMILAR) {
    diffBuilder.withComparisonController(ComparisonControllers.StopWhenDifferent);
  }
  diffResult = diffBuilder.withTest(item).build();
  if (!diffResult.hasDifferences()) {
    return true;
  }
  if (throwComparisonFailure) {
    AssertionError assertionError = createComparisonFailure();
    if (assertionError != null)
      throw assertionError;
  }
  return false;
}

代码示例来源:origin: nl.vpro.shared/vpro-shared-test

public static void similar(String input, String expected, Consumer<DiffBuilder>... build) throws IOException, SAXException {
  DiffBuilder builder = DiffBuilder
    .compare(expected)
    .withTest(input)
    .ignoreWhitespace()
    .checkForSimilar()
    ;
  for (Consumer<DiffBuilder> b : build) {
    b.accept(builder);
  }
  try {
    Diff diff = builder.build();
    if (diff.hasDifferences()) {
      throw new ComparisonFailure(diff.toString(), expected, input);
    } else {
      assertThat(diff.hasDifferences()).isFalse();
    }
  } catch (XMLUnitException xue) {
    throw new ComparisonFailure(xue.getMessage(), expected, input);
  }
}

代码示例来源:origin: dita-ot/dita-ot

@Test
public void test() throws Exception {
  final ForceUniqueFilter f = new ForceUniqueFilter();
  f.setJob(job);
  f.setTempFileNameScheme(tempFileNameScheme);
  f.setCurrentFile(new File(srcDir, "test.ditamap").toURI());
  f.setParent(SAXParserFactory.newInstance().newSAXParser().getXMLReader());
  final DOMResult dst = new DOMResult();
  TransformerFactory.newInstance().newTransformer().transform(new SAXSource(f, new InputSource(new File(srcDir, "test.ditamap").toURI().toString())), dst);
  final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
  builderFactory.setNamespaceAware(true);
  builderFactory.setIgnoringComments(true);
  final Document exp = builderFactory.newDocumentBuilder().parse(new InputSource(new File(expDir, "test.ditamap").toURI().toString()));
  final Diff d = DiffBuilder
      .compare(exp)
      .withTest(dst.getNode())
      .ignoreWhitespace()
      .build();
  assertFalse(d.hasDifferences());
  assertEquals(new HashMap<FileInfo, FileInfo>(ImmutableMap.of(
      createFileInfo("test.dita", "test_3.dita"),
      createFileInfo("test.dita", "test.dita"),
      createFileInfo("test.dita", "test_2.dita"),
      createFileInfo("test.dita", "test.dita"),
      createFileInfo(null, "copy-to_2.dita"),
      createFileInfo(null, "copy-to.dita")
  )), f.copyToMap);
}

代码示例来源:origin: dita-ot/dita-ot

private void assertXMLEqual(Document exp, Document act) {
  final Diff d = DiffBuilder
      .compare(exp)
      .withTest(act)
      .build();
  if (d.hasDifferences()) {
    throw new AssertionError(d.toString());
  }
}

代码示例来源:origin: dswarm/dswarm

.withTest(Input.fromString(actualDataConfig)).ignoreWhitespace().checkForSimilar().build();
Assert.assertFalse(xmlDiff.hasDifferences());

相关文章