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


Java XMLUnit類代碼示例

本文整理匯總了Java中org.custommonkey.xmlunit.XMLUnit的典型用法代碼示例。如果您正苦於以下問題:Java XMLUnit類的具體用法?Java XMLUnit怎麽用?Java XMLUnit使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XMLUnit類屬於org.custommonkey.xmlunit包,在下文中一共展示了XMLUnit類的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: ignoresTrailingWhitespace

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
@Test
public void ignoresTrailingWhitespace() throws Exception {
    StringWriter writer = new StringWriter();
    Properties log4jProperties = new Properties();
    log4jProperties.load(getClass().getClassLoader().getResourceAsStream("log4j.issue5.properties"));

    converter.toXml(log4jProperties, writer);

    String expected = readFromStream("log4j.issue5.expected.xml");
    String actual = writer.toString();

    System.out.println(expected);
    System.out.println("=============================");
    System.out.println(actual);

    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setControlEntityResolver(new Log4JEntityResolver());
    XMLUnit.setTestEntityResolver(new Log4JEntityResolver());

    Validator validator = new Validator(actual);
    validator.assertIsValid();

    XMLAssert.assertXMLEqual(expected, actual);
}
 
開發者ID:jroyals,項目名稱:log4j-properties-converter,代碼行數:25,代碼來源:ConvertFromPropertiesToXmlTest.java

示例3: compare

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
@Override
protected boolean compare(File baselineFile, File comparisonFile) {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        factory.setNamespaceAware(true);
        factory.setCoalescing(true);
        factory.setIgnoringElementContentWhitespace(true);
        factory.setIgnoringComments(true);

        DocumentBuilder builder = factory.newDocumentBuilder();
        Document baselineXml = builder.parse(baselineFile);
        Document comparisonXml = builder.parse(comparisonFile);

        baselineXml.normalizeDocument();
        comparisonXml.normalizeDocument();

        XMLUnit.setIgnoreAttributeOrder(true);
        XMLUnit.setIgnoreComments(true);
        XMLUnit.setIgnoreWhitespace(true);

        return XMLUnit.compareXML(baselineXml, comparisonXml).similar();
    } catch (SAXException | IOException | ParserConfigurationException e) {
        throw new TransformationUtilityException("An exception happened when comparing the two XML files", e);
    }
}
 
開發者ID:paypal,項目名稱:butterfly,代碼行數:27,代碼來源:CompareXMLFiles.java

示例4: assertEqualsXml

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
/**
 * Assert that the specified XML file has not semantically changed,
 * although it might be identical to the original one due to format
 * changes, comments not being present, etc
 *
 * @param relativeFilePath relative path to file to be evaluated
 * @throws ParserConfigurationException
 * @throws IOException
 * @throws SAXException
 */
protected void assertEqualsXml(String relativeFilePath) throws ParserConfigurationException, IOException, SAXException {
    File originalFile = new File(appFolder, relativeFilePath);
    File transformedFile = new File(transformedAppFolder, relativeFilePath);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setNamespaceAware(true);
    factory.setCoalescing(true);
    factory.setIgnoringElementContentWhitespace(true);
    factory.setIgnoringComments(true);

    DocumentBuilder builder = factory.newDocumentBuilder();
    Document originalXml = builder.parse(originalFile);
    Document transformedXml = builder.parse(transformedFile);

    originalXml.normalizeDocument();
    transformedXml.normalizeDocument();

    XMLUnit.setIgnoreAttributeOrder(true);
    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreWhitespace(true);

    Assert.assertTrue(XMLUnit.compareXML(originalXml, transformedXml).similar());
}
 
開發者ID:paypal,項目名稱:butterfly,代碼行數:35,代碼來源:TransformationUtilityTestHelper.java

示例5: setUp

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();
    postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis();


    Map<String,String> m = new HashMap<String,String>();
    m.put("sv", "http://www.jcp.org/jcr/sv/1.0");

    NamespaceContext ctx = new SimpleNamespaceContext(m);
    XMLUnit.setXpathNamespaceContext(ctx);


    final NameValuePairList props = new NameValuePairList();
    props.add("a", "");
    props.add("jcr:mixinTypes", "mix:referenceable");

    firstCreatedNodeUrl = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props, null, false);
    firstUuid = getProperty(firstCreatedNodeUrl, "jcr:uuid");
    firstPath = getPath(firstCreatedNodeUrl);

    secondCreatedNodeUrl = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props, null, false);
    secondUuid = getProperty(secondCreatedNodeUrl, "jcr:uuid");
    secondPath = getPath(secondCreatedNodeUrl);
}
 
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:26,代碼來源:ReferenceTypeHintTest.java

示例6: 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

示例7: 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

示例8: 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

示例9: writeDeliverResponse

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
@Test
public void writeDeliverResponse() throws Exception {
    DeliverResponse deliverResponse = new DeliverResponse();
    deliverResponse.setErrorCode(5);
    deliverResponse.setErrorMessage("Success");

    StringWriter sw = new StringWriter();
    SxmpWriter.write(sw, deliverResponse);

    logger.debug(sw.toString());

    StringBuilder expectedXML = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"deliver\">\n")
        .append(" <deliverResponse>\n")
        .append("   <error code=\"5\" message=\"Success\"/>\n")
        .append(" </deliverResponse>\n")
        .append("</operation>\n")
        .append("");

    // compare to actual correct submit response
    XMLUnit.setIgnoreWhitespace(true);
    Diff myDiff = new Diff(expectedXML.toString(), sw.toString());
    DetailedDiff myDetailedDiff = new DetailedDiff(myDiff);
    Assert.assertTrue("XML are similar " + myDetailedDiff, myDetailedDiff.similar());
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:27,代碼來源:SxmpWriterTest.java

