From 9ba13b6e71533bb98f557a73d8083d173d2d28c5 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Thu, 14 Oct 2010 23:01:50 +0000 Subject: [PATCH] tests: fix resource leaks and simplify git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1022755 13f79535-47bb-0310-9956-ffa450edef68 --- .../component/SpellCheckComponentTest.java | 57 +++---------------- 1 file changed, 7 insertions(+), 50 deletions(-) diff --git a/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java b/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java index 04ed5b42548..596d2e9b20f 100644 --- a/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java +++ b/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java @@ -66,57 +66,14 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 { @Test public void testExtendedResultsCount() throws Exception { - SolrCore core = h.getCore(); - SearchComponent speller = core.getSearchComponent("spellcheck"); - assertTrue("speller is null and it shouldn't be", speller != null); + assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellCheckComponent.SPELLCHECK_BUILD, "true", "q","bluo", SpellCheckComponent.SPELLCHECK_COUNT,"5", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS,"false") + ,"/spellcheck/suggestions/[0]=='bluo'" + ,"/spellcheck/suggestions/[1]/numFound==5" + ); - ModifiableSolrParams params = new ModifiableSolrParams(); - params.add(CommonParams.QT, "spellCheckCompRH"); - params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true"); - params.add(CommonParams.Q, "bluo"); - params.add(SpellCheckComponent.COMPONENT_NAME, "true"); - params.add(SpellCheckComponent.SPELLCHECK_COUNT, String.valueOf(5)); - params.add(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, String.valueOf(false)); - SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH"); - SolrQueryResponse rsp; - rsp = new SolrQueryResponse(); - SolrQueryRequest req = new LocalSolrQueryRequest(core, params); - handler.handleRequest(req, rsp); - NamedList values = rsp.getValues(); - String cmdExec = (String) values.get("command"); - assertEquals("build",cmdExec); - NamedList spellCheck = (NamedList) values.get("spellcheck"); - NamedList suggestions = (NamedList) spellCheck.get("suggestions"); - NamedList blue = (NamedList) suggestions.get("bluo"); - assertEquals(5,blue.get("numFound")); - Collection theSuggestion = (Collection) blue.get("suggestion"); - 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); - params.add(SpellCheckComponent.SPELLCHECK_COUNT, "3"); - params.add(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, String.valueOf(true)); - params.add(SpellCheckComponent.SPELLCHECK_BUILD, "false"); - rsp = new SolrQueryResponse(); - handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp); - values = rsp.getValues(); - - spellCheck = (NamedList) values.get("spellcheck"); - suggestions = (NamedList) spellCheck.get("suggestions"); - blue = (NamedList) suggestions.get("bluo"); - assertEquals(3, blue.get("numFound")); - - List theSuggestions = (List)blue.get("suggestion"); - assertEquals(3, theSuggestions.size()); - - for (SimpleOrderedMap sug : theSuggestions) { - assertNotNull(sug.get("word")); - assertNotNull(sug.get("freq")); - } + assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","bluo", SpellCheckComponent.SPELLCHECK_COUNT,"3", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS,"true") + ,"/spellcheck/suggestions/[1]/suggestion==[{'word':'blue','freq':1}, {'word':'blud','freq':1}, {'word':'boue','freq':1}]" + ); } @Test