本文整理汇总了Java中org.custommonkey.xmlunit.Diff.similar方法的典型用法代码示例。如果您正苦于以下问题:Java Diff.similar方法的具体用法?Java Diff.similar怎么用?Java Diff.similar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.custommonkey.xmlunit.Diff
的用法示例。
在下文中一共展示了Diff.similar方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: test1
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
public void test1() throws Exception {
XMLUnit.setIgnoreWhitespace(true);
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Java2WSDLBuilder builder = new Java2WSDLBuilder(out, ComplexDataTypes.class.getName(), ComplexDataTypes.class.getClassLoader());
builder.generateWSDL();
FileReader control = new FileReader(wsdlLocation);
StringReader test = new StringReader(new String(out.toByteArray()));
Diff myDiff = new Diff(XMLUnit.buildDocument(XMLUnit.getControlParser(), control),
XMLUnit.buildDocument(XMLUnit.getControlParser(), test),
new WSDLDifferenceEngine(new WSDLController()), new WSDLElementQualifier());
if (!myDiff.similar())
fail(myDiff.toString());
} finally {
XMLUnit.setIgnoreWhitespace(false);
}
}
示例3: test1
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
public void test1() throws Exception {
XMLUnit.setIgnoreWhitespace(true);
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Java2WSDLBuilder builder = new Java2WSDLBuilder(out, BaseDataTypes.class.getName(), BaseDataTypes.class.getClassLoader());
builder.generateWSDL();
FileReader control = new FileReader(wsdlLocation);
StringReader test = new StringReader(new String(out.toByteArray()));
Diff myDiff = new Diff(XMLUnit.buildDocument(XMLUnit.getControlParser(), control),
XMLUnit.buildDocument(XMLUnit.getControlParser(), test),
(DifferenceEngine) null, new WSDLElementQualifier());
if (!myDiff.similar())
fail(myDiff.toString());
} finally {
XMLUnit.setIgnoreWhitespace(false);
}
}
示例4: test1
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
public void test1() throws Exception {
XMLUnit.setIgnoreWhitespace(true);
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Java2WSDLBuilder builder = new Java2WSDLBuilder(out, GenericService.class.getName(), GenericService.class.getClassLoader());
builder.generateWSDL();
FileReader control = new FileReader(wsdlLocation);
StringReader test = new StringReader(new String(out.toByteArray()));
Diff myDiff = new Diff(XMLUnit.buildDocument(XMLUnit.getControlParser(), control),
XMLUnit.buildDocument(XMLUnit.getControlParser(), test),
new WSDLDifferenceEngine(new WSDLController()), new WSDLElementQualifier());
if (!myDiff.similar()) {
fail(myDiff.toString());
}
} finally {
XMLUnit.setIgnoreWhitespace(false);
}
}
示例5: doAssertXmlEquals
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
private static void doAssertXmlEquals(String expectedXml, String actualXml) throws Exception {
Diff diff = new Diff(expectedXml, actualXml);
diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
if (!diff.similar()) {
fail(String.format("\nExpected the following XML\n" + formatXml(expectedXml) +
"\nbut actual XML was\n\n" +
formatXml(actualXml)));
}
}
示例6: assertXmlEqual
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
/**
* Parse the expected and actual content strings as XML and assert that the
* two are "similar" -- i.e. they contain the same elements and attributes
* regardless of order.
* <p>Use of this method assumes the
* <a href="http://xmlunit.sourceforge.net/">XMLUnit<a/> library is available.
* @param expected the expected XML content
* @param actual the actual XML content
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Object...)
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Map, Object...)
*/
public void assertXmlEqual(String expected, String actual) throws Exception {
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
Document control = XMLUnit.buildControlDocument(expected);
Document test = XMLUnit.buildTestDocument(actual);
Diff diff = new Diff(control, test);
if (!diff.similar()) {
AssertionErrors.fail("Body content " + diff.toString());
}
}
示例7: assertXmlSimilar
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
/** @see Diff#similar() */
public static void assertXmlSimilar(String expected, String actual) throws IOException, SAXException {
Diff diff = new Diff(expected, actual);
if (!diff.similar()) {
fail(diff.toString());
}
}
示例8: different
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
public static boolean different(Element e1, Element e2) throws IOException, SAXException
{
// logger.debug("e1="+Utils.element2String(e1, false));
// logger.debug("e2="+Utils.element2String(e2, false));
Diff diff = new Diff(Utils.element2String(e1, false), Utils.element2String(e2, false));
boolean similiar = diff.similar();
// logger.debug("identical="+diff.identical()+", similar="+similiar);
return !similiar;
}
示例9: testSimilarityBetweenFileAndModel
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
/**
* Verify if model from file is similar to model created by test.
*
* @throws Exception If model from file can not be read.
*/
@Test
public void testSimilarityBetweenFileAndModel() throws Exception {
String refXml = getFirstBinding().toString();
String newXml = createTestModel().toString();
XMLUnit.setIgnoreWhitespace(true);
Diff diff = XMLUnit.compareXML(refXml, newXml);
if (!diff.similar()) {
System.out.println("Expected\n" + refXml);
System.out.println("Generated\n" + newXml);
}
assertTrue(diff.toString(), diff.similar());
}
示例10: testCreoleAnnotationHandler
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
/**
* Take a skeleton creole.xml file, process the annotations on the classes it
* mentions and compare the resulting XML to the expected result.
*/
public void testCreoleAnnotationHandler() throws Exception {
URL originalUrl = new URL(TestDocument.getTestServerName()+"tests/creole-annotation-handler/initial-creole.xml");
org.jdom.Document creoleXml =
jdomBuilder.build(originalUrl.openStream());
CreoleAnnotationHandler processor = new CreoleAnnotationHandler(new Plugin.Directory(new URL(TestDocument.getTestServerName()+"tests/creole-annotation-handler/")));
processor.processAnnotations(creoleXml);
URL expectedURL = new URL(TestDocument.getTestServerName()+"tests/creole-annotation-handler/expected-creole.xml");
// XMLUnit requires the expected and actual results as W3C DOM rather than
// JDOM
DocumentBuilder docBuilder = jaxpFactory.newDocumentBuilder();
org.w3c.dom.Document targetXmlDOM =
docBuilder.parse(expectedURL.openStream());
org.w3c.dom.Document actualXmlDOM = jdom2dom.output(creoleXml);
Diff diff = XMLUnit.compareXML(targetXmlDOM, actualXmlDOM);
// compare parameter elements with the same NAME, resources with the same
// CLASS, and all other elements that have the same element name
diff.overrideElementQualifier(new ElementNameQualifier() {
@Override
public boolean qualifyForComparison(Element control, Element test) {
if("PARAMETER".equals(control.getTagName()) && "PARAMETER".equals(test.getTagName())) {
return control.getAttribute("NAME").equals(test.getAttribute("NAME"));
}
else if("RESOURCE".equals(control.getTagName()) && "RESOURCE".equals(test.getTagName())) {
String controlClass = findClass(control);
String testClass = findClass(test);
return (controlClass == null) ? (testClass == null)
: controlClass.equals(testClass);
}
else {
return super.qualifyForComparison(control, test);
}
}
private String findClass(Element resource) {
Node node = resource.getFirstChild();
while(node != null && !"CLASS".equals(node.getNodeName())) {
node = node.getNextSibling();
}
if(node != null) {
return node.getTextContent();
}
else {
return null;
}
}
});
// do the comparison!
boolean match = diff.similar();
if(!match) {
// if comparison failed, output the "actual" result document for
// debugging purposes
System.err.println("---------actual-----------");
new XMLOutputter(Format.getPrettyFormat()).output(creoleXml, System.err);
}
assertTrue("XML produced by annotation handler does not match expected: "
+ diff.toString() , match);
}
示例11: addRemoveModuleTest
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
@Test
public void addRemoveModuleTest() throws IOException, CommandFailedException, CliException, SAXException {
String directoryName = "directory with spaces";
if (client.version().lessThan(ServerVersion.VERSION_2_0_0)) {
// AS7 doesn't accept paths with spaces
directoryName = "directory_without_spaces";
}
File testJar1 = createTestJar("testJar1.jar", directoryName);
File testJar2 = createTestJar("testJar2.jar", null);
AddModule addModule = new AddModule.Builder(TEST_MODULE_NAME)
.resource(testJar1)
.resource(testJar2)
.resourceDelimiter(":")
.dependency("org.hibernate")
.dependency("org.jboss.as.controller")
.mainClass("test.mainclass")
.property("foo", "bar")
.property("john", "doe")
.build();
client.apply(addModule);
// verify that module was added
File asRoot = new File(getPathToAs());
File module = new File(asRoot, "modules" + File.separator + TEST_MODULE_NAME.replaceAll("\\.", File.separator));
assertTrue("Module " + module.getAbsolutePath() + " should exist on path", module.exists());
File moduleTestJar1 = new File(module, "main" + File.separator + testJar1.getName());
assertTrue("File " + moduleTestJar1.getAbsolutePath() + " should exist", moduleTestJar1.exists());
File moduleTestJar2 = new File(module, "main" + File.separator + testJar2.getName());
assertTrue("File " + moduleTestJar2.getAbsolutePath() + " should exist", moduleTestJar2.exists());
File moduleXml = new File(module, "main" + File.separator + "module.xml");
assertTrue("File " + moduleXml.getName() + " should exist in " + module.getAbsolutePath(), moduleXml.exists());
Diff diff = new Diff(EXPECTED_MODULE_XML, Files.toString(moduleXml, Charsets.UTF_8));
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
if (!diff.similar()) {
fail(diff.toString());
}
// remove test module
RemoveModule removeModule = new RemoveModule(TEST_MODULE_NAME);
client.apply(removeModule);
// verify that module was removed
assertFalse("Module shouldn't exist on path " + module.getAbsolutePath(), module.exists());
}
示例12: isSimilar
import org.custommonkey.xmlunit.Diff; //导入方法依赖的package包/类
/**
* This method will compare both XMLs and WILL NOT validate its attribute order
*
* @param expected what are we expecting
* @param actual what we receive
* @return if they have same value
*/
public static boolean isSimilar(final String expected, final String actual) {
final Diff diff = createDiffResult(expected, actual, true);
return diff.similar();
}