public void testJaxenIntegrationTest() throws ParsingException, IOException {
Builder builder = new Builder();
Document testDoc = builder.build(
"http://cvs.jaxen.codehaus.org/viewrep/~raw,r=HEAD/jaxen/jaxen/xml/test/tests.xml");
Elements documents = testDoc.getRootElement().getChildElements("document");
for (int i = 0; i < documents.size(); i++) {
Element documentElement = documents.get(i);
String url = documentElement.getAttributeValue("url");
Document source = builder.build(
"http://cvs.jaxen.codehaus.org/viewrep/~raw,r=HEAD/jaxen/jaxen/"
+ url);
Elements contextElements = documentElement.getChildElements("context");
for (int j = 0; j < contextElements.size(); j++) {
Element contextElement = contextElements.get(j);
// skip tests that use variables
// because XOM doesn't support variables in
// XPath expressions
if (queryUsesVars(contextElement)) continue;
String xpath = contextElement.getAttributeValue("select");
XPathContext namespaces = getXPathContext(contextElement);
Node context = source.query(xpath).get(0);
// process counts
Elements tests = contextElement.getChildElements("test");
for (int k = 0; k < tests.size(); k++) {
Element test = tests.get(k);
String select = test.getAttributeValue("select");
Attribute countAttribute = test.getAttribute("count");
int count = -1;
if (countAttribute != null) {
count = Integer.parseInt(countAttribute.getValue());
}
boolean exceptional = false;
String exception = test.getAttributeValue("exception");
if ("true".equals(exception)) {
exceptional = true;
}
if (exceptional) {
try {
context.query(select, namespaces);
fail("Evaluated " + select);
}
catch (XPathException success) {
assertNotNull(success.getMessage());
}
}
else {
try {
Nodes results = context.query(select, namespaces);
if (count != -1) {
assertEquals(select, count, results.size());
}
Elements valueOfs = test.getChildElements("valueOf");
for (int v = 0; v < valueOfs.size(); v++) {
Element vo = valueOfs.get(v);
checkValueOf(results.get(0), vo, namespaces);
}
}
catch (XPathException ex) {
if (ex.getMessage().equalsIgnoreCase("XPath error: No such function document")
|| ex.getMessage().equalsIgnoreCase("XPath error: No such function evaluate")) {
continue;
}
throw ex;
}
}
}
// process valueOfs
Elements valueOfs = contextElement.getChildElements("valueOf");
for (int k = 0; k < valueOfs.size(); k++) {
checkValueOf(context, valueOfs.get(k), namespaces);
}
}
}
}