當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLUnit.compareXML方法代碼示例

本文整理匯總了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());

}
 
開發者ID:Accuity,項目名稱:xml-document-merge,代碼行數:23,代碼來源:DocumentNodeMergerTest.java

示例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());
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:19,代碼來源:XmlUtilTest.java

示例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());
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:17,代碼來源:SerializationUtilsTest.java

示例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());            
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:TestHelper.java

示例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);
}
 
開發者ID:mojohaus,項目名稱:jaxb2-maven-plugin,代碼行數:25,代碼來源:AbstractSourceCodeAwareNodeProcessingTest.java

示例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 );
}
 
開發者ID:immutables,項目名稱:maven-shade-plugin,代碼行數:18,代碼來源:ComponentsXmlResourceTransformerTest.java

示例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());
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:18,代碼來源:UnwrappedMessageTest.java

示例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());
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:25,代碼來源:ValidateModelTests.java

示例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());
}
 
開發者ID:hashmapinc,項目名稱:WitsmlObjectsLibrary,代碼行數:11,代碼來源:TestUtilities.java

示例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());
}
 
開發者ID:Accuity,項目名稱:xml-document-merge,代碼行數:43,代碼來源:RuleProcessorTest.java

示例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());
}
 
開發者ID:checkstyle,項目名稱:sonar-checkstyle,代碼行數:13,代碼來源:CheckstyleTestUtils.java

示例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());
}
 
開發者ID:Accuity,項目名稱:xml-document-merge,代碼行數:36,代碼來源:RuleProcessorTest.java

示例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());
}
 
開發者ID:Accuity,項目名稱:xml-document-merge,代碼行數:37,代碼來源:RuleProcessorTest.java

示例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());
}
 
開發者ID:Accuity,項目名稱:xml-document-merge,代碼行數:41,代碼來源:RuleProcessorTest.java


注:本文中的org.custommonkey.xmlunit.XMLUnit.compareXML方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。