diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-17 14:40:30 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-17 14:40:30 +0200 |
commit | c8cdfb65631a6814f2d85e18171badc9144ed33e (patch) | |
tree | f807a0a4a9fd288c658611e36e5e9bb25e740b65 /container-search/src/test/java/com/yahoo/search/query/rewrite | |
parent | 6b9f956080484c22e894ee0ccd2692c2f442a333 (diff) |
Remove usage of junit.framework
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/query/rewrite')
6 files changed, 97 insertions, 68 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/GenericExpansionRewriterTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/GenericExpansionRewriterTestCase.java index 6399c24277e..63599f60ade 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/GenericExpansionRewriterTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/GenericExpansionRewriterTestCase.java @@ -8,13 +8,15 @@ import com.yahoo.search.searchchain.*; import com.yahoo.search.query.rewrite.*; import com.yahoo.search.query.rewrite.rewriters.*; import com.yahoo.search.query.rewrite.RewritesConfig; +import org.junit.Before; +import org.junit.Test; /** * Test Cases for GenericExpansionRewriter * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { +public class GenericExpansionRewriterTestCase { private QueryRewriteSearcherTestUtils utils; private final String CONFIG_PATH = "file:src/test/java/com/yahoo/search/query/rewrite/test/" + @@ -27,7 +29,8 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { * Load the GenericExpansionRewriterSearcher and prepare the * execution object */ - protected void setUp() { + @Before + public void setUp() { RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(CONFIG_PATH); HashMap<String, File> fileList = new HashMap<>(); fileList.put(GenericExpansionRewriter.GENERIC_EXPAND_DICT, new File(GENERIC_EXPAND_DICT_PATH)); @@ -37,13 +40,10 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { utils = new QueryRewriteSearcherTestUtils(execution); } - public GenericExpansionRewriterTestCase(String name) { - super(name); - } - /** * MaxRewrites=3, PartialPhraseMatch is on, type=adv case */ + @Test public void testPartialPhraseMaxRewriteAdvType() { utils.assertRewrittenQuery("?query=(modern new york city travel phone number) OR (travel agency) OR travel&type=adv&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true&" + @@ -56,6 +56,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * PartialPhraseMatch is off, type=adv case */ + @Test public void testPartialPhraseNoMaxRewriteAdvType() { utils.assertRewrittenQuery("?query=(modern new york city travel phone number) OR (travel agency) OR travel&type=adv&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=false", @@ -66,6 +67,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, type=adv, added filter case */ + @Test public void testFullPhraseNoMaxRewriteAdvTypeFilter() { utils.assertRewrittenQuery("?query=ca OR (modern new york city travel phone number) OR (travel agency) OR travel&" + "type=adv&filter=citystate:santa clara ca&" + @@ -77,6 +79,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * MaxRewrites=0 (i.e No MaxRewrites), PartialPhraseMatch is on, type=adv, added filter case */ + @Test public void testPartialPhraseNoMaxRewriteAdvTypeFilter() { utils.assertRewrittenQuery("?query=ca OR (modern new york city travel phone number) OR (travel agency) OR travel&" + "type=adv&filter=citystate:santa clara ca&" + @@ -92,6 +95,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, single word, added filter case */ + @Test public void testFullPhraseNoMaxRewriteSingleWordFilter() { utils.assertRewrittenQuery("?query=ca&" + "filter=citystate:santa clara ca&" + @@ -102,6 +106,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is on, single word, added filter case */ + @Test public void testPartialPhraseNoMaxRewriteSingleWordFilter() { utils.assertRewrittenQuery("?query=ca&" + "filter=citystate:santa clara ca&" + @@ -112,6 +117,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, multi word, added filter case */ + @Test public void testFullPhraseNoMaxRewriteMultiWordFilter() { utils.assertRewrittenQuery("?query=travel agency&" + "filter=citystate:santa clara ca&" + @@ -122,6 +128,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is on, multi word, added filter case */ + @Test public void testPartialPhraseNoMaxRewriteMultiWordFilter() { utils.assertRewrittenQuery("?query=modern new york city travel phone number&" + "filter=citystate:santa clara ca&" + @@ -134,6 +141,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, single word */ + @Test public void testFullPhraseNoMaxRewriteSingleWord() { utils.assertRewrittenQuery("?query=ca&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=false", @@ -143,6 +151,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is on, single word */ + @Test public void testPartialPhraseNoMaxRewriteSingleWord() { utils.assertRewrittenQuery("?query=ca&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true", @@ -152,6 +161,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, multi word */ + @Test public void testFullPhraseNoMaxRewriteMultiWord() { utils.assertRewrittenQuery("?query=travel agency&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=false", @@ -161,6 +171,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, multi word, no full match */ + @Test public void testFullPhraseNoMaxRewriteMultiWordNoMatch() { utils.assertRewrittenQuery("?query=nyc travel agency&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=false", @@ -170,6 +181,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is on, multi word */ + @Test public void testPartialPhraseNoMaxRewriteMultiWord() { utils.assertRewrittenQuery("?query=modern new york city travel phone number&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true", @@ -182,6 +194,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { * Dictionary contain the word "travel agency", the word "agency" and the word "travel" * Should rewrite travel but not travel agency in this case */ + @Test public void testPartialPhraseMultiWordRankTree() { utils.assertRewrittenQuery("?query=travel RANK agency&type=adv&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true", @@ -193,10 +206,12 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { * Dictionary contain the word "travel agency", the word "agency" and the word "travel" * Should rewrite travel but not travel agency in this case */ + @Test public void testFullPhraseMultiWordRankTree() { utils.assertRewrittenQuery("?query=travel RANK agency&type=adv&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true", "query 'RANK (OR tr travel) agency'"); } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java index 82f548727f6..9a9e9ff52e0 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java @@ -6,13 +6,17 @@ import com.yahoo.search.searchchain.*; import com.yahoo.search.intent.model.*; import com.yahoo.search.query.rewrite.*; import com.yahoo.search.query.rewrite.rewriters.*; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.fail; /** * Test Cases for MisspellRewriter * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class MisspellRewriterTestCase extends junit.framework.TestCase { +public class MisspellRewriterTestCase { private QueryRewriteSearcherTestUtils utils; public final String REWRITER_NAME = MisspellRewriter.REWRITER_NAME; @@ -21,20 +25,18 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * Load the QueryRewriteSearcher and prepare the * execution object */ - protected void setUp() { + @Before + public void setUp() { MisspellRewriter searcher = new MisspellRewriter(); Execution execution = QueryRewriteSearcherTestUtils.createExecutionObj(searcher); utils = new QueryRewriteSearcherTestUtils(execution); } - public MisspellRewriterTestCase(String name) { - super(name); - } - /** * QSSRewrite and QSSSuggest are on * QLAS returns spell correction: qss_rw=0.9 qss_sugg=1.0 */ + @Test public void testQSSRewriteQSSSuggestWithRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("will smith rw", 0.9, @@ -53,6 +55,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * QSSRewrite is on * QLAS returns spell correction: qss_rw=0.9 qss_rw=0.9 qss_sugg=1.0 */ + @Test public void testQSSRewriteWithRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("will smith rw1", 0.9, @@ -72,6 +75,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * QSSSuggest is on * QLAS returns spell correction: qss_rw=1.0 qss_sugg=0.9 qss_sugg=0.8 */ + @Test public void testQSSSuggWithRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("will smith rw", 1.0, @@ -91,6 +95,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * QSSRewrite and QSSSuggest are off * QLAS returns spell correction: qss_rw=1.0 qss_sugg=1.0 */ + @Test public void testFeautureOffWithRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("will smith rw", 1.0, @@ -107,6 +112,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * QSSRewrite and QSSSuggest are on * QLAS returns no spell correction */ + @Test public void testQSSRewriteQSSSuggWithoutRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("use diff query for testing", 1.0, @@ -125,6 +131,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * IntentModel is null * It should throw exception */ + @Test public void testNullIntentModelException() { try { RewriterUtils.getSpellCorrected(new Query("willl smith"), true, true); @@ -132,5 +139,6 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { } catch (RuntimeException e) { } } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/NameRewriterTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/NameRewriterTestCase.java index c44613f4f49..985ea2da001 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/NameRewriterTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/NameRewriterTestCase.java @@ -8,13 +8,15 @@ import com.yahoo.search.searchchain.*; import com.yahoo.search.query.rewrite.*; import com.yahoo.search.query.rewrite.rewriters.*; import com.yahoo.search.query.rewrite.RewritesConfig; +import org.junit.Before; +import org.junit.Test; /** * Test Cases for NameRewriter * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class NameRewriterTestCase extends junit.framework.TestCase { +public class NameRewriterTestCase { private QueryRewriteSearcherTestUtils utils; private final String CONFIG_PATH = "file:src/test/java/com/yahoo/search/query/rewrite/test/" + @@ -27,7 +29,8 @@ public class NameRewriterTestCase extends junit.framework.TestCase { * Load the NameRewriterSearcher and prepare the * execution object */ - protected void setUp() { + @Before + public void setUp() { RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(CONFIG_PATH); HashMap<String, File> fileList = new HashMap<>(); fileList.put(NameRewriter.NAME_ENTITY_EXPAND_DICT, new File(NAME_ENTITY_EXPAND_DICT_PATH)); @@ -37,13 +40,10 @@ public class NameRewriterTestCase extends junit.framework.TestCase { utils = new QueryRewriteSearcherTestUtils(execution); } - public NameRewriterTestCase(String name) { - super(name); - } - /** * RewritesAsEquiv and OriginalAsUnit are on */ + @Test public void testRewritesAsEquivAndOriginalAsUnit() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&" + @@ -58,6 +58,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * RewritesAsEquiv is on */ + @Test public void testRewritesAsEquiv() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&", @@ -72,6 +73,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { * Complex query with more than two levels for RewritesAsEquiv is on case * Should not rewrite */ + @Test public void testComplextQueryRewritesAsEquiv() { utils.assertRewrittenQuery("?query=((will smith) OR (willl smith)) AND (tom cruise)&type=adv&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&", @@ -81,6 +83,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * Single word query for RewritesAsEquiv and OriginalAsUnit on case */ + @Test public void testSingleWordForRewritesAsEquivAndOriginalAsUnit() { utils.assertRewrittenQuery("?query=obama&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&" + @@ -97,6 +100,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * RewritesAsUnitEquiv and OriginalAsUnitEquiv are on */ + @Test public void testRewritesAsUnitEquivAndOriginalAsUnitEquiv() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_UNIT_EQUIV + @@ -113,6 +117,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * Single word query for RewritesAsUnitEquiv and OriginalAsUnitEquiv on case */ + @Test public void testSingleWordForRewritesAsUnitEquivAndOriginalAsUnitEquiv() { utils.assertRewrittenQuery("?query=obama&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_UNIT_EQUIV + @@ -132,6 +137,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { * Boosting only query (n/a as rewrite in FSA) * for RewritesAsEquiv and OriginalAsUnit on case */ + @Test public void testBoostingQueryForRewritesAsEquivAndOriginalAsUnit() { utils.assertRewrittenQuery("?query=angelina jolie&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&" + @@ -143,6 +149,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { * No match in FSA for the query * RewritesAsEquiv and OriginalAsUnit on case */ + @Test public void testFSANoMatchForRewritesAsEquivAndOriginalAsUnit() { utils.assertRewrittenQuery("?query=tom cruise&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&" + @@ -153,6 +160,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * RewritesAsUnitEquiv is on */ + @Test public void testRewritesAsUnitEquiv() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_UNIT_EQUIV + @@ -167,6 +175,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * RewritesAsUnitEquiv is on and MaxRewrites is set to 2 */ + @Test public void testRewritesAsUnitEquivAndMaxRewrites() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_UNIT_EQUIV + @@ -175,5 +184,6 @@ public class NameRewriterTestCase extends junit.framework.TestCase { "query 'OR (AND will smith) \"will smith movies\" " + "\"will smith news\"'"); } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestCase.java index 9e21df844f2..46693915f95 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestCase.java @@ -10,13 +10,15 @@ import com.yahoo.search.intent.model.*; import com.yahoo.search.query.rewrite.RewritesConfig; import com.yahoo.search.query.rewrite.*; import com.yahoo.search.query.rewrite.rewriters.*; +import org.junit.Before; +import org.junit.Test; /** * Generic Test Cases for QueryRewriteSearcher * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { +public class QueryRewriteSearcherTestCase { private QueryRewriteSearcherTestUtils utils; private final String NAME_REWRITER_CONFIG_PATH = "file:src/test/java/com/yahoo/search/query/rewrite/test/" + @@ -34,7 +36,8 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { * Load the QueryRewriteSearcher and prepare the * execution object */ - protected void setUp() { + @Before + public void setUp() { // Instantiate Name Rewriter RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(NAME_REWRITER_CONFIG_PATH); HashMap<String, File> fileList = new HashMap<>(); @@ -53,14 +56,11 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { utils = new QueryRewriteSearcherTestUtils(execution); } - public QueryRewriteSearcherTestCase(String name) { - super(name); - } - /** * Invalid FSA config path * Query will be passed to next rewriter */ + @Test public void testInvalidFSAConfigPath() { // Instantiate Name Rewriter with fake FSA path RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(FAKE_FSA_CONFIG_PATH); @@ -89,7 +89,8 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { * IntentModel is null and rewriter throws exception * It should skip to the next rewriter */ - public void testExceptionInRewriter() { + @Test + public void testExceptionInRewriter() { utils.assertRewrittenQuery("?query=will smith&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_SUGG + "=true&" + @@ -108,6 +109,7 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { * Two rewrites in chain * Query will be rewritten twice */ + @Test public void testTwoRewritersInChain() { IntentModel intentModel = new IntentModel( utils.createInterpretation("wills smith", 0.9, @@ -129,5 +131,6 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { "\"will smith biography\"'", intentModel); } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestUtils.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestUtils.java index 0ae9715c377..fc76a27f306 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestUtils.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestUtils.java @@ -1,24 +1,26 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.rewrite.test; +import com.yahoo.search.Query; +import com.yahoo.search.Result; +import com.yahoo.search.Searcher; +import com.yahoo.search.intent.model.IntentModel; +import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; -import junit.framework.Assert; -import java.util.*; - -import com.yahoo.search.*; -import com.yahoo.search.searchchain.*; import com.yahoo.search.query.rewrite.RewritesConfig; -import com.yahoo.search.intent.model.*; import com.yahoo.text.interpretation.Modification; import com.yahoo.text.interpretation.Interpretation; import com.yahoo.text.interpretation.Annotations; import com.yahoo.config.subscription.ConfigGetter; import com.yahoo.component.chain.Chain; +import org.junit.Assert; + +import java.util.List; /** * Test utilities for QueryRewriteSearcher * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ public class QueryRewriteSearcherTestUtils { @@ -33,16 +35,13 @@ public class QueryRewriteSearcherTestUtils { this.execution = execution; } - /** * Create config object based on config path * * @param configPath path for the searcher config */ public static RewritesConfig createConfigObj(String configPath) { - ConfigGetter<RewritesConfig> getter = new ConfigGetter<>(RewritesConfig.class); - RewritesConfig config = getter.getConfig(configPath); - return config; + return new ConfigGetter<>(RewritesConfig.class).getConfig(configPath); } /** @@ -51,10 +50,7 @@ public class QueryRewriteSearcherTestUtils { * @param searcher searcher to be added to the search chain */ public static Execution createExecutionObj(Searcher searcher) { - @SuppressWarnings("deprecation") - Chain<Searcher> searchChain = new Chain<>(searcher); - Execution myExecution = new Execution(searchChain, Execution.Context.createContextStub()); - return myExecution; + return new Execution(new Chain<>(searcher), Execution.Context.createContextStub()); } /** @@ -63,19 +59,15 @@ public class QueryRewriteSearcherTestUtils { * @param searchers list of searchers to be added to the search chain */ public static Execution createExecutionObj(List<Searcher> searchers) { - @SuppressWarnings("deprecation") - Chain<Searcher> searchChain = new Chain<>(searchers); - Execution myExecution = new Execution(searchChain, Execution.Context.createContextStub()); - return myExecution; + return new Execution(new Chain<>(searchers), Execution.Context.createContextStub()); } /** * Compare the rewritten query returned after executing * the origQuery against the provided finalQuery - * @param origQuery query to be passed to Query object - * e.g. "?query=will%20smith" - * @param finalQuery expected final query from result.getQuery() - * e.g. "query 'AND will smith'" + * + * @param origQuery query to be passed to Query object e.g. "?query=will%20smith" + * @param finalQuery expected final query from result.getQuery() e.g. "query 'AND will smith'" */ public void assertRewrittenQuery(String origQuery, String finalQuery) { Query query = new Query(QueryTestCase.httpEncode(origQuery)); @@ -87,10 +79,9 @@ public class QueryRewriteSearcherTestUtils { * Set the provided intent model * Compare the rewritten query returned after executing * the origQuery against the provided finalQuery - * @param origQuery query to be passed to Query object - * e.g. "?query=will%20smith" - * @param finalQuery expected final query from result.getQuery() - * e.g. "query 'AND will smith'" + * + * @param origQuery query to be passed to Query object e.g. "?query=will%20smith" + * @param finalQuery expected final query from result.getQuery() e.g. "query 'AND will smith'" * @param intentModel IntentModel to be added to the Query */ public void assertRewrittenQuery(String origQuery, String finalQuery, IntentModel intentModel) { @@ -103,14 +94,14 @@ public class QueryRewriteSearcherTestUtils { /** * Create a new interpretation with modification that * contains the passed in query and score + * * @param spellRewrite query to be used as modification * @param score score to be used as modification score * @param isQSSRW whether the modification is qss_rw * @param isQSSSugg whether the modification is qss_sugg * @return newly created interpretation with modification */ - public Interpretation createInterpretation(String spellRewrite, double score, - boolean isQSSRW, boolean isQSSSugg) { + public Interpretation createInterpretation(String spellRewrite, double score, boolean isQSSRW, boolean isQSSSugg) { Modification modification = new Modification(spellRewrite); Annotations annotation = modification.getAnnotation(); annotation.put("score", score); @@ -121,5 +112,6 @@ public class QueryRewriteSearcherTestUtils { Interpretation interpretation = new Interpretation(modification); return interpretation; } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/SearchChainDispatcherSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/SearchChainDispatcherSearcherTestCase.java index af16d892aa2..8142c9032b5 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/SearchChainDispatcherSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/SearchChainDispatcherSearcherTestCase.java @@ -12,13 +12,15 @@ import com.yahoo.search.searchchain.SearchChainRegistry; import com.yahoo.search.query.rewrite.RewritesConfig; import com.yahoo.search.intent.model.*; import com.yahoo.component.chain.Chain; +import org.junit.Before; +import org.junit.Test; /** * Test Cases for SearchChainDispatcherSearcher * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestCase { +public class SearchChainDispatcherSearcherTestCase { private QueryRewriteSearcherTestUtils utils; private final String NAME_REWRITER_CONFIG_PATH = "file:src/test/java/com/yahoo/search/query/rewrite/test/" + @@ -29,13 +31,12 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC private final String MISSPELL_REWRITER_NAME = MisspellRewriter.REWRITER_NAME; private final String US_MARKET_SEARCH_CHAIN = "us_qrw"; - /** * Load the QueryRewriteSearcher and prepare the * execution object */ - @SuppressWarnings("deprecation") - protected void setUp() { + @Before + public void setUp() { // Instantiate Name Rewriter RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(NAME_REWRITER_CONFIG_PATH); HashMap<String, File> fileList = new HashMap<>(); @@ -64,14 +65,11 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC utils = new QueryRewriteSearcherTestUtils(execution); } - public SearchChainDispatcherSearcherTestCase(String name) { - super(name); - } - /** * Execute the market chain * Query will be rewritten twice */ + @Test public void testMarketChain() { IntentModel intentModel = new IntentModel( utils.createInterpretation("wills smith", 0.9, @@ -98,6 +96,7 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC * Market chain is not valid * Query will be passed to next rewriter */ + @Test public void testInvalidMarketChain() { utils.assertRewrittenQuery("?query=will smith&QRWChain=abc&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true&" + @@ -111,6 +110,7 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC * Empty market chain value * Query will be passed to next rewriter */ + @Test public void testEmptyMarketChain() { utils.assertRewrittenQuery("?query=will smith&QRWChain=&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true&" + @@ -124,7 +124,7 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC * Searchers down the chain after SearchChainDispatcher * should be executed */ - @SuppressWarnings("deprecation") + @Test public void testChainContinuation() { // Instantiate Name Rewriter RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(NAME_REWRITER_CONFIG_PATH); @@ -175,5 +175,6 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC "\"will smith biography\"'", intentModel); } + } |