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


Java Difference类代码示例

本文整理汇总了Java中org.custommonkey.xmlunit.Difference的典型用法代码示例。如果您正苦于以下问题:Java Difference类的具体用法?Java Difference怎么用?Java Difference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Difference类属于org.custommonkey.xmlunit包,在下文中一共展示了Difference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: differenceFound

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
/**
 * On each difference this method is called by XMLUnit framework to
 * determine whether we accept the difference or ignore it. If any of the
 * provided regular expression match with xml xpath location at which
 * difference found then ignore the difference.
 *
 * @param difference
 *            contains information about differences.
 */
public int differenceFound(Difference difference) {
    Iterator<Pattern> it = this.ignorableRegexPatters.iterator();
    final String xpathLocation = difference.getTestNodeDetail()
            .getXpathLocation();
    while (it.hasNext()) {
        final Pattern pattern = it.next();
        final Matcher m = pattern.matcher(xpathLocation);
        if (m.find()) {
            return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
            /** ignore it, not a valid difference */
        }
    }
    return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
    /** no objection, mark it as a valid difference */
}
 
开发者ID:bhits,项目名称:common-libraries,代码行数:25,代码来源:RegexBasedDifferenceListener.java

示例2: identicalExceptAdditionalFieldsInActual

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
/**
 * 
 * @return true si les deux résultats XML sont identiques en ignorant les champs supplémentaires dans le résultat du process ("actual result")
 * qui ne sont pas présents dans le résultat attendu ("expected result").
 */
public boolean identicalExceptAdditionalFieldsInActual() {
	boolean notIdentical = false;
	
	for (Difference difference : this.getAllDifferences()) {
		if (difference.getId() == DifferenceConstants.CHILD_NODELIST_LENGTH_ID) {
			// possibilité d'accepter des champs en plus dans le "actual"
			int expectedCount = Integer.parseInt(difference.getControlNodeDetail().getValue());
			int actualCount = Integer.parseInt(difference.getTestNodeDetail().getValue());
			
			if (expectedCount > actualCount) { // on accepte les différences s'il y a plus dans le actual que dans l'expected mais pas l'inverse
				notIdentical = true;
			}
		}
	}
	
	return (this.identical() && !notIdentical);
}
 
开发者ID:fastconnect,项目名称:tibco-fcunit,代码行数:23,代码来源:FCDiff.java

示例3: getAdditionalFieldsInActual

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
/**
 * 
 * @return La liste des champs supplémentaires présents dans le résultat d'un process ("actual result")
 * et non présent dans le résultat attendu ("expected result") sous forme de différences ({@link org.custommonkey.xmlunit.Difference}).
 */
public List<Difference> getAdditionalFieldsInActual() {
	List<Difference> differences = new ArrayList<Difference>(this.getAllDifferences()); // deep-copy of the differences
	
    for (Iterator<Difference> it = differences.iterator(); it.hasNext(); ) {
    	Difference difference = it.next();
        if (difference.getId() == DifferenceConstants.CHILD_NODELIST_LENGTH_ID) {
			int expectedCount = Integer.parseInt(difference.getControlNodeDetail().getValue());
			int actualCount = Integer.parseInt(difference.getTestNodeDetail().getValue());
			
			if (expectedCount > actualCount) { // on accepte les différences s'il y a plus dans le actual que dans l'expected mais pas l'inverse
	            it.remove();
			}
        }
        else {
            it.remove();
        }
    }
    
	return differences;
}
 
开发者ID:fastconnect,项目名称:tibco-fcunit,代码行数:26,代码来源:FCDiff.java

