org.xmlunit.diff.Diff.hasDifferences()方法的使用及代码示例

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

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

Diff.hasDifferences介绍

暂无

代码示例

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

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

代码示例来源: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: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

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: 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: 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: 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: 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: 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: org.mock-server/mockserver-core

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: dita-ot/dita-ot

public static void assertXMLEqual(InputSource exp, InputSource act) {
  try {
    final Diff d;
    d = DiffBuilder
        .compare(ignoreComments(builderFactory.newDocumentBuilder().parse(exp)))
        .withTest(ignoreComments(builderFactory.newDocumentBuilder().parse(act)))
        .ignoreWhitespace()
        .withNodeFilter(node -> node.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE)
        .build();
    if (d.hasDifferences()) {
      throw new AssertionError(d.toString());
    }
  } catch (SAXException | IOException | ParserConfigurationException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源: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

public static void assertHtmlEqual(InputSource exp, InputSource act) {
  final DocumentBuilderFactory builderFactory = new HTMLDocumentBuilderFactory();
  try {
    final Diff d = DiffBuilder
        .compare(ignoreComments(builderFactory.newDocumentBuilder().parse(exp)))
        .withTest(ignoreComments(builderFactory.newDocumentBuilder().parse(act)))
        .ignoreWhitespace()
        .normalizeWhitespace()
        .withNodeFilter(node -> node.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE)
        .build();
    if (d.hasDifferences()) {
      throw new AssertionError(d.toString());
    }
  } catch (SAXException | IOException | ParserConfigurationException e) {
    throw new RuntimeException(e);
  }
}

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

public static void assertXMLEqual(Document exp, Document act) {
  final Diff d = DiffBuilder
      .compare(ignoreComments(exp))
      .withTest(ignoreComments(act))
      .ignoreWhitespace()
      .normalizeWhitespace()
      .withNodeFilter(node -> node.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE)
      .build();
  if (d.hasDifferences()) {
    throw new AssertionError(d.toString());
  }
}

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

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

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

@Override
public boolean isExactMatch() {
  if (isNullOrEmpty(value)) {
    return false;
  }
  try {
    Diff diff = DiffBuilder.compare(Input.from(expectedValue))
      .withTest(value)
      .withComparisonController(ComparisonControllers.StopWhenDifferent)
      .ignoreWhitespace()
      .ignoreComments()
      .withDifferenceEvaluator(IGNORE_UNCOUNTED_COMPARISONS)
      .withNodeMatcher(new OrderInvariantNodeMatcher())
      .withDocumentBuilderFactory(Xml.newDocumentBuilderFactory())
      .build();
    return !diff.hasDifferences();
  } catch (XMLUnitException e) {
    notifier().info("Failed to process XML. " + e.getMessage() +
      "\nExpected:\n" + expectedValue +
      "\n\nActual:\n" + value);
    return false;
  }
}

代码示例来源:origin: com.powsybl/powsybl-commons

protected static void compareXml(InputStream expected, InputStream actual) {
  Source control = Input.fromStream(expected).build();
  Source test = Input.fromStream(actual).build();
  Diff myDiff = DiffBuilder.compare(control).withTest(test).ignoreWhitespace().ignoreComments().build();
  boolean hasDiff = myDiff.hasDifferences();
  if (hasDiff) {
    System.err.println(myDiff.toString());
  }
  assertFalse(hasDiff);
}

代码示例来源:origin: de.juplo.yourshouter.api/data-model

public void assertXmlEquals(String path, ByteArrayOutputStream os)
{
 Diff diff =
   DiffBuilder
     .compare(Input.fromStream(TestData.get(path)))
     .withTest(Input.fromByteArray(os.toByteArray()))
     .ignoreComments()
     .ignoreWhitespace()
     .withComparisonFormatter(new ShowDiffComparisonFormatter())
     .build();
 assertFalse(diff.toString(), diff.hasDifferences());
}

代码示例来源:origin: de.juplo.yourshouter.api/data-model

@Override
 public void compareTo(String path, ByteArrayOutputStream os)
 {
  Diff diff =
    DiffBuilder
      .compare(Input.fromStream(TestData.get(path + ".xml")))
      .withTest(Input.fromByteArray(os.toByteArray()))
      .ignoreComments()
      .ignoreWhitespace()
      .withComparisonFormatter(new ShowDiffComparisonFormatter())
      .build();
  assertFalse(diff.toString(), diff.hasDifferences());
 }
}

相关文章