/** Validates an update XML String failed */ public void assertFailedU(String update) { assertFailedU(null, update); }
/** Validates a query matches some XPath test expressions and closes the query */ public void assertQ(SolrQueryRequest req, String... tests) { assertQ(null, req, tests); }
public void setUp() throws Exception { log.info("####SETUP_START " + getName()); dataDir = new File(System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + getClass().getName() + "-" + System.currentTimeMillis()); dataDir.mkdirs(); String configFile = getSolrConfigFile(); if (configFile != null) { solrConfig = h.createConfig(getSolrConfigFile()); h = new TestHarness( dataDir.getAbsolutePath(), solrConfig, getSchemaFile()); lrf = h.getRequestFactory ("standard",0,20,"version","2.2"); } log.info("####SETUP_END " + getName()); }
/** Makes sure a query throws a SolrException with the listed response code */ public void assertQEx(String message, SolrQueryRequest req, int code ) { try { h.query(req); fail( message ); } catch (SolrException sex) { assertEquals( code, sex.code() ); } catch (Exception e2) { throw new RuntimeException("Exception during query", e2); } }
/** * Shuts down the test harness, and makes the best attempt possible * to delete dataDir, unless the system property "solr.test.leavedatadir" * is set. */ public void tearDown() throws Exception { log.info("####TEARDOWN_START " + getName()); if (h != null) { h.close(); } String skip = System.getProperty("solr.test.leavedatadir"); if (null != skip && 0 != skip.trim().length()) { System.err.println("NOTE: per solr.test.leavedatadir, dataDir will not be removed: " + dataDir.getAbsolutePath()); } else { if (!recurseDelete(dataDir)) { System.err.println("!!!! WARNING: best effort to remove " + dataDir.getAbsolutePath() + " FAILED !!!!!"); } } }
/** Subclasses that override setUp can optionally call this method * to log the fact that their setUp process has ended. */ public void postSetUp() { log.info("####POSTSETUP " + getName()); }
/** Validates an update XML String is successful */ public void assertU(String message, String update) { checkUpdateU(message, update, true); }
/** Checks the success or failure of an update message */ private void checkUpdateU(String message, String update, boolean shouldSucceed) { try { String m = (null == message) ? "" : message + " "; if (shouldSucceed) { String res = h.validateUpdate(update); if (res != null) fail(m + "update was not successful: " + res); } else { String res = h.validateErrorUpdate(update); if (res != null) fail(m + "update succeeded, but should have failed: " + res); } } catch (SAXException e) { throw new RuntimeException("Invalid XML", e); } }
/** Validates an update XML String is successful */ public void assertU(String update) { assertU(null, update); }
/** * Generates a simple <add><doc>... XML String with no options */ public String adoc(SolrInputDocument sdoc) { List<String> fields = new ArrayList<String>(); for (SolrInputField sf : sdoc) { for (Object o : sf.getValues()) { fields.add(sf.getName()); fields.add(o.toString()); } } return adoc(fields.toArray(new String[fields.size()])); }
/** Subclasses that override tearDown can optionally call this method * to log the fact that the tearDown process has started. This is necessary * since subclasses will want to call super.tearDown() at the *end* of their * tearDown method. */ public void preTearDown() { log.info("####PRETEARDOWN " + getName()); }
/** Validates an update XML String failed */ public void assertFailedU(String message, String update) { checkUpdateU(message, update, false); }
/** Validates a query matches some XPath test expressions and closes the query */ public void assertQ(String message, SolrQueryRequest req, String... tests) { try { String m = (null == message) ? "" : message + " "; String response = h.query(req); String results = h.validateXPath(response, tests); if (null != results) { fail(m + "query failed XPath: " + results + "\n xml response was: " + response + "\n request was: " + req.getParamString()); } } catch (XPathExpressionException e1) { throw new RuntimeException("XPath is invalid", e1); } catch (Exception e2) { throw new RuntimeException("Exception during query", e2); } }