示例4: differenceFound

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
public int differenceFound(Difference difference) {
    // ignore <recordTime> presence
    if (difference.equals(DifferenceConstants.CHILD_NODE_NOT_FOUND)
            && "recordTime".equals(difference.getTestNodeDetail().getValue())) {
        return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
    }
    // ignore <recordTime> value
    if (difference.equals(DifferenceConstants.TEXT_VALUE)
            && "recordTime".equals(difference.getTestNodeDetail().getNode().getParentNode().getNodeName())) {
        return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
    }
    // check if <eventTime> equal
    if (difference.equals(DifferenceConstants.TEXT_VALUE)
            && "eventTime".equals(difference.getTestNodeDetail().getNode().getParentNode().getNodeName())) {
        try {
            Calendar testCal = TimeParser.parseAsCalendar(difference.getTestNodeDetail().getValue());
            Calendar controlCal = TimeParser.parseAsCalendar(difference.getControlNodeDetail().getValue());
            return controlCal.getTimeInMillis() == testCal.getTimeInMillis() ? RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL
                    : RETURN_ACCEPT_DIFFERENCE;
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    return ignore.contains(difference) ? RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL : RETURN_ACCEPT_DIFFERENCE;
}
 
开发者ID:Fosstrak,项目名称:fosstrak-epcis,代码行数:26,代码来源:QueryResultsComparator.java

示例5: differentValueAttributeOnInput

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
/**
 * Checks this heuristic: if the attribute that has been modified is the "value" attribute of an
 * "input" element, it is much likely to be a false difference
 */
static boolean differentValueAttributeOnInput(Difference difference) {
  String controlNodeXpath = difference.getTestNodeDetail().getXpathLocation();

  if ((controlNodeXpath != null) && controlNodeXpath.endsWith("@value")
      && (difference.getId() == 3)) {
    String nodeName = "input";
    String[] elements = controlNodeXpath.split("/");
    String secondLastElement = elements[elements.length - 2];

    if ((secondLastElement != null) && secondLastElement.startsWith(nodeName)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:google,项目名称:zarathustra,代码行数:20,代码来源:Heuristics.java

示例6: dumpDifferences

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
/**
 * Saves a text representation of the differences in a file.
 */
public static void dumpDifferences(List<Difference> differences, String filePath)
    throws IOException {
  StringBuilder sb = new StringBuilder();
  RulesJsonSerializer serializer = new RulesJsonSerializer(filePath + ".json");

  for (Difference difference : differences) {
    sb.append(
        "--- Difference " + difference.getId() + " at "
            + difference.getTestNodeDetail().getXpathLocation() + " ---\n"
            + difference.toString()).append("\n\n");
  }
  File dumpFile = new File(filePath);
  Files.write(sb.toString(), dumpFile, Charsets.UTF_8);
  serializer.printDifferencesToFile(differences);
}
 
开发者ID:google,项目名称:zarathustra,代码行数:19,代码来源:DifferenceHelper.java

示例7: test_doubleDifference_withBaseDifferences

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
public void test_doubleDifference_withBaseDifferences() throws IOException {
  firstDocument.getChildNodes().item(0).getChildNodes().item(0)
      .appendChild(firstDocument.createTextNode("VAL1"));
  secondDocument.getChildNodes().item(0).getChildNodes().item(0)
      .appendChild(secondDocument.createTextNode("VAL2"));
  secondDocument.getChildNodes().item(0).appendChild(secondDocument.createElement("script"));
  thirdDocument.getChildNodes().item(0).getChildNodes().item(0)
      .appendChild(thirdDocument.createTextNode("VAL3"));
  thirdDocument.getChildNodes().item(0).appendChild(thirdDocument.createElement("script"));
  Element nodeToEdit = (Element) thirdDocument.getChildNodes().item(0).getChildNodes().item(0);
  Attr attributeToEdit = thirdDocument.createAttribute("src");
  attributeToEdit.setValue("http://127.0.0.1/");
  nodeToEdit.setAttributeNode(attributeToEdit);
  serializeDocs();
  List<Difference> diff =
      DifferenceHelper.getDifferences(firstFile, ImmutableList.of(secondFile), thirdFile);

  assertEquals(1, diff.size());
  assertEquals("/rootElement[1]/script[1]/@src", diff.get(0).getTestNodeDetail()
      .getXpathLocation());
}
 
开发者ID:google,项目名称:zarathustra,代码行数:22,代码来源:DifferenceHelperTest.java

示例8: test_doubleDifference_withDifferentDifferences

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
public void test_doubleDifference_withDifferentDifferences() throws IOException {
  firstDocument.getChildNodes().item(0).getChildNodes().item(0)
      .appendChild(firstDocument.createTextNode("VAL1"));
  secondDocument.getChildNodes().item(0).getChildNodes().item(0)
      .appendChild(secondDocument.createElement("foobar"));
  secondDocument.getChildNodes().item(0).appendChild(secondDocument.createTextNode("Data2"));
  thirdDocument.getChildNodes().item(0).getChildNodes().item(0)
      .appendChild(thirdDocument.createTextNode("VAL3"));
  thirdDocument.getChildNodes().item(0).getChildNodes().item(0)
      .appendChild(thirdDocument.createElement("barfoo"));
  thirdDocument.getChildNodes().item(0).appendChild(thirdDocument.createTextNode("Data3"));

  serializeDocs();
  List<Difference> diff =
      DifferenceHelper.getDifferences(firstFile, ImmutableList.of(secondFile), thirdFile);

  assertEquals(2, diff.size());
  assertEquals("/rootElement[1]/script[1]/text()[1]", diff.get(0).getTestNodeDetail()
      .getXpathLocation());
  assertEquals("/rootElement[1]/script[1]/barfoo[1]", diff.get(1).getTestNodeDetail()
      .getXpathLocation());
}
 
开发者ID:google,项目名称:zarathustra,代码行数:23,代码来源:DifferenceHelperTest.java

示例9: differenceFound

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
/**
 * On each difference this method is called by XMLUnit framework to
 * determine whether we accept the difference or ignore it. If any of the
 * provided regular expression match with xml xpath location at which
 * difference found then ignore the difference.
 * 
 * @param difference
 *            contains information about differences.
 */
public int differenceFound(Difference difference) {
	Iterator<Pattern> it = this.ignorableRegexPatters.iterator();
	final String xpathLocation = difference.getTestNodeDetail()
			.getXpathLocation();
	while (it.hasNext()) {
		final Pattern pattern = it.next();
		final Matcher m = pattern.matcher(xpathLocation);
		if (m.find()) {
			return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
			/** ignore it, not a valid difference */
		}
	}
	return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
	/** no objection, mark it as a valid difference */
}
 
开发者ID:tlin-fei,项目名称:ds4p,代码行数:25,代码来源:RegexBasedDifferenceListener.java

示例10: differenceFound

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
@Override
public int differenceFound(Difference difference) {
  final String xpath = "/updated[1]/text()[1]";
  if(difference.getControlNodeDetail().getXpathLocation().endsWith(xpath)) {
    String controlValue = difference.getControlNodeDetail().getValue();
    String testValue = difference.getTestNodeDetail().getValue();
    // Allow a difference of up to 2 seconds.
    try {
      long controlTime = UPDATED_FORMAT.parse(controlValue).getTime();
      long testTime = UPDATED_FORMAT.parse(testValue).getTime();
      long diff = controlTime - testTime;
      if (diff < 0) {
        diff = diff * -1;
      }
      if (diff <= MAX_ALLOWED_UPDATED_DIFFERENCE) {
        return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
      }
    } catch (ParseException e) {
      throw new RuntimeException("Parse exception for updated value (see difference '" + difference + "').");
    }
  }
  // Yes it is a difference so throw an exception.
  return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:25,代码来源:ODataXmlSerializerTest.java

示例11: differenceFound

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
@Override
public int differenceFound(Difference difference) {

	if ("id".equals(difference.getControlNodeDetail().getNode().getParentNode().getNodeName())) {
		// Difference found in id attribute...
		String controlValue = difference.getControlNodeDetail().getValue();
		String testValue = difference.getTestNodeDetail().getValue();

		// only compare the prefix...
		if (getPrefix(controlValue).equals(getPrefix(testValue))) {
			return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
		}
	}

	return RETURN_ACCEPT_DIFFERENCE;
}
 
开发者ID:dana-i2cat,项目名称:mqnaas,代码行数:17,代码来源:UnitSerializationTest.java

示例12: differenceFound

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
@Override
public int differenceFound(Difference diff) {

    if (diff.getId() == DifferenceConstants.TEXT_VALUE.getId()) {
        String control = diff.getControlNodeDetail().getValue();
        if (control != null) {
            control = control.trim();
            if (diff.getTestNodeDetail().getValue() != null
                && control.equals(diff.getTestNodeDetail().getValue().trim())) {
                return
                    DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
            }
        }
    }
    return RETURN_ACCEPT_DIFFERENCE;
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:17,代码来源:IgnoreWhiteCharsDiffListener.java

示例13: canIgnore

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
@Override
public boolean canIgnore (Difference difference)
{
    // Check for redundancy
    if (info.canIgnoreDiff(difference.getDescription())) {
        return true;
    }

    if (canIgnore(difference.getControlNodeDetail().getNode())) {
        return true;
    }

    if (canIgnore(difference.getTestNodeDetail().getNode())) {
        return true;
    }

    return false;
}
 
开发者ID:jlpoolen,项目名称:libreveris,代码行数:19,代码来源:BasicFilter.java

示例14: differenceFound

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
@Override
public int differenceFound(Difference difference) {
	if (difference.getControlNodeDetail() == null
	        || difference.getControlNodeDetail().getNode() == null
	        || difference.getTestNodeDetail() == null
	        || difference.getTestNodeDetail().getNode() == null) {
		return RETURN_ACCEPT_DIFFERENCE;
	}
	if (ignoreAttributes.contains(difference.getTestNodeDetail().getNode()
	        .getNodeName())
	        || ignoreAttributes.contains(difference.getControlNodeDetail()
	                .getNode().getNodeName())) {
		return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
	}
	return RETURN_ACCEPT_DIFFERENCE;
}
 
开发者ID:aminmf,项目名称:crawljax,代码行数:17,代码来源:DomDifferenceListener.java

示例15: comparePartialDifference

import org.custommonkey.xmlunit.Difference; //导入依赖的package包/类
@Test
public void comparePartialDifference() throws IOException {
	String controlHTML =
	        "<html><body><header>Crawljax</header><p>There are differences</p></body></html>";
	String testHTML =
	        "<html><head><title>Crawljax</title></head><body><p>There are differences.</body></html>";
	final int EXPECTED_DIFF = 5;

	Document control = DomUtils.asDocument(controlHTML);
	assertNotNull(control);

	Document test = DomUtils.asDocument(testHTML);
	assertNotNull(test);

	DOMComparer dc = new DOMComparer(control, test);

	List<Difference> differences = dc.compare();
	assertEquals("Error: Did not find 5 differences", differences.size(), EXPECTED_DIFF);

}
 
开发者ID:aminmf,项目名称:crawljax,代码行数:21,代码来源:DOMComparerTest.java


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