Example usage for org.apache.solr.util BaseTestHarness validateXPath

List of usage examples for org.apache.solr.util BaseTestHarness validateXPath

Introduction

In this page you can find the example usage for org.apache.solr.util BaseTestHarness validateXPath.

Prototype

public static String validateXPath(String xml, String... tests) throws XPathExpressionException, SAXException 

Source Link

Document

A helper method which validates a String against an array of XPath test strings.

Usage

From source file:org.alfresco.solr.AbstractAlfrescoSolrTests.java

License:Open Source License

/**
 * Validates a query matches some XPath test expressions and closes the query
 * @param message/*from  www  .  ja va2 s  . c o  m*/
 * @param req
 * @param tests
 */
public static void assertQ(String message, SolrQueryRequest req, String... tests) {
    try {
        String response = query(req);
        if (req.getParams().getBool("facet", false)) {
            // add a test to ensure that faceting did not throw an exception
            // internally, where it would be added to facet_counts/exception
            String[] allTests = new String[tests.length + 1];
            System.arraycopy(tests, 0, allTests, 1, tests.length);
            allTests[0] = "*[count(//lst[@name='facet_counts']/*[@name='exception'])=0]";
            tests = allTests;
        }
        String results = BaseTestHarness.validateXPath(response, tests);

        if (null != results) {
            String msg = "REQUEST FAILED: xpath=" + results + "\n\txml response was: " + response
                    + "\n\trequest was:" + req.getParamString();
            LOG.error(msg);
            throw new RuntimeException(msg);
        }
    } catch (XPathExpressionException e1) {
        throw new RuntimeException("XPath is invalid", e1);
    } catch (Exception e2) {
        throw new RuntimeException("Exception during query", e2);
    }
}