本文整理汇总了Java中org.xmlunit.diff.DefaultNodeMatcher类的典型用法代码示例。如果您正苦于以下问题:Java DefaultNodeMatcher类的具体用法?Java DefaultNodeMatcher怎么用?Java DefaultNodeMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultNodeMatcher类属于org.xmlunit.diff包,在下文中一共展示了DefaultNodeMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareXML
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
public static void compareXML(String expectedXML, String actualXML) throws SAXException, IOException {
Diff xmlDiff = DiffBuilder.compare(expectedXML).withTest(actualXML)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName))
.ignoreWhitespace().normalizeWhitespace()
.checkForSimilar()
.build();
try {
assertFalse("pieces of XML are not similar\n" + xmlDiff, xmlDiff.hasDifferences());
} catch (AssertionError ae) {
System.out.println("--------------- ActualXML ---------------");
System.out.println(actualXML);
System.out.println("=========================================");
System.out.println("-------------- ExpectedXML --------------");
System.out.println(expectedXML);
System.out.println("=========================================");
throw ae;
}
}
示例2: testPerformExport
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public final void testPerformExport() throws IOException, SaveException {
String xmlFileName = filename.replace(".bib", ".xml");
Path importFile = resourceDir.resolve(filename);
List<BibEntry> entries = testImporter.importDatabase(importFile, StandardCharsets.UTF_8).getDatabase()
.getEntries();
msBibExportFormat.export(databaseContext, tempFile, charset, entries);
Builder control = Input.from(Files.newInputStream(resourceDir.resolve(xmlFileName)));
Builder test = Input.from(Files.newInputStream(tempFile));
assertThat(test, CompareMatcher.isSimilarTo(control)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
}
示例3: testPerformExport
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public final void testPerformExport() throws IOException, SaveException {
String xmlFileName = filename.replace(".bib", ".xml");
Path importFile = resourceDir.resolve(filename);
String tempFilename = tempFile.getCanonicalPath();
List<BibEntry> entries = testImporter.importDatabase(importFile, StandardCharsets.UTF_8).getDatabase()
.getEntries();
bibtexmlExportFormat.export(databaseContext, tempFile.toPath(), charset, entries);
Builder control = Input.from(Files.newInputStream(resourceDir.resolve(xmlFileName)));
Builder test = Input.from(Files.newInputStream(Paths.get(tempFilename)));
Assert.assertThat(test, CompareMatcher.isSimilarTo(control)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
}
示例4: testImportAsModsAndExportAsMods
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public final void testImportAsModsAndExportAsMods() throws Exception {
String xmlFileName = filename.replace(".bib", ".xml");
String tempFilename = tempFile.getCanonicalPath();
Path xmlFile = Paths.get(ModsExportFormatTestFiles.class.getResource(xmlFileName).toURI());
List<BibEntry> entries = modsImporter.importDatabase(xmlFile, charset).getDatabase().getEntries();
modsExportFormat.export(databaseContext, tempFile.toPath(), charset, entries);
Builder control = Input.from(Files.newInputStream(xmlFile));
Builder test = Input.from(Files.newInputStream(Paths.get(tempFilename)));
Assert.assertThat(test, CompareMatcher.isSimilarTo(control)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
}
示例5: compare
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
public XMLFileAssertion compare(Builder in1, Builder in2) {
diffBuilder = DiffBuilder.compare(in1).withTest(in2).withNodeFilter(new Predicate<Node>() {
public boolean test(Node node) {
LOGGER.trace("current node " + node.getNodeName() + " result "
+ String.valueOf(!tokens.contains(node.getNodeName())));
return !tokens.contains(node.getNodeName());
}
}).withAttributeFilter(new Predicate<Attr>() {
public boolean test(Attr a) {
LOGGER.trace("current attr " + a.getName() + " result "
+ String.valueOf(!attrs.contains(a.getName())));
return !attrs.contains(a.getName());
}
});
if(context.ignoreWhitespaces){
diffBuilder.ignoreWhitespace();
}if(context.checkForIdentical){
diffBuilder.checkForIdentical();
}if(context.checkForSimilar){
diffBuilder.checkForSimilar();
}if(context.selector!=null){
diffBuilder.withNodeMatcher(new DefaultNodeMatcher(context.selector));
}
return this;
}
示例6: valueCompositeXmlEquality
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public void valueCompositeXmlEquality()
{
// START SNIPPET: xml-serialization
try( UnitOfWork uow = unitOfWorkFactory.newUnitOfWork() )
{
Some valueInstance = buildSomeValue( moduleInstance, uow, "42" );
// Serialize using injected service
String serializedXml = xmlSerialization.serialize( valueInstance );
System.out.println( serializedXml );
// Deserialize using Module API
Some valueFromSerializedState = moduleInstance.newValueFromSerializedState( Some.class, serializedXml );
assertThat( "Deserialized Value equality", valueInstance, equalTo( valueFromSerializedState ) );
// END SNIPPET: xml-serialization
// value.toString()
// Need to loosely compare because of HashMaps not retaining order
String valueXmlWithoutTypeInfo = xmlSerialization.serialize( Serializer.Options.NO_TYPE_INFO, valueFromSerializedState );
assertThat( "value.toString() XML equality",
valueFromSerializedState.toString(),
isSimilarTo( valueXmlWithoutTypeInfo )
.withNodeMatcher( new DefaultNodeMatcher( ElementSelectors.byNameAndAllAttributes ) ) );
// START SNIPPET: xml-serialization
}
// END SNIPPET: xml-serialization
}
示例7: compareXml
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
public static void compareXml(String content, String reEncoded) {
Diff d = DiffBuilder.compare(Input.fromString(content))
.withTest(Input.fromString(reEncoded))
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
.checkForSimilar()
.ignoreWhitespace() // this is working with newest Saxon 9.8.0-2 (not worked with 9.7.0-15
.ignoreComments() // this is not working even with newest Saxon 9.8.0-2
.withComparisonController(ComparisonControllers.Default)
.build();
assertTrue(d.toString(), !d.hasDifferences());
}
示例8: compareXml
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
public static void compareXml(String content, String reEncoded) {
Diff d = DiffBuilder.compare(Input.fromString(content))
.withTest(Input.fromString(reEncoded))
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
.checkForSimilar()
.ignoreWhitespace()
.ignoreComments()
.withComparisonController(ComparisonControllers.Default)
.build();
assertTrue(d.toString(), !d.hasDifferences());
}
示例9: testPerformExport
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public final void testPerformExport() throws Exception {
String xmlFileName = filename.replace(".bib", ".xml");
String tempFilename = tempFile.getCanonicalPath();
List<BibEntry> entries = bibtexImporter.importDatabase(importFile, charset).getDatabase().getEntries();
Path xmlFile = Paths.get(ModsExportFormatTestFiles.class.getResource(xmlFileName).toURI());
modsExportFormat.export(databaseContext, tempFile.toPath(), charset, entries);
Builder control = Input.from(Files.newInputStream(xmlFile));
Builder test = Input.from(Files.newInputStream(Paths.get(tempFilename)));
Assert.assertThat(test, CompareMatcher.isSimilarTo(control)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
}
示例10: testIsIdenticalTo_withAssertionErrorForElementOrder_throwsReadableMessage
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public void testIsIdenticalTo_withAssertionErrorForElementOrder_throwsReadableMessage() {
// Expected Exception
expect(AssertionError.class);
expectMessage("Expected child nodelist sequence '0' but was '1'");
expectMessage("comparing <b...> at /a[1]/b[1] to <b...> at /a[1]/b[1]");
// run test:
assertThat("<a><c/><b/></a>", isIdenticalTo("<a><b/><c/></a>")
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)));
}
示例11: tryToSelectMatchingChildNodesUsingXPath
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public void tryToSelectMatchingChildNodesUsingXPath() throws Exception {
ElementSelector childSelector = selectorForElementNamed("child", byXPath("./*[1]", byName));
assertThat(fromString(test1),
isSimilarTo(fromString(test2))
.withNodeMatcher(new DefaultNodeMatcher(childSelector, byName)));
}
示例12: tryToSelectMatchingChildNodesUsingXPathAlpha02
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
@Ignore("doesn't work with XMLUnit > 2.0.0-alpha-02")
public void tryToSelectMatchingChildNodesUsingXPathAlpha02() throws Exception {
ElementSelector childSelector = selectorForElementNamed("child", byXPath("./child/*[1]", byName));
assertThat(fromString(test1),
isSimilarTo(fromString(test2))
.withNodeMatcher(new DefaultNodeMatcher(childSelector, byName)));
}
示例13: tryToSelectMatchingChildNodesUsingCustomElementSelector
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public void tryToSelectMatchingChildNodesUsingCustomElementSelector() throws Exception {
ElementSelector childSelector = selectorForElementNamed("child", new FirstChildElementNameSelector());
assertThat(fromString(test1),
isSimilarTo(fromString(test2))
.withNodeMatcher(new DefaultNodeMatcher(childSelector, byName)));
}
示例14: testIsSimilarTo_withAssertionErrorForElementOrder_throwsReadableMessage
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public void testIsSimilarTo_withAssertionErrorForElementOrder_throwsReadableMessage() {
// run test:
assertThat("<a><c/><b/></a>", isSimilarTo("<a><b/><c/></a>")
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)));
}
示例15: canBeCombinedWithPassingMatcher
import org.xmlunit.diff.DefaultNodeMatcher; //导入依赖的package包/类
@Test
public void canBeCombinedWithPassingMatcher() {
assertThat("<a><c/><b/></a>", both(not(isEmptyString()))
.and(isSimilarTo("<a><b/><c/></a>")
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))));
}