本文整理汇总了Java中org.custommonkey.xmlunit.XMLUnit.compareXML方法的典型用法代码示例。如果您正苦于以下问题:Java XMLUnit.compareXML方法的具体用法?Java XMLUnit.compareXML怎么用?Java XMLUnit.compareXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.custommonkey.xmlunit.XMLUnit
的用法示例。
在下文中一共展示了XMLUnit.compareXML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMergeNodeChildrenMultiple
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
@Test
/**
* Tests that when the source node has multiple nodes with the same name, and the destination has none of that name,
* all instances of that node get appended to the destination
*/
public void testMergeNodeChildrenMultiple() throws Exception {
DocumentNodeMerger merger = new DocumentNodeMerger();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
Document doc1 = documentBuilder.parse(new ByteArrayInputStream("<a></a>".getBytes(StandardCharsets.UTF_8)));
Document doc2 = documentBuilder.parse(new ByteArrayInputStream("<a><b>1</b><b>2</b><b>3</b></a>".getBytes(StandardCharsets.UTF_8)));
Document expected = documentBuilder.parse(new ByteArrayInputStream("<a><b>1</b><b>2</b><b>3</b></a>".getBytes(StandardCharsets.UTF_8)));
merger.mergeNodeChildren(doc1.getDocumentElement(), doc2.getDocumentElement());
Diff diff = XMLUnit.compareXML(expected, doc1);
Assert.assertTrue(buildXmlDiffMessage(diff), diff.similar());
}
示例2: testConfigurationMerging
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
public void testConfigurationMerging()
throws Exception
{
XMLUnit.setNormalizeWhitespace( true );
InputStream resourceAsStream = getClass().getResourceAsStream( "/components-1.xml" );
transformer.processResource( "components-1.xml", resourceAsStream,
Collections.<Relocator> emptyList() );
resourceAsStream.close();
InputStream resourceAsStream1 = getClass().getResourceAsStream( "/components-2.xml" );
transformer.processResource( "components-1.xml", resourceAsStream1,
Collections.<Relocator> emptyList() );
resourceAsStream1.close();
final InputStream resourceAsStream2 = getClass().getResourceAsStream( "/components-expected.xml" );
Diff diff = XMLUnit.compareXML(
IOUtil.toString( resourceAsStream2, "UTF-8" ),
IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ) );
//assertEquals( IOUtil.toString( getClass().getResourceAsStream( "/components-expected.xml" ), "UTF-8" ),
// IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ).replaceAll("\r\n", "\n") );
resourceAsStream2.close();
XMLAssert.assertXMLIdentical( diff, true );
}
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:24,代码来源:ComponentsXmlResourceTransformerTest.java
示例3: testCreateElement
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
@Test
public void testCreateElement() throws Exception {
final Document document = XmlUtil.newDocument();
final Element top = XmlUtil.createElement(document, "top", Optional.of("namespace"));
top.appendChild(XmlUtil.createTextElement(document, "innerText", "value", Optional.of("namespace")));
top.appendChild(XmlUtil.createTextElementWithNamespacedContent(document, "innerPrefixedText", "pref", "prefixNamespace", "value", Optional.of("namespace")));
top.appendChild(XmlUtil.createTextElementWithNamespacedContent(document, "innerPrefixedText", "pref", "prefixNamespace", "value", Optional.of("randomNamespace")));
document.appendChild(top);
assertEquals("top", XmlUtil.createDocumentCopy(document).getDocumentElement().getTagName());
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setIgnoreWhitespace(true);
final Diff diff = XMLUnit.compareXML(XMLUnit.buildControlDocument(xml), document);
assertTrue(diff.toString(), diff.similar());
}
示例4: testSerializeDeserializeAnyXmlNode
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
@Test
public void testSerializeDeserializeAnyXmlNode() throws Exception {
final ByteArrayInputStream is =
new ByteArrayInputStream("<xml><data/></xml>".getBytes(Charset.defaultCharset()));
final Document parse = UntrustedXML.newDocumentBuilder().parse(is);
final AnyXmlNode anyXmlNode = Builders.anyXmlBuilder()
.withNodeIdentifier(id("anyXmlNode"))
.withValue(new DOMSource(parse))
.build();
final byte[] bytes = SerializationUtils.serializeNormalizedNode(anyXmlNode);
final NormalizedNode<?, ?> deserialized = SerializationUtils.deserializeNormalizedNode(bytes);
final DOMSource value = (DOMSource) deserialized.getValue();
final Diff diff = XMLUnit.compareXML((Document) anyXmlNode.getValue().getNode(),
value.getNode().getOwnerDocument());
Assert.assertTrue(diff.toString(), diff.similar());
}
示例5: testDecryption
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
protected void testDecryption(String fragment, CamelContext context) throws Exception {
MockEndpoint resultEndpoint = context.getEndpoint("mock:decrypted", MockEndpoint.class);
resultEndpoint.setExpectedMessageCount(1);
// verify that the message was encrypted before checking that it is decrypted
testEncryption(fragment, context);
resultEndpoint.assertIsSatisfied(100);
Exchange exchange = resultEndpoint.getExchanges().get(0);
Document inDoc = getDocumentForInMessage(exchange);
if (log.isDebugEnabled()) {
logMessage(exchange, inDoc);
}
Assert.assertFalse("The XML message has encrypted data.", hasEncryptedData(inDoc));
// verify that the decrypted message matches what was sent
Document fragmentDoc = createDocumentfromInputStream(new ByteArrayInputStream(fragment.getBytes()), context);
Diff xmlDiff = XMLUnit.compareXML(fragmentDoc, inDoc);
Assert.assertTrue("The decrypted document does not match the control document.", xmlDiff.identical());
}
示例6: compareXmlIgnoringWhitespace
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
/**
* Compares XML documents provided by the two Readers.
*
* @param expected The expected document data.
* @param actual The actual document data.
* @return A DetailedDiff object, describing all differences in documents supplied.
* @throws org.xml.sax.SAXException If a SAXException was raised during parsing of the two Documents.
* @throws IOException If an I/O-related exception was raised while acquiring the data from the Readers.
*/
protected static Diff compareXmlIgnoringWhitespace(final String expected, final String actual) throws SAXException,
IOException {
// Check sanity
org.apache.commons.lang3.Validate.notNull(expected, "Cannot handle null expected argument.");
org.apache.commons.lang3.Validate.notNull(actual, "Cannot handle null actual argument.");
// Ignore whitespace - and also normalize the Documents.
XMLUnit.setNormalize(true);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setNormalize(true);
// Compare and return
return XMLUnit.compareXML(expected, actual);
}
示例7: testConfigurationMerging
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
public void testConfigurationMerging()
throws Exception
{
XMLUnit.setNormalizeWhitespace( true );
transformer.processResource( "components-1.xml", getClass().getResourceAsStream( "/components-1.xml" ),
Collections.<Relocator> emptyList() );
transformer.processResource( "components-1.xml", getClass().getResourceAsStream( "/components-2.xml" ),
Collections.<Relocator> emptyList() );
Diff diff = XMLUnit.compareXML(
IOUtil.toString( getClass().getResourceAsStream( "/components-expected.xml" ), "UTF-8" ),
IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ) );
//assertEquals( IOUtil.toString( getClass().getResourceAsStream( "/components-expected.xml" ), "UTF-8" ),
// IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ).replaceAll("\r\n", "\n") );
XMLAssert.assertXMLIdentical( diff, true );
}
示例8: testWrapUnwrap
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
@Test
public void testWrapUnwrap() throws Exception {
MockHandler provider = new MockHandler().forwardInToOut();
testKit.registerInOutService("Payments", provider, new InOutService("submit"));
String reply = httpMixIn.postResource("http://localhost:18001/Payments", "wrappedRequest.xml");
String receivedPayload = provider.getMessages().poll(300, TimeUnit.MILLISECONDS)
.getMessage().getContent(String.class);
// verify request is unwrapped
XMLUnit.setIgnoreWhitespace(true);
Diff requestDiff = XMLUnit.compareXML(testKit.readResourceString(UNWRAPPED_PAYLOAD), receivedPayload);
Assert.assertTrue(requestDiff.toString(), requestDiff.similar());
// verify reply is wrapped
Diff replyDiff = XMLUnit.compareXML(testKit.readResourceString(WRAPPED_REPLY), reply);
Assert.assertTrue(replyDiff.toString(), replyDiff.similar());
}
示例9: testCreate
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
@Test
public void testCreate() throws Exception {
SwitchYardModel switchyard = new V1SwitchYardModel(SwitchYardNamespace.V_1_0.uri());
ValidatesModel validates = new V1ValidatesModel(SwitchYardNamespace.V_1_0.uri());
JavaValidateModel javaValidate = new V1JavaValidateModel(ValidateNamespace.V_1_0.uri());
javaValidate.setName(new QName("msgA"));
javaValidate.setClazz("org.examples.validate.AValidate");
validates.addValidate(javaValidate);
XmlValidateModel xmlValidate = new V1XmlValidateModel(ValidateNamespace.V_1_0.uri());
xmlValidate.setName(new QName("msgB"));
xmlValidate.setSchemaType(XmlSchemaType.XML_SCHEMA);
FileEntryModel entry = new V1FileEntryModel(ValidateNamespace.V_1_0.uri()).setFile("/validates/xxx.xml");
SchemaFilesModel schemaFiles = new V1SchemaFilesModel(ValidateNamespace.V_1_0.uri());
schemaFiles.addEntry(entry);
xmlValidate.setSchemaFiles(schemaFiles);
xmlValidate.setFailOnWarning(true);
validates.addValidate(xmlValidate);
switchyard.setValidates(validates);
String new_xml = switchyard.toString();
String old_xml = new ModelPuller<SwitchYardModel>().pull(XML, getClass()).toString();
XMLUnit.setIgnoreWhitespace(true);
Diff diff = XMLUnit.compareXML(old_xml, new_xml);
Assert.assertTrue(diff.toString(), diff.identical());
}
示例10: assertXMLEquals
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
public static void assertXMLEquals(String expectedXML, String actualXML) throws Exception {
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
XMLUnit.setIgnoreAttributeOrder(true);
DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(expectedXML, actualXML));
List<?> allDifferences = diff.getAllDifferences();
Assert.assertEquals("Differences found: "+ diff.toString(), 0, allDifferences.size());
}
示例11: testProcessRuleWillUseParentSourcesWhenRuleHasNoWeight
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
/**
* Tests that rules that have no sources will use the parent's sources
*
* @throws Exception
*/
@Test
public void testProcessRuleWillUseParentSourcesWhenRuleHasNoWeight() throws Exception {
LOG.info("testProcessRuleWillNotMergeUntrustedData");
RuleProcessor ruleProcessor = new RuleProcessor();
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document fdbDocument = documentBuilder.parse(new ByteArrayInputStream("<test source=\"fdb\"><stringElement>fdb</stringElement><complexElement><childElement>fdb</childElement></complexElement></test>".getBytes(StandardCharsets.UTF_8)));
Document zeusDocument = documentBuilder.parse(new ByteArrayInputStream("<test source=\"zeus\"><stringElement>zeus</stringElement><complexElement><childElement>zeus</childElement></complexElement></test>".getBytes(StandardCharsets.UTF_8)));
Map<String, Document> sourceDocuments = new HashMap<>();
sourceDocuments.put("fdb", fdbDocument);
sourceDocuments.put("zeus", zeusDocument);
// simulate what the trusted doc will be after doc root rule is applied
Document trusted = documentBuilder.parse(new ByteArrayInputStream("<test source=\"trusted\"><stringElement>fdb</stringElement><complexElement><childElement></childElement></complexElement></test>".getBytes(StandardCharsets.UTF_8)));
Rule parentRule = new Rule();
parentRule.setWeighting(buildFdbFirstWeighting());
Rule subRule = new Rule();
Field field = new Field();
field.setCoalesce(false);
field.setStop(false);
subRule.setField(field);
subRule.setContext("childElement");
subRule.setFullContextXPath("/test/complexElement/childElement");
subRule.setParentRule(parentRule);
ruleProcessor.processRule(subRule, trusted, sourceDocuments);
Document expected = documentBuilder.parse(new ByteArrayInputStream("<test source=\"trusted\"><stringElement>fdb</stringElement><complexElement><childElement>fdb</childElement></complexElement></test>".getBytes(StandardCharsets.UTF_8)));
Diff diff = XMLUnit.compareXML(expected, trusted);
Assert.assertTrue(buildXmlDiffMessage(diff), diff.similar());
}
示例12: assertSimilarXml
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
public static void assertSimilarXml(String expectedXml, String xml) {
XMLUnit.setIgnoreWhitespace(true);
final Diff diff;
try {
diff = XMLUnit.compareXML(xml, expectedXml);
}
catch (SAXException | IOException ex) {
throw new IllegalArgumentException("Could not run XML comparison", ex);
}
final String message = "Diff: " + diff + CharUtils.LF + "XML: " + xml;
assertTrue(message, diff.similar());
}
示例13: testDocRoot
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
/**
* tests docroot
*
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
*/
@Test
public void testDocRoot() throws ParserConfigurationException, IOException, SAXException {
RuleProcessor ruleProcessor = new RuleProcessor();
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document fdbDocument = documentBuilder.parse(new ByteArrayInputStream("<test source=\"fdb\"><stringElement>test</stringElement></test>".getBytes(StandardCharsets.UTF_8)));
Map<String, Document> sourceDocuments = new HashMap<>();
sourceDocuments.put("fdb", fdbDocument);
Document trusted = documentBuilder.newDocument();
Rule rule = new Rule();
Field field = new Field();
field.setCoalesce(false);
field.setStop(false);
rule.setField(field);
rule.setContext("test");
rule.setWeighting(buildFdbFirstWeighting());
ruleProcessor.processRule(rule, trusted, sourceDocuments);
Document expected = documentBuilder.parse(new ByteArrayInputStream("<test source=\"fdb\"><stringElement>test</stringElement></test>".getBytes(StandardCharsets.UTF_8)));
Diff diff = XMLUnit.compareXML(expected, trusted);
Assert.assertTrue(buildXmlDiffMessage(diff), diff.similar());
}
示例14: testDocRootHasNoWeightingSources
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
/**
* tests that no trusted doc will be generated when there are no weights on the docroot rule
* test created to verify HAPI-388
*
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
*/
@Test
public void testDocRootHasNoWeightingSources() throws ParserConfigurationException, IOException, SAXException {
RuleProcessor ruleProcessor = new RuleProcessor();
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document fdbDocument = documentBuilder.parse(new ByteArrayInputStream("<test source=\"fdb\"><stringElement>test</stringElement></test>".getBytes(StandardCharsets.UTF_8)));
Map<String, Document> sourceDocuments = new HashMap<>();
sourceDocuments.put("fdb", fdbDocument);
Document trusted = documentBuilder.newDocument();
Rule rule = new Rule();
Field field = new Field();
field.setCoalesce(false);
field.setStop(false);
rule.setField(field);
rule.setContext("test");
rule.setWeighting(new Weighting());
ruleProcessor.processRule(rule, trusted, sourceDocuments);
Document expected = documentBuilder.newDocument();
Diff diff = XMLUnit.compareXML(expected, trusted);
Assert.assertTrue(buildXmlDiffMessage(diff), diff.similar());
}
示例15: testProcessRuleSimpleFieldWithChildrenAndNoStop
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
/**
* tests that a rule with a context of an element (not root element) will merge in that element
* with 1 of each child element from all sources (in order of trust weight
*
* @throws Exception
*/
@Test
public void testProcessRuleSimpleFieldWithChildrenAndNoStop() throws Exception {
RuleProcessor ruleProcessor = new RuleProcessor();
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document fdbDocument = documentBuilder.parse(new ByteArrayInputStream("<test source=\"fdb\"><stringElement><childElement>test</childElement><childElement2>test</childElement2></stringElement></test>".getBytes(StandardCharsets.UTF_8)));
Document zeusDocument = documentBuilder.parse(new ByteArrayInputStream("<test source=\"zeus\"><stringElement><childElement>zeus</childElement></stringElement></test>".getBytes(StandardCharsets.UTF_8)));
Map<String, Document> sourceDocuments = new HashMap<>();
sourceDocuments.put("fdb", fdbDocument);
sourceDocuments.put("zeus", zeusDocument);
// simulate that the docroot rule has run with a trusted source of fdb
Document trusted = documentBuilder.parse(new ByteArrayInputStream("<test source=\"fdb\"><stringElement></stringElement></test>".getBytes(StandardCharsets.UTF_8)));
Rule rule = new Rule();
Field field = new Field();
field.setCoalesce(false);
field.setStop(false);
rule.setField(field);
rule.setContext("stringElement");
rule.setWeighting(buildZeusFirstWeighting());
ruleProcessor.processRule(rule, trusted, sourceDocuments);
// assertions
Document expected = documentBuilder.parse(new ByteArrayInputStream("<test source=\"fdb\"><stringElement><childElement>zeus</childElement><childElement2>test</childElement2></stringElement></test>".getBytes(StandardCharsets.UTF_8)));
Diff diff = XMLUnit.compareXML(expected, trusted);
Assert.assertTrue(buildXmlDiffMessage(diff), diff.similar());
}