本文整理汇总了Java中org.custommonkey.xmlunit.XpathEngine.getMatchingNodes方法的典型用法代码示例。如果您正苦于以下问题:Java XpathEngine.getMatchingNodes方法的具体用法?Java XpathEngine.getMatchingNodes怎么用?Java XpathEngine.getMatchingNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.custommonkey.xmlunit.XpathEngine
的用法示例。
在下文中一共展示了XpathEngine.getMatchingNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldCreeateCategoryWithDomainAsHtmlAtttribute
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void shouldCreeateCategoryWithDomainAsHtmlAtttribute() throws Exception {
final String categoryName = CATEGORY_TEXT;
final String categoryDomain = CATEGORY_DOMAIN;
rss.getChannel().setCategory(Collections.singletonList(new Category()
.setTextValue(categoryName)
.setDomain(categoryDomain)));
final Document document = XmlUtils.getDocument(rss);
final XpathEngine engine = XmlUtils.getXpathEngine();
NodeList matchingNodes = engine.getMatchingNodes(String.format("/rss/channel/category", categoryName), document);
assertEquals("Could not category element", 1, matchingNodes.getLength());
assertEquals("Category domain had unexpected or absent value", categoryDomain, matchingNodes.item(0).getAttributes().getNamedItem("domain").getTextContent());
}
示例2: shouldNextSubcategoriesAsElementsUnderParentCategory
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void shouldNextSubcategoriesAsElementsUnderParentCategory() throws Exception {
final ItunesCategory itunesCategory = new ItunesCategory();
itunesCategory.setText(ItunesCategoryNames.Business.value());
final ItunesCategory subItunesCategory = new ItunesCategory();
subItunesCategory.setText(ItunesCategoryNames.Business.careers);
itunesCategory.getSubcategories().add(subItunesCategory);
rss.getChannel().setItunesCategory(itunesCategory);
final Document document = XmlUtils.getDocument(rss);
final XpathEngine engine = XmlUtils.getXpathEngine();
final String subcategoryXpath = String.format("/rss/channel/itunes:category[@text='%s']/itunes:category[@text='%s']", ItunesCategoryNames.Business.value(), ItunesCategoryNames.Business.careers);
NodeList matchingNodes = engine.getMatchingNodes(subcategoryXpath, document);
assertEquals("Could not find itunes subcategory attribute", 1, matchingNodes.getLength());
}
示例3: removeIgnoredBranches
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的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;
}
示例4: testLoanRequestAccepted
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testLoanRequestAccepted() throws Exception {
HTTPMixIn httpMixIn = new HTTPMixIn();
httpMixIn.initialize();
try {
String port = System.getProperty("org.switchyard.component.soap.standalone.port", "8181/cxf");
String response = httpMixIn.postString("http://localhost:" + port + "/loanService/loanService", SOAP_REQUEST_1);
org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
m.put("tns", "http://example.com/loan-approval/loanService/");
NamespaceContext ctx = new SimpleNamespaceContext(m);
XpathEngine engine = XMLUnit.newXpathEngine();
engine.setNamespaceContext(ctx);
NodeList l = engine.getMatchingNodes("//tns:accept", d);
assertEquals(1, l.getLength());
assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
if (!l.item(0).getTextContent().equals("yes")) {
fail("Expecting 'yes'");
}
} finally {
httpMixIn.uninitialize();
}
}
示例5: testLoanRequestUnableToHandle
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testLoanRequestUnableToHandle() throws Exception {
HTTPMixIn httpMixIn = new HTTPMixIn();
httpMixIn.initialize();
try {
String response = httpMixIn.postString("http://localhost:" + getSoapClientPort() + "/loanService/loanService", SOAP_REQUEST_2);
org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
//m.put("tns", "http://example.com/loan-approval/loanService/");
NamespaceContext ctx = new SimpleNamespaceContext(m);
XpathEngine engine = XMLUnit.newXpathEngine();
engine.setNamespaceContext(ctx);
NodeList l = engine.getMatchingNodes("//faultcode", d);
assertEquals(1, l.getLength());
assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
if (!l.item(0).getTextContent().endsWith(":unableToHandleRequest")) {
fail("Expecting 'unableToHandleRequest' fault code");
}
} finally {
httpMixIn.uninitialize();
}
}
示例6: testDeployment
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Override
@Test
public void testDeployment() throws Exception {
HTTPMixIn httpMixIn = new HTTPMixIn();
httpMixIn.initialize();
try {
String response = httpMixIn.postString("http://localhost:" + getSoapClientPort() + "/SayHelloService/SayHelloService", SOAP_REQUEST);
org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
m.put("tns", "http://www.jboss.org/bpel/examples");
NamespaceContext ctx = new SimpleNamespaceContext(m);
XpathEngine engine = XMLUnit.newXpathEngine();
engine.setNamespaceContext(ctx);
NodeList l = engine.getMatchingNodes("//tns:result", d);
assertEquals(1, l.getLength());
assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
if (!l.item(0).getTextContent().equals("Hello Fred")) {
fail("Expecting 'Hello Fred'");
}
} finally {
httpMixIn.uninitialize();
}
}
示例7: testLoanRequestAccepted
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testLoanRequestAccepted() throws Exception {
HTTPMixIn httpMixIn = new HTTPMixIn();
httpMixIn.initialize();
try {
String response = httpMixIn.postString("http://localhost:8080/loanService/loanService", SOAP_REQUEST_1);
org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
m.put("tns", "http://example.com/loan-approval/loanService/");
NamespaceContext ctx = new SimpleNamespaceContext(m);
XpathEngine engine = XMLUnit.newXpathEngine();
engine.setNamespaceContext(ctx);
NodeList l = engine.getMatchingNodes("//tns:accept", d);
assertEquals(1, l.getLength());
assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
if (!l.item(0).getTextContent().equals("yes")) {
fail("Expecting 'yes'");
}
} finally {
httpMixIn.uninitialize();
}
}
示例8: testLoanRequestUnableToHandle
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testLoanRequestUnableToHandle() throws Exception {
HTTPMixIn httpMixIn = new HTTPMixIn();
httpMixIn.initialize();
try {
String response = httpMixIn.postString("http://localhost:8080/loanService/loanService", SOAP_REQUEST_2);
org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
//m.put("tns", "http://example.com/loan-approval/loanService/");
NamespaceContext ctx = new SimpleNamespaceContext(m);
XpathEngine engine = XMLUnit.newXpathEngine();
engine.setNamespaceContext(ctx);
NodeList l = engine.getMatchingNodes("//faultcode", d);
assertEquals(1, l.getLength());
assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
if (!l.item(0).getTextContent().endsWith(":unableToHandleRequest")) {
fail("Expecting 'unableToHandleRequest' fault code");
}
} finally {
httpMixIn.uninitialize();
}
}
示例9: testSayHello
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testSayHello() throws Exception {
HTTPMixIn httpMixIn = new HTTPMixIn();
httpMixIn.initialize();
try {
String response = httpMixIn.postString("http://localhost:8080/SayHelloService/SayHelloService", SOAP_REQUEST);
org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
m.put("tns", "http://www.jboss.org/bpel/examples");
NamespaceContext ctx = new SimpleNamespaceContext(m);
XpathEngine engine = XMLUnit.newXpathEngine();
engine.setNamespaceContext(ctx);
NodeList l = engine.getMatchingNodes("//tns:result", d);
assertEquals(1, l.getLength());
assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
if (!l.item(0).getTextContent().equals("Hello Fred")) {
fail("Expecting 'Hello Fred'");
}
} finally {
httpMixIn.uninitialize();
}
}
示例10: shouldRenderItunesImageHrefAsAttribute
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void shouldRenderItunesImageHrefAsAttribute() throws Exception {
final String imageUrl = "http://www.example.com/images/logo.png";
final ItunesImage itunesImage = new ItunesImage().setHref(imageUrl);
rss.getChannel().setItunesImage(itunesImage);
final Document document = XmlUtils.getDocument(rss);
final XpathEngine engine = XmlUtils.getXpathEngine();
final String subcategoryXpath = String.format("/rss/channel/itunes:image[@href='%s']", imageUrl);
NodeList matchingNodes = engine.getMatchingNodes(subcategoryXpath, document);
assertEquals("Could not find itunes image href attribute", 1, matchingNodes.getLength());
}
示例11: shouldCreateCategoryWithTextValue
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void shouldCreateCategoryWithTextValue() throws Exception {
final String categoryName = CATEGORY_TEXT;
rss.getChannel().setCategory(Collections.singletonList(new Category().setTextValue(categoryName)));
final Document document = XmlUtils.getDocument(rss);
final XpathEngine engine = XmlUtils.getXpathEngine();
NodeList matchingNodes = engine.getMatchingNodes(String.format("/rss/channel/category", categoryName), document);
assertEquals("Could not category element", 1, matchingNodes.getLength());
assertEquals("Category element had unexpected text", categoryName, matchingNodes.item(0).getTextContent());
}
示例12: shouldIncludeCategoryTextAsXmlAttribute
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void shouldIncludeCategoryTextAsXmlAttribute() throws Exception {
final String categoryName = ItunesCategoryNames.Business.value();
final ItunesCategory itunesCategory = new ItunesCategory();
itunesCategory.setText(categoryName);
rss.getChannel().setItunesCategory(itunesCategory);
final Document document = XmlUtils.getDocument(rss);
final XpathEngine engine = XmlUtils.getXpathEngine();
NodeList matchingNodes = engine.getMatchingNodes(String.format("/rss/channel/itunes:category[@text='%s']", categoryName), document);
assertEquals("Could not find itunes itunesCategory attribute", 1, matchingNodes.getLength());
}
示例13: shouldRenderBuildDateAsRfc822Format
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void shouldRenderBuildDateAsRfc822Format() throws Exception {
rss.getChannel().setLastBuildDate(getDate());
final Document document = XmlUtils.getDocument(rss);
final XpathEngine engine = XmlUtils.getXpathEngine();
NodeList matchingNodes = engine.getMatchingNodes("/rss/channel/lastBuildDate", document);
String test = matchingNodes.item(0).getTextContent();
//assertTrue(test.startsWith("Sat, 01 Jan 2000"));
}
示例14: assertXpathEvaluatesTo
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
/**
* 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<String, String>();
namespaces.put("tns", "http://samples.springframework.org/flight");
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
NamespaceContext ctx = new SimpleNamespaceContext(namespaces);
XpathEngine engine = XMLUnit.newXpathEngine();
engine.setNamespaceContext(ctx);
Document doc = XMLUnit.buildControlDocument(xmlDoc);
NodeList node = engine.getMatchingNodes(xpath, doc);
assertEquals(msg, expected, node.item(0).getNodeValue());
}
示例15: assertXpathEvaluatesTo
import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
/**
* Asserts 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<String, String>();
namespaces.put("tns", "http://samples.springframework.org/flight");
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
NamespaceContext ctx = new SimpleNamespaceContext(namespaces);
XpathEngine engine = XMLUnit.newXpathEngine();
engine.setNamespaceContext(ctx);
Document doc = XMLUnit.buildControlDocument(xmlDoc);
NodeList node = engine.getMatchingNodes(xpath, doc);
assertEquals(msg, expected, node.item(0).getNodeValue());
}