示例10: writeDeliveryReportResponse

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
@Test
public void writeDeliveryReportResponse() throws Exception {
    DeliveryReportResponse deliveryResponse = new DeliveryReportResponse();
    deliveryResponse.setErrorCode(5);
    deliveryResponse.setErrorMessage("Success");

    StringWriter sw = new StringWriter();
    SxmpWriter.write(sw, deliveryResponse);

    logger.debug(sw.toString());

    StringBuilder expectedXML = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"deliveryReport\">\n")
        .append(" <deliveryReportResponse>\n")
        .append("   <error code=\"5\" message=\"Success\"/>\n")
        .append(" </deliveryReportResponse>\n")
        .append("</operation>\n")
        .append("");

    // compare to actual correct submit response
    XMLUnit.setIgnoreWhitespace(true);
    Diff myDiff = new Diff(expectedXML.toString(), sw.toString());
    DetailedDiff myDetailedDiff = new DetailedDiff(myDiff);
    Assert.assertTrue("XML are similar " + myDetailedDiff, myDetailedDiff.similar());
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:27,代碼來源:SxmpWriterTest.java

示例11: testMarshalAsByteArrayOutputStream

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
@Test
public void testMarshalAsByteArrayOutputStream()
        throws SimpleMarshallerException, SAXException, IOException {
    // Arrange
    XMLUnit.setIgnoreAttributeOrder(true);
    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreWhitespace(true);
    final String expectedOutput = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ruleExecutionContainer><executionResponseList/></ruleExecutionContainer>";
    final RuleExecutionContainer r = createRuleExecutionContainer();

    // Act
    final ByteArrayOutputStream output = marshaller
            .marshalAsByteArrayOutputStream(r);

    assertNotNull(output);
    assertXMLEqual(expectedOutput, output.toString());
}
 
開發者ID:bhits,項目名稱:common-libraries,代碼行數:18,代碼來源:SimpleMarshallerImplTest.java

示例12: testRemovingProcessor

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
@Test
public void testRemovingProcessor()
    throws Exception
{
    Model m = full();
    ModelVisitor mock = EasyMock.createNiceMock( ModelVisitor.class );
    EasyMock.replay( mock );
    mp.processModel( m, mock );
    XMLUnit.setIgnoreWhitespace( true );
    assertXMLEqual( "<?xml version=\"1.0\"?>" + //
        "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0" + //
        " http://maven.apache.org/xsd/maven-4.0.0.xsd\"" + //
        " xmlns=\"http://maven.apache.org/POM/4.0.0\"" + //
        " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + //
        "<modelVersion/>" + //
        "<groupId/>" + //
        "<artifactId/>" + //
        "<version/>" + //
        "<packaging/>" + //
        "<name/>" + //
        "<description/>" + //
        "<url/>" + //
        "<inceptionYear/>" + //
        "</project>", m2s( m ) );
}
 
開發者ID:fedora-java,項目名稱:xmvn,代碼行數:26,代碼來源:ModelProcessorTest.java

示例13: 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

示例14: testSetEndpoints

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
public void testSetEndpoints() throws Exception {
    // Create a new Camel context and add an endpoint
    CamelContextFactoryBean camelContext = new CamelContextFactoryBean();
    List<CamelEndpointFactoryBean> endpoints = new LinkedList<CamelEndpointFactoryBean>();
    CamelEndpointFactoryBean endpoint = new CamelEndpointFactoryBean();
    endpoint.setId("endpoint1");
    endpoint.setUri("mock:end");
    endpoints.add(endpoint);
    camelContext.setEndpoints(endpoints);

    // Compare the new context with our reference context
    Reader expectedContext = null;
    try {
        expectedContext = new InputStreamReader(getClass().getResourceAsStream("/org/apache/camel/spring/context-with-endpoint.xml"));
        String createdContext = contextAsString(camelContext);
        XMLUnit.setIgnoreWhitespace(true);
        XMLAssert.assertXMLEqual(expectedContext, new StringReader(createdContext));
    } finally {
        IOHelper.close(expectedContext);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:CamelContextFactoryBeanTest.java

示例15: removeIgnoredBranches

import org.custommonkey.xmlunit.XMLUnit; //導入依賴的package包/類
public Document removeIgnoredBranches(Document document) {
	for (String branch : getIgnoredBranches()) {
        XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine();
        
        NodeList nodeList;
		try {
			nodeList = simpleXpathEngine.getMatchingNodes(branch, document);
			for (int i = 0; i < nodeList.getLength(); i++) {
				Node parentNode = nodeList.item(i).getParentNode();
				parentNode.removeChild(nodeList.item(i));
			}
		} catch (XpathException e) {
			e.printStackTrace(); // FIXME : remove printStackTrace()
		}
	}
	return document;
}
 
開發者ID:fastconnect,項目名稱:tibco-fcunit,代碼行數:18,代碼來源:FCDiff.java


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