mirror of https://github.com/apache/lucene.git
tests: fix resource leaks and simplify
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1022748 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9b8431be6c
commit
77c543b73f
|
@ -43,6 +43,9 @@ import static org.junit.Assert.*;
|
|||
* @since solr 1.3
|
||||
*/
|
||||
public class SpellCheckComponentTest extends SolrTestCaseJ4 {
|
||||
static String rh = "spellCheckCompRH";
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig.xml","schema.xml");
|
||||
|
@ -77,7 +80,8 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 {
|
|||
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
|
||||
SolrQueryResponse rsp;
|
||||
rsp = new SolrQueryResponse();
|
||||
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
|
||||
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
|
||||
handler.handleRequest(req, rsp);
|
||||
NamedList values = rsp.getValues();
|
||||
String cmdExec = (String) values.get("command");
|
||||
assertEquals("build",cmdExec);
|
||||
|
@ -89,6 +93,8 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 {
|
|||
assertEquals(5,theSuggestion.size());
|
||||
//we know there are at least 5, but now only get 3
|
||||
|
||||
req.close();
|
||||
|
||||
params.remove(SpellCheckComponent.SPELLCHECK_COUNT);
|
||||
params.remove(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS);
|
||||
params.remove(SpellCheckComponent.SPELLCHECK_BUILD);
|
||||
|
@ -115,35 +121,10 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 {
|
|||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
SolrCore core = h.getCore();
|
||||
SearchComponent speller = core.getSearchComponent("spellcheck");
|
||||
assertTrue("speller is null and it shouldn't be", speller != null);
|
||||
|
||||
ModifiableSolrParams params = new ModifiableSolrParams();
|
||||
params.add(CommonParams.QT, "spellCheckCompRH");
|
||||
params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
|
||||
params.add(CommonParams.Q, "documemt");
|
||||
params.add(SpellCheckComponent.COMPONENT_NAME, "true");
|
||||
|
||||
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
|
||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
|
||||
NamedList values = rsp.getValues();
|
||||
String cmdExec = (String) values.get("command");
|
||||
assertTrue("command is null and it shouldn't be", cmdExec != null);
|
||||
assertTrue(cmdExec + " is not equal to " + "build",
|
||||
cmdExec.equals("build") == true);
|
||||
NamedList spellCheck = (NamedList) values.get("spellcheck");
|
||||
assertNotNull(spellCheck);
|
||||
NamedList suggestions = (NamedList) spellCheck.get("suggestions");
|
||||
assertNotNull(suggestions);
|
||||
NamedList document = (NamedList) suggestions.get("documemt");
|
||||
assertEquals(1, document.get("numFound"));
|
||||
assertEquals(0, document.get("startOffset"));
|
||||
assertEquals(document.get("endOffset"), "documemt".length());
|
||||
Collection<String> theSuggestion = (Collection<String>) document.get("suggestion");
|
||||
assertEquals(1, theSuggestion.size());
|
||||
assertEquals("document", theSuggestion.iterator().next());
|
||||
assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellCheckComponent.SPELLCHECK_BUILD, "true", "q","documemt")
|
||||
,"/command=='build'"
|
||||
,"/spellcheck=={'suggestions':['documemt',{'numFound':1,'startOffset':0,'endOffset':8,'suggestion':['document']}]}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue