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


Java DifferenceListener类代码示例

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


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

示例1: differenceFound

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的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: differenceFound

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的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

示例3: differenceFound

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的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

示例4: compareAttribute

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
/**
 * Compare two attributes to determine if they are equivalent
 * @param control a known attribute against which a test attribute is being compared
 * @param test the generated attribute that is being tested against a known attribute
 * @param listener 
 * @throws DifferenceFoundException if there is a difference detected between
 *  the two attributes
 */
protected void compareAttribute(Attr control, Attr test,
DifferenceListener listener) throws DifferenceFoundException {    	
	// There are no getter methods for these private fields in DifferenceEngine
	// controlTracker.visited(control);
	// testTracker.visited(test);
	
	compare(control.getPrefix(), test.getPrefix(), control, test, 
		listener, NAMESPACE_PREFIX);

    compare(getValueWithoutNamespace(control), getValueWithoutNamespace(test), control, test,
        listener, ATTR_VALUE);
    
    compare(getValueNamespaceURI(control), getValueNamespaceURI(test), control, test,
            listener, ATTR_VALUE);        
    
    compare(control.getSpecified() ? Boolean.TRUE : Boolean.FALSE,
        test.getSpecified() ? Boolean.TRUE : Boolean.FALSE,
        control, test, listener, ATTR_VALUE_EXPLICITLY_SPECIFIED);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:28,代码来源:WSDLDifferenceEngine.java

示例5: differenceFound

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的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

示例6: textualDifference

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
protected int textualDifference(Difference d) {
    String control = d.getControlNodeDetail().getValue();
    String test = d.getTestNodeDetail().getValue();
    if (control != null && test != null) {
        try {
            double controlVal = Double.parseDouble(control);
            double testVal = Double.parseDouble(test);
            return Math.abs(controlVal - testVal) <= tolerance
                ? DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL
                : DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
        } catch (NumberFormatException nfe) {
            // ignore, delegate to nested DifferenceListener
        }
    }
    // no numbers or null, delegate
    return super.textualDifference(d);
}
 
开发者ID:xmlunit,项目名称:xmlunit,代码行数:18,代码来源:FloatingPointTolerantDifferenceListener.java

示例7: differenceFound

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
@Override
public int differenceFound(Difference difference) {
	try{
		if (isInIgnoredNode(difference) || isCausedByIgnoredChildNode(difference)
				|| isCausedByIgnorableMissingId(difference)
				|| isCausedByIgnorableDifferingId(difference)
				|| isCausedByIgnoredAttribute(difference)
				|| isCausedByOptionalAttribute(difference)
				|| isCausedByIgnorableAttributeValue(difference)
				|| isCausedByNamespaceProblems(difference)
                   || isCausedByAdditionalNamespace(difference)
				|| isCausedByLanguageSettings(difference)
				|| isCausedByCapitalizationOfAttributeValue(difference)
                   || isCausedByAddingDefaultAttribute(difference)
                   || isRedundantSummaryError(difference)
				|| canDifferenceBeIgnored(difference)){
			numIgnoredDiffs++;
			return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
		}
		numAcceptedDiffs++;
		return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
	}catch (Exception e){
		LOGGER.error("Exception while examining difference: " + difference.toString(), e);
		return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
	}
}
 
开发者ID:bpmn-miwg,项目名称:bpmn-miwg-tools,代码行数:27,代码来源:AbstractXmlDifferenceListener.java

示例8: testValidOperations

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
@Test
public void testValidOperations() throws BatchJobException, IOException, SAXException {
  RequestT request = createMutateRequest();
  addBudgetOperation(request, -1L, "Test budget", 50000000L, "STANDARD");
  addCampaignOperation(
      request, -2L, "Test campaign #1", "PAUSED", "SEARCH", -1L, "MANUAL_CPC", false);
  addCampaignOperation(
      request, -3L, "Test campaign #2", "PAUSED", "SEARCH", -1L, "MANUAL_CPC", false);
  addCampaignNegativeKeywordOperation(request, -2L, "venus", "BROAD");
  addCampaignNegativeKeywordOperation(request, -3L, "venus", "BROAD");
  ByteArrayContent httpContent =
      request.createBatchJobUploadBodyProvider().getHttpContent(request, true, true);
  String actualRequestXml = Streams.readAll(httpContent.getInputStream(), Charset.forName(UTF_8));
  actualRequestXml =
      SoapRequestXmlProvider.normalizeXmlForComparison(actualRequestXml, getApiVersion());
  String expectedRequestXml = SoapRequestXmlProvider.getTestBatchUploadRequest(getApiVersion());

  // Perform an XML diff using the custom difference listener that properly handles namespaces
  // and attributes.
  Diff diff = new Diff(expectedRequestXml, actualRequestXml);
  DifferenceListener diffListener = new CustomDifferenceListener();
  diff.overrideDifferenceListener(diffListener);
  XMLAssert.assertXMLEqual("Serialized upload request does not match expected XML", diff, true);
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:25,代码来源:BatchJobUploadBodyProviderTest.java

示例9: assertXMLIgnorePrefix

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
public static void assertXMLIgnorePrefix(String aMessage, Document aExpected, Document aActual) throws Exception {
    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreAttributeOrder(true);

    Diff diff = new Diff(aExpected, aActual);
    diff.overrideDifferenceListener(new DifferenceListener() {

        public void skippedComparison(Node aArg0, Node aArg1) {
        }

        public int differenceFound(Difference aDifference) {
            if (aDifference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
                return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
            }
            return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
        }
    });
    try {
        XMLAssert.assertXMLEqual(diff, true);
    } catch (Throwable t) {
        dump(aActual);
        StringWriter sw = new StringWriter();
        t.printStackTrace(new PrintWriter(sw));
        fail(sw.toString());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:XmlFixture.java

示例10: differenceFound

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
@Override
public int differenceFound(Difference aDifference) {
    if (aDifference.getId() == DifferenceConstants.TEXT_VALUE_ID) {
        if (blackList.contains(aDifference.getControlNodeDetail().getNode()
                .getNodeName())) {
            return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
        }
    }

    return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
 
开发者ID:jwiesel,项目名称:sfdcCommander,代码行数:12,代码来源:IgnoreNamedElementsDifferenceListener.java

示例11: equalsInternal

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
@Override
protected boolean equalsInternal(ObjectLocator leftLocator,
		ObjectLocator rightLocator, Node lhs, Node rhs) {
	final Diff diff = new Diff(new DOMSource(lhs), new DOMSource(rhs)) {
		@Override
		public int differenceFound(Difference difference) {
			if (difference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
				return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
			} else {
				return super.differenceFound(difference);
			}
		}
	};
	return diff.identical();
}
 
开发者ID:highsource,项目名称:hyperjaxb3,代码行数:16,代码来源:ExtendedJAXBEqualsStrategy.java

示例12: sliceUnitSerializationTest

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
@Test
public void sliceUnitSerializationTest() throws JAXBException, IOException, SAXException {

	UnitResource su = new UnitResource(SLICE_UNIT_NAME);

	String serializedXml = SerializationUtils.toXml(su);
	String expectedXml = IOUtils.toString(this.getClass().getResourceAsStream(SLICE_FILE_1));

	DifferenceListener idComparingDifferenceListener = new IDComparingDifferenceListener();
	Diff myDiff = new Diff(expectedXml, serializedXml);
	myDiff.overrideDifferenceListener(idComparingDifferenceListener);

	Assert.assertTrue("Serialized xml should be equals to the expected one.", myDiff.similar());
}
 
开发者ID:dana-i2cat,项目名称:mqnaas,代码行数:15,代码来源:UnitSerializationTest.java

示例13: textualDifference

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
protected int textualDifference(Difference d) {
    String control = d.getControlNodeDetail().getValue();
    if (control != null) {
        control = control.toLowerCase(Locale.US);
        if (d.getTestNodeDetail().getValue() != null
            && control.equals(d.getTestNodeDetail().getValue()
                              .toLowerCase(Locale.US))) {
            return
                DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
        }
    }
    // some string is null, delegate
    return super.textualDifference(d);
}
 
开发者ID:xmlunit,项目名称:xmlunit,代码行数:15,代码来源:CaseInsensitiveDifferenceListener.java

示例14: differenceFound

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
@Override
public int differenceFound(Difference difference) {
  switch (difference.getId()) {
    case DifferenceConstants.NAMESPACE_URI_ID:
      return namespaceDifferenceFound(difference);
    case DifferenceConstants.ELEMENT_NUM_ATTRIBUTES_ID:
    case DifferenceConstants.ATTR_NAME_NOT_FOUND_ID:
      return attributeDifferenceFound(difference);
    default:
      return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
  }
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:13,代码来源:CustomDifferenceListener.java

示例15: namespaceDifferenceFound

import org.custommonkey.xmlunit.DifferenceListener; //导入依赖的package包/类
/**
 * Checks for logical equivalence of the qualified node names.
 */
private int namespaceDifferenceFound(Difference difference) {
  Node controlNode = difference.getControlNodeDetail().getNode();
  Node testNode = difference.getTestNodeDetail().getNode();
  String controlNs = getNamespaceURI(controlNode);
  String testNs = getNamespaceURI(testNode);
  if (Objects.equal(controlNs, testNs)) {
    if (Objects.equal(controlNode.getLocalName(), testNode.getLocalName())) {
      return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
    }
  }
  return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:16,代码来源:CustomDifferenceListener.java


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