本文整理汇总了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());
}
示例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);
}
示例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);
}
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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 ) );
}
示例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());
}
示例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);
}
}
示例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;
}