use of org.xmlunit.xpath.JAXPXPathEngine in project atlasmap by atlasmap.
the class AtlasTestUtil method validateXmlOrderElement.
public static void validateXmlOrderElement(Object orderObject, int expectedOrderId) {
assertNotNull(orderObject);
HashMap<String, String> ns = new HashMap<>();
ns.put("ns", "http://atlasmap.io/xml/test/v2");
assertThat(orderObject).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:orderId").isEqualTo(expectedOrderId);
Source source = Input.from(orderObject).build();
JAXPXPathEngine engine = new JAXPXPathEngine();
engine.setNamespaceContext(ns);
Iterable<Node> addresses = engine.selectNodes("/ns:XmlOE/ns:Address", source);
validateXmlAddressElement(addresses.iterator().next());
Iterable<Node> contacts = engine.selectNodes("/ns:XmlOE/ns:Contact", source);
validateXmlContactElement(contacts.iterator().next());
}
use of org.xmlunit.xpath.JAXPXPathEngine in project spring-framework by spring-projects.
the class CastorMarshallerTests method assertXpathEvaluatesTo.
/**
* Assert the values of xpath expression evaluation is exactly the same as expected value.
* <p>The xpath may contain the xml namespace prefixes, since namespaces from flight example
* are being registered.
* @param msg the error message that will be used in case of test failure
* @param expected the expected value
* @param xpath the xpath to evaluate
* @param xmlDoc the xml to use
* @throws Exception if any error occurs during xpath evaluation
*/
private void assertXpathEvaluatesTo(String msg, String expected, String xpath, String xmlDoc) throws Exception {
Map<String, String> namespaces = new HashMap<>();
namespaces.put("tns", "http://samples.springframework.org/flight");
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
JAXPXPathEngine engine = new JAXPXPathEngine();
engine.setNamespaceContext(namespaces);
Source source = Input.fromString(xmlDoc).build();
Iterable<Node> nodeList = engine.selectNodes(xpath, source);
assertEquals(msg, expected, nodeList.iterator().next().getNodeValue());
}
use of org.xmlunit.xpath.JAXPXPathEngine in project pom-manipulation-ext by release-engineering.
the class XMLManipulatorTest method alterFile.
@Test
public void alterFile() throws Exception {
String replacementGA = "com.rebuild:servlet-api";
String tomcatPath = "//include[starts-with(.,'org.apache.tomcat')]";
File target = tf.newFile();
FileUtils.copyFile(xmlFile, target);
Project project = new Project(null, target, null);
xmlManipulator.internalApplyChanges(project, new XMLState.XMLOperation(target.getName(), tomcatPath, replacementGA));
Diff diff = DiffBuilder.compare(fromFile(xmlFile)).withTest(fromFile(target)).build();
assertTrue(diff.toString(), diff.hasDifferences());
String xpathForHamcrest = "/*/*/*/*/*[starts-with(.,'com.rebuild') and local-name() = 'include']";
Iterable<Node> i = new JAXPXPathEngine().selectNodes(xpathForHamcrest, fromFile(target).build());
int count = 0;
for (Node anI : i) {
count++;
assertTrue(anI.getTextContent().startsWith("com.rebuild:servlet-api"));
}
assertEquals(1, count);
}
Aggregations