diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-13 22:18:11 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-13 22:18:11 +0200 |
commit | 8c54be83e36fa4ba28c747fec2b8040832002b49 (patch) | |
tree | c63d75c05930352205e46fd405b2ddc5272dcd1f /container-search/src/test/java/com/yahoo/prelude | |
parent | 41969051757a99e5c8ed09fac31fa0658f039c7c (diff) |
Remove usage of old junit
Diffstat (limited to 'container-search/src/test/java/com/yahoo/prelude')
47 files changed, 486 insertions, 283 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java index b1763471c82..7b92e2c1a7c 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.prelude.searcher.test; import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; -import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.search.Query; import com.yahoo.search.Result; @@ -12,16 +11,19 @@ import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.result.Hit; import com.yahoo.prelude.searcher.QuerySnapshotSearcher; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; import java.util.ArrayList; import java.util.List; +import static org.junit.Assert.assertEquals; + /** * @author bratseth */ -@SuppressWarnings("deprecation") -public class QuerySnapshotSearcherTestCase extends junit.framework.TestCase { +public class QuerySnapshotSearcherTestCase { + @Test public void test() { Searcher searcher=new QuerySnapshotSearcher(); Result result = doSearch(searcher, new Query(), 0,10); diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java index d41db1ca227..3967ac63e36 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.prelude.searcher.test; import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; -import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.result.Hit; @@ -13,23 +12,24 @@ import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.testutil.DocumentSourceSearcher; import com.yahoo.prelude.searcher.QueryValidatingSearcher; +import org.junit.Test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + /** * Tests correct denial of query. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class QueryValidatingSearcherTestCase extends junit.framework.TestCase { - - public QueryValidatingSearcherTestCase(String name) { - super(name); - } +public class QueryValidatingSearcherTestCase { + @Test public void testBasic() { // Setup Map<Searcher, Searcher> chained = new HashMap<>(); diff --git a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java index 4386fcd1cd1..6c4253bff2d 100644 --- a/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java @@ -5,7 +5,6 @@ import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.ComponentId; import com.yahoo.component.chain.Chain; import com.yahoo.config.subscription.ConfigGetter; -import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.searcher.QrQuotetableConfig; import com.yahoo.search.rendering.RendererRegistry; @@ -19,29 +18,30 @@ import com.yahoo.search.Searcher; import com.yahoo.prelude.searcher.DocumentSourceSearcher; import com.yahoo.prelude.searcher.QuotingSearcher; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Tests hit property quoting. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ @SuppressWarnings("deprecation") -public class QuotingSearcherTestCase extends junit.framework.TestCase { - - public QuotingSearcherTestCase (String name) { - super(name); - } +public class QuotingSearcherTestCase { public static QuotingSearcher createQuotingSearcher(String configId) { QrQuotetableConfig config = new ConfigGetter<>(QrQuotetableConfig.class).getConfig(configId); return new QuotingSearcher(new ComponentId("QuotingSearcher"), config); } + @Test public void testBasicQuoting() { Map<Searcher, Searcher> chained = new HashMap<>(); Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" @@ -61,6 +61,7 @@ public class QuotingSearcherTestCase extends junit.framework.TestCase { assertTrue(check.hits().get(0).fields().containsKey("title")); } + @Test public void testBasicQuotingWithNoisyStrings() { Map<Searcher, Searcher> chained = new HashMap<>(); Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" @@ -80,6 +81,7 @@ public class QuotingSearcherTestCase extends junit.framework.TestCase { assertTrue(check.hits().get(0).fields().containsKey("title")); } + @Test public void testFieldQuotingWithNoisyStrings() { Map<Searcher, Searcher> chained = new HashMap<>(); Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" @@ -100,6 +102,7 @@ public class QuotingSearcherTestCase extends junit.framework.TestCase { } + @Test public void testNoQuotingWithOtherTypes() { Map<Searcher, Searcher> chained = new HashMap<>(); Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AlibabaTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AlibabaTestCase.java index c1827ad035c..f3e9a174288 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AlibabaTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AlibabaTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * Test a case reported by Alibaba * @@ -8,22 +10,26 @@ package com.yahoo.prelude.semantics.test; */ public class AlibabaTestCase extends RuleBaseAbstractTestCase { - public AlibabaTestCase(String name) { - super(name,"alibaba.sr"); + public AlibabaTestCase() { + super("alibaba.sr"); } + @Test public void testNumberReplacement() { assertSemantics("AND nokia 3100","3100"); } + @Test public void testRuleFollowingNumber() { assertSemantics("lenovo","legend"); } + @Test public void testCombinedNumberAndRegular1() { assertSemantics("AND lenovo nokia 3100","legend 3100"); } + @Test public void testCombinedNumberAndRegular2() { assertSemantics("AND nokia 3100 lenovo","3100 legend"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AnchorTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AnchorTestCase.java index 459c09642ee..960a790c671 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AnchorTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AnchorTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * Tests anchoring * @@ -8,24 +10,27 @@ package com.yahoo.prelude.semantics.test; */ public class AnchorTestCase extends RuleBaseAbstractTestCase { - public AnchorTestCase(String name) { - super(name,"anchor.sr"); + public AnchorTestCase() { + super("anchor.sr"); } + @Test public void testSingleWordAnchoredBothSides() { - assertSemantics("anchor","word"); - assertSemantics("anchor","anotherword"); - assertSemantics("notthisword","notthisword"); - assertSemantics("AND word anotherword","word anotherword"); + assertSemantics("anchor", "word"); + assertSemantics("anchor", "anotherword"); + assertSemantics("notthisword", "notthisword"); + assertSemantics("AND word anotherword", "word anotherword"); } + @Test public void testMultiwordAnchored() { - assertSemantics("anchor","this is complete"); - assertSemantics("AND this is complete toomuch","this is complete toomuch"); - assertSemantics("anchor","a phrase"); - assertSemantics("anchor","another phrase"); + assertSemantics("anchor", "this is complete"); + assertSemantics("AND this is complete toomuch", "this is complete toomuch"); + assertSemantics("anchor", "a phrase"); + assertSemantics("anchor", "another phrase"); } + @Test public void testFirstAnchored() { assertSemantics("anchor","first"); assertSemantics("AND anchor andmore","first andmore"); @@ -33,6 +38,7 @@ public class AnchorTestCase extends RuleBaseAbstractTestCase { assertSemantics("AND before first andmore","before first andmore"); } + @Test public void testLastAnchored() { assertSemantics("anchor","last"); assertSemantics("AND andmore anchor","andmore last"); @@ -40,6 +46,7 @@ public class AnchorTestCase extends RuleBaseAbstractTestCase { assertSemantics("AND andmore last after","andmore last after"); } + @Test public void testFirstAndLastAnchored() { assertSemantics("AND anchor anchor","first last"); assertSemantics("AND last first","last first"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataNotTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataNotTestCase.java index f2f8c3f7cf9..cda5bf91fd4 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataNotTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataNotTestCase.java @@ -1,6 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Ignore; +import org.junit.Test; + /** * Tests that ![a] is interpreted as "default:![a]", not as "!default:[a]", * that is, in negative conditions we still only want to match the default index by default. @@ -9,14 +12,16 @@ package com.yahoo.prelude.semantics.test; */ public class AutomataNotTestCase extends RuleBaseAbstractTestCase { - public AutomataNotTestCase(String name) { - super(name,"automatanot.sr","semantics.fsa"); + public AutomataNotTestCase() { + super("automatanot.sr", "semantics.fsa"); } + @Test + @Ignore // TODO: MAKE THIS WORK! public void testAutomataNot() { - if (System.currentTimeMillis() > 0) return; // TODO: MAKE THIS WORK! - assertSemantics("carpenter","carpenter"); - assertSemantics("RANK brukbar busname:brukbar","brukbar"); + if (System.currentTimeMillis() > 0) return; + assertSemantics("carpenter", "carpenter"); + assertSemantics("RANK brukbar busname:brukbar", "brukbar"); } } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataTestCase.java index f0bf194f7a3..70952ece676 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataTestCase.java @@ -3,6 +3,11 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; import com.yahoo.prelude.semantics.RuleBase; +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Tests rule bases using automatas for matching @@ -13,11 +18,12 @@ public class AutomataTestCase extends RuleBaseAbstractTestCase { private final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; - public AutomataTestCase(String name) { - super(name,"automatarules.sr","semantics.fsa"); + public AutomataTestCase() { + super("automatarules.sr", "semantics.fsa"); } - public void testAutomataRuleBase() throws Exception { + @Test + public void testAutomataRuleBase() { RuleBase ruleBase=searcher.getDefaultRuleBase(); assertEquals(RuleBase.class,ruleBase.getClass()); assertTrue(ruleBase.getSource().endsWith(root + "automatarules.sr")); @@ -35,16 +41,19 @@ public class AutomataTestCase extends RuleBaseAbstractTestCase { assertEquals("RANK (AND sony digital camera) dsp1:sony dsp5:digicamera", query.getModel().getQueryTree().getRoot().toString()); } - public void testAutomataSingleQuery() throws Exception { + @Test + public void testAutomataSingleQuery() { assertSemantics("RANK sony dsp1:sony","sony"); } - public void testAutomataFilterIsIgnored() throws Exception { + @Test + public void testAutomataFilterIsIgnored() { assertSemantics("RANK sony |something dsp1:sony","sony&filter=something"); assertSemantics("RANK something |sony","something&filter=sony"); } - public void testAutomataPluralMatches() throws Exception { + @Test + public void testAutomataPluralMatches() { assertSemantics("RANK sonys dsp1:sony","sonys"); assertSemantics("RANK (AND car cleaner) dsp1:\"car cleaners\" dsp5:\"car cleaners\"","car cleaner"); @@ -52,15 +61,19 @@ public class AutomataTestCase extends RuleBaseAbstractTestCase { assertSemantics("RANK (AND sony digitals cameras) dsp1:sony dsp5:digicamera","sony digitals cameras"); } + @Test public void testMatchingMultipleAutomataConditionsSingleWord() { assertSemantics("RANK carpenter dsp1:carpenter dsp5:carpenter","carpenter"); } + @Test public void testMatchingMultipleAutomataConditionsPhrase() { assertSemantics("RANK (AND car cleaners) dsp1:\"car cleaners\" dsp5:\"car cleaners\"","car cleaners"); } - public void tstReplaceOnNoMatch() { // TODO: Make this work again + @Test + @Ignore // TODO: Make this work again + public void testReplaceOnNoMatch() { assertSemantics("nomatch:sonny","sonny&donomatch"); assertSemantics("RANK sony dsp1:sony","sony&donomatch"); assertSemantics("RANK sonys dsp1:sony","sonys&donomatch"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java index 245556a1487..68c870872b9 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java @@ -1,40 +1,42 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; -import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.search.Query; -import com.yahoo.prelude.semantics.RuleBase; import com.yahoo.prelude.semantics.RuleImporter; import com.yahoo.prelude.semantics.SemanticSearcher; -import com.yahoo.prelude.semantics.parser.ParseException; import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author bratseth */ @SuppressWarnings("deprecation") -public class BacktrackingTestCase extends junit.framework.TestCase { +public class BacktrackingTestCase { - private final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; + private static final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; - public BacktrackingTestCase(String name) throws ParseException, IOException { - super(name); - RuleBase rules=new RuleImporter().importFile(root + "backtrackingrules.sr"); - searcher=new SemanticSearcher(rules); - } + private static final SemanticSearcher searcher; - private SemanticSearcher searcher; + static { + try { + searcher = new SemanticSearcher(new RuleImporter().importFile(root + "backtrackingrules.sr")); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } protected void assertSemantics(String result,String input) { assertSemantics(result,input,0); @@ -48,37 +50,45 @@ public class BacktrackingTestCase extends junit.framework.TestCase { // Literal terms --------------- + @Test public void testMultilevelBacktrackingLiteralTerms() { assertSemantics("replaced","word1 word2 word5 word8"); } + @Test public void testMultilevelBacktrackingWontReorderOthertermsLiteralTerms() { assertSemantics("AND other1 other2 other3 replaced","other1 other2 other3 word1 word2 word5 word8"); } + @Test public void testMultilevelBacktrackingWithMulticompoundMatchLiteralTerms() { assertSemantics("AND other1 other2 other3 replaced","other1 other2 other3 word1 word2 word5-word8"); } + @Test public void testMultilevelBacktrackingPreservePartialMatchBeforeLiteralTerms() { assertSemantics("AND word1 word2 word5 replaced","word1 word2 word5 word1 word2 word5 word8"); } + @Test public void testMultilevelBacktrackingPreservePartialMatchAfterLiteralTerms() { assertSemantics("AND replaced word1 word2 word5","word1 word2 word5 word8 word1 word2 word5 "); } // reference terms --------------- + @Test public void testMultilevelBacktrackingReferenceTerms() { assertSemantics("AND ref:ref1 ref:ref2 ref:ref5 ref:ref8","ref1 ref2 ref5 ref8"); } + @Test public void testMultilevelBacktrackingPreservePartialMatchBeforeReferenceTerms() { assertSemantics("AND ref1 ref2 ref5 ref:ref1 ref:ref2 ref:ref5 ref:ref8", "ref1 ref2 ref5 ref1 ref2 ref5 ref8"); } + @Test public void testMultilevelBacktrackingPreservePartialMatchAfterReferenceTerms() { assertSemantics("AND ref:ref1 ref:ref2 ref:ref5 ref:ref8 ref1 ref2 ref5", "ref1 ref2 ref5 ref8 ref1 ref2 ref5"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BlendingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BlendingTestCase.java index acf45309c83..2b3a33d1662 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/BlendingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/BlendingTestCase.java @@ -2,6 +2,9 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests blending rules @@ -10,24 +13,26 @@ import com.yahoo.search.Query; */ public class BlendingTestCase extends RuleBaseAbstractTestCase { - public BlendingTestCase(String name) { - super(name,"blending.sr"); + public BlendingTestCase() { + super("blending.sr"); } /** Tests parameter literal matching */ + @Test public void testLiteralEquals() { assertParameterSemantics("AND a sun came cd","a sun came cd","search","[music]"); assertParameterSemantics("AND driving audi","driving audi","search","[cars]"); //assertParameterSemantics("AND audi music quality","audi music quality","search","carstereos",1); } - private void assertParameterSemantics(String producedQuery,String inputQuery, - String producedParameterName,String producedParameterValue) { + private void assertParameterSemantics(String producedQuery, String inputQuery, + String producedParameterName, String producedParameterValue) { assertParameterSemantics(producedQuery,inputQuery,producedParameterName,producedParameterValue,0); } private void assertParameterSemantics(String producedQuery,String inputQuery, - String producedParameterName,String producedParameterValue,int tracing) { + String producedParameterName,String producedParameterValue, + int tracing) { Query query=assertSemantics(producedQuery,inputQuery,tracing); assertEquals(producedParameterValue, query.properties().getString(producedParameterName)); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/CJKTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/CJKTestCase.java index 7ad3842c7a5..0f0644c22cb 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/CJKTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/CJKTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * Tests that using rule bases containing cjk characters work * @@ -8,10 +10,11 @@ package com.yahoo.prelude.semantics.test; */ public class CJKTestCase extends RuleBaseAbstractTestCase { - public CJKTestCase(String name) { - super(name,"cjk.sr"); + public CJKTestCase() { + super("cjk.sr"); } + @Test public void testIt() { assertSemantics("\u7d22a","a\u7d22"); assertSemantics("\u7d22a","\u7d22a"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java index 44774c63219..70b637754ce 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java @@ -1,19 +1,22 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * @author bratseth */ public class ComparisonTestCase extends RuleBaseAbstractTestCase { - public ComparisonTestCase(String name) { - super(name,"comparison.sr"); + public ComparisonTestCase() { + super("comparison.sr"); } /** * Tests that we can wriote rules which depends on the <i>same term</i> (java) being matched by two * different conditions (coffee, island) */ + @Test public void testNamedConditionReturnComparison() { // Not sufficient that both conditions are matched assertSemantics("AND borneo arabica island:borneo coffee:arabica","borneo arabica"); @@ -26,12 +29,14 @@ public class ComparisonTestCase extends RuleBaseAbstractTestCase { "borneo arabica java"); } + @Test public void testContainsAsSubstring() { assertSemantics("AND java island:java coffee:java control:ambigous off","java"); assertSemantics("AND kanava island:kanava off","kanava"); assertSemantics("AND borneo island:borneo","borneo"); } + @Test public void testAlphanumericComparison() { assertSemantics("a","a"); assertSemantics("AND z highletter","z"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonsTestCase.java index d42b344281d..3e322039240 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonsTestCase.java @@ -1,15 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * @author bratseth */ public class ComparisonsTestCase extends RuleBaseAbstractTestCase { - public ComparisonsTestCase(String name) { - super(name,"comparisons.sr"); + public ComparisonsTestCase() { + super("comparisons.sr"); } + @Test public void testLiteralEquals() { assertSemantics("a","a"); assertSemantics("RANK a foo:a","a&ranking=category"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConditionTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConditionTestCase.java index d17de425e88..295fd713c1d 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConditionTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConditionTestCase.java @@ -12,66 +12,70 @@ import com.yahoo.prelude.semantics.rule.ProductionRule; import com.yahoo.prelude.semantics.rule.ReplacingProductionRule; import com.yahoo.prelude.semantics.rule.SequenceCondition; import com.yahoo.prelude.semantics.rule.TermCondition; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author bratseth */ -public class ConditionTestCase extends junit.framework.TestCase { - - public ConditionTestCase(String name) { - super(name); - } +public class ConditionTestCase { + @Test public void testTermCondition() { TermCondition term=new TermCondition("foo"); Query query=new Query("?query=foo"); assertTrue(term.matches(new Evaluation(query).freshRuleEvaluation())); } + @Test public void testSequenceCondition() { - TermCondition term1=new TermCondition("foo"); - TermCondition term2=new TermCondition("bar"); - SequenceCondition sequence=new SequenceCondition(); + TermCondition term1 = new TermCondition("foo"); + TermCondition term2 = new TermCondition("bar"); + SequenceCondition sequence = new SequenceCondition(); sequence.addCondition(term1); sequence.addCondition(term2); - Query query=new Query("?query=foo+bar"); + Query query = new Query("?query=foo+bar"); assertTrue(query + " matches " + sequence,sequence.matches(new Evaluation(query).freshRuleEvaluation())); - Query query2=new Query("?query=foo"); + Query query2 = new Query("?query=foo"); assertFalse(query2 + " does not match " + sequence,sequence.matches(new Evaluation(query2).freshRuleEvaluation())); - Query query3=new Query("?query=bar"); + Query query3 = new Query("?query=bar"); assertFalse(query3 + " does not match " + sequence,sequence.matches(new Evaluation(query3).freshRuleEvaluation())); } + @Test public void testChoiceCondition() { - TermCondition term1=new TermCondition("foo"); - TermCondition term2=new TermCondition("bar"); - ChoiceCondition choice=new ChoiceCondition(); + TermCondition term1 = new TermCondition("foo"); + TermCondition term2 = new TermCondition("bar"); + ChoiceCondition choice = new ChoiceCondition(); choice.addCondition(term1); choice.addCondition(term2); - Query query1=new Query("?query=foo+bar"); - assertTrue(query1 + " matches " + choice,choice.matches(new Evaluation(query1).freshRuleEvaluation())); - Query query2=new Query("?query=foo"); - assertTrue(query2 + " matches " + choice,choice.matches(new Evaluation(query2).freshRuleEvaluation())); - Query query3=new Query("?query=bar"); - assertTrue(query3 + " matches " + choice,choice.matches(new Evaluation(query3).freshRuleEvaluation())); + Query query1 = new Query("?query=foo+bar"); + assertTrue(query1 + " matches " + choice, choice.matches(new Evaluation(query1).freshRuleEvaluation())); + Query query2 = new Query("?query=foo"); + assertTrue(query2 + " matches " + choice, choice.matches(new Evaluation(query2).freshRuleEvaluation())); + Query query3 = new Query("?query=bar"); + assertTrue(query3 + " matches " + choice, choice.matches(new Evaluation(query3).freshRuleEvaluation())); } + @Test public void testNamedConditionReference() { - TermCondition term=new TermCondition("foo"); - NamedCondition named=new NamedCondition("cond",term); - ConditionReference reference=new ConditionReference("cond"); + TermCondition term = new TermCondition("foo"); + NamedCondition named = new NamedCondition("cond",term); + ConditionReference reference = new ConditionReference("cond"); // To initialize the condition reference... - ProductionRule rule=new ReplacingProductionRule(); + ProductionRule rule = new ReplacingProductionRule(); rule.setCondition(reference); rule.setProduction(new ProductionList()); - RuleBase ruleBase=new RuleBase(); + RuleBase ruleBase = new RuleBase(); ruleBase.setName("test"); ruleBase.addCondition(named); ruleBase.addRule(rule); ruleBase.initialize(); - Query query=new Query("?query=foo"); + Query query = new Query("?query=foo"); assertTrue(query + " matches " + reference,reference.matches(new Evaluation(query).freshRuleEvaluation())); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java index 1617b9b4e83..ed09e47f3b3 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java @@ -4,7 +4,6 @@ package com.yahoo.prelude.semantics.test; import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; import com.yahoo.config.subscription.ConfigGetter; -import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.semantics.SemanticRulesConfig; import com.yahoo.search.Query; @@ -16,25 +15,28 @@ import com.yahoo.search.Searcher; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; +import org.junit.Test; import java.util.ArrayList; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + /** * Tests creating a set of rule bases (the same set as in inheritingrules) from config * * @author bratseth */ -@SuppressWarnings("deprecation") -public class ConfigurationTestCase extends junit.framework.TestCase { +public class ConfigurationTestCase { - private final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; + private static final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; - private SemanticSearcher searcher; - private SemanticRulesConfig semanticRulesConfig; + private static final SemanticSearcher searcher; + private static final SemanticRulesConfig semanticRulesConfig; - public ConfigurationTestCase(String name) { - super(name); + static { semanticRulesConfig = new ConfigGetter<>(SemanticRulesConfig.class).getConfig("file:" + root + "semantic-rules.cfg"); searcher=new SemanticSearcher(semanticRulesConfig); } @@ -51,6 +53,7 @@ public class ConfigurationTestCase extends junit.framework.TestCase { assertEquals(result, query.getModel().getQueryTree().getRoot().toString()); } + @Test public void testReadingConfigurationRuleBase() { RuleBase parent=searcher.getRuleBase("parent"); assertNotNull(parent); @@ -58,6 +61,7 @@ public class ConfigurationTestCase extends junit.framework.TestCase { assertEquals("semantic-rules.cfg",parent.getSource()); } + @Test public void testParent() throws Exception { assertSemantics("vehiclebrand:audi","audi cars","parent"); assertSemantics("vehiclebrand:alfa","alfa bus","parent"); @@ -66,6 +70,7 @@ public class ConfigurationTestCase extends junit.framework.TestCase { assertSemantics("AND skoda car", "skoda cars","parent.sr"); } + @Test public void testChild1() throws Exception { assertSemantics("vehiclebrand:skoda","audi cars","child1.sr"); assertSemantics("vehiclebrand:alfa", "alfa bus","child1"); @@ -74,6 +79,7 @@ public class ConfigurationTestCase extends junit.framework.TestCase { assertSemantics("AND skoda car", "skoda cars","child1"); } + @Test public void testChild2() throws Exception { assertSemantics("vehiclebrand:audi","audi cars","child2"); assertSemantics("vehiclebrand:alfa","alfa bus","child2.sr"); @@ -82,6 +88,7 @@ public class ConfigurationTestCase extends junit.framework.TestCase { assertSemantics("vehiclebrand:skoda","skoda cars","child2"); } + @Test public void testGrandchild() throws Exception { assertSemantics("vehiclebrand:skoda","audi cars","grandchild.sr"); assertSemantics("vehiclebrand:alfa","alfa bus","grandchild"); @@ -90,6 +97,7 @@ public class ConfigurationTestCase extends junit.framework.TestCase { assertSemantics("vehiclebrand:skoda","skoda cars","grandchild"); } + @Test public void testSearcher() { assertSemantics("vehiclebrand:skoda", "vw cars", "grandchild"); assertSemantics("vehiclebrand:skoda", "vw cars", "grandchild.sd"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/DuplicateRuleTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/DuplicateRuleTestCase.java index 74cb15e64ee..338864ba2eb 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/DuplicateRuleTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/DuplicateRuleTestCase.java @@ -4,18 +4,19 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.prelude.semantics.RuleBaseException; import com.yahoo.prelude.semantics.RuleImporter; import com.yahoo.prelude.semantics.parser.ParseException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author bratseth */ -public class DuplicateRuleTestCase extends junit.framework.TestCase { +public class DuplicateRuleTestCase { private final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; - public DuplicateRuleTestCase(String name) { - super(name); - } - + @Test public void testDuplicateRuleBaseLoading() throws java.io.IOException, ParseException { if (System.currentTimeMillis() > 0) return; // TODO: Include this test... diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/Ellipsis2TestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/Ellipsis2TestCase.java index d4ae78cc2b9..77f3c656b4c 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/Ellipsis2TestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/Ellipsis2TestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * tersts the ellipsis rule base * @@ -8,10 +10,11 @@ package com.yahoo.prelude.semantics.test; */ public class Ellipsis2TestCase extends RuleBaseAbstractTestCase { - public Ellipsis2TestCase(String name) { - super(name,"ellipsis2.sr"); + public Ellipsis2TestCase() { + super("ellipsis2.sr"); } + @Test public void testUnreferencedEllipsis() { assertSemantics("AND a b c someindex:\"a b c\"","a b c"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/EllipsisTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/EllipsisTestCase.java index 7234f3cfd60..2672a91ce62 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/EllipsisTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/EllipsisTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * tersts the ellipsis rule base * @@ -8,10 +10,11 @@ package com.yahoo.prelude.semantics.test; */ public class EllipsisTestCase extends RuleBaseAbstractTestCase { - public EllipsisTestCase(String name) { - super(name,"ellipsis.sr"); + public EllipsisTestCase() { + super("ellipsis.sr"); } + @Test public void testUnreferencedEllipsis() { assertSemantics("AND why is stench unpleasant about:stench","why is stench unpleasant"); assertSemantics("AND why is the sky blue about:\"the sky\"","why is the sky blue"); @@ -19,6 +22,7 @@ public class EllipsisTestCase extends RuleBaseAbstractTestCase { "why is aardwark almost always most relevant in dictionaries"); } + @Test public void testReferencedEllipsis() { assertSemantics("album:parade","parade album"); assertSemantics("album:\"a sun came\"","a sun came album"); @@ -26,12 +30,14 @@ public class EllipsisTestCase extends RuleBaseAbstractTestCase { assertSemantics("album:\"a sun came\"","a sun came cd"); } + @Test public void testEllipsisInNamedCondition() { assertSemantics("AND name:\"a sun came\" product:video","buy a sun came"); assertSemantics("AND name:stalker product:video","buy stalker video"); assertSemantics("AND name:\"the usual suspects\" product:video","buy the usual suspects video"); } + @Test public void testMultipleEllipsis() { assertSemantics("AND from:paris to:texas","from paris to texas"); assertSemantics("AND from:\"sao paulo\" to:\"real madrid\"","from sao paulo to real madrid"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTestCase.java index 5521a478968..c811867f82c 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTestCase.java @@ -1,15 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * @author bratseth */ public class ExactMatchTestCase extends RuleBaseAbstractTestCase { - public ExactMatchTestCase(String name) { - super(name,"exactmatch.sr"); + public ExactMatchTestCase() { + super("exactmatch.sr"); } + @Test public void testCompleteMatch() { assertSemantics("AND primetime in no time","primetime notime"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTrickTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTrickTestCase.java index 7d9f7b401ba..4f2e1c79ba7 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTrickTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTrickTestCase.java @@ -3,25 +3,29 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; import com.yahoo.search.test.QueryTestCase; +import org.junit.Test; /** * @author bratseth */ public class ExactMatchTrickTestCase extends RuleBaseAbstractTestCase { - public ExactMatchTrickTestCase(String name) { - super(name,"exactmatchtrick.sr"); + public ExactMatchTrickTestCase() { + super("exactmatchtrick.sr"); } + @Test public void testCompleteMatch() { assertSemantics("AND default:primetime default:in default:no default:time", "primetime notime"); } + @Test public void testCompleteMatchWithNegative() { // Notice ordering bug assertSemantics("+(AND default:primetime default:in default:time default:no) -regionexcl:us", new Query(QueryTestCase.httpEncode("?query=primetime ANDNOT regionexcl:us&type=adv"))); } + @Test public void testCompleteMatchWithFilterAndNegative() { assertSemantics("AND (+(AND default:primetime default:in default:time default:no) -regionexcl:us) |lang:en", new Query(QueryTestCase.httpEncode("?query=primetime ANDNOT regionexcl:us&type=adv&filter=+lang:en"))); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java index 6553c64e00d..7c998fc43ee 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java @@ -7,7 +7,6 @@ import java.util.StringTokenizer; import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; -import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.search.Query; import com.yahoo.prelude.semantics.RuleBase; @@ -18,39 +17,50 @@ import com.yahoo.search.Searcher; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author bratseth */ @SuppressWarnings("deprecation") -public class InheritanceTestCase extends junit.framework.TestCase { +public class InheritanceTestCase { - private final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; + private static final String root = "src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; - private RuleBase parent, child1, child2, grandchild; - private SemanticSearcher searcher; + private static final RuleBase parent, child1, child2, grandchild; + private static final SemanticSearcher searcher; - public InheritanceTestCase(String name) throws Exception { - super(name); - parent=RuleBase.createFromFile(root + "inheritingrules/parent.sr",null); - child1=RuleBase.createFromFile(root + "inheritingrules/child1.sr",null); - child2=RuleBase.createFromFile(root + "inheritingrules/child2.sr",null); - grandchild=RuleBase.createFromFile(root + "inheritingrules/grandchild.sr",null); - grandchild.setDefault(true); + static { + try { + parent = RuleBase.createFromFile(root + "inheritingrules/parent.sr", null); + child1 = RuleBase.createFromFile(root + "inheritingrules/child1.sr", null); + child2 = RuleBase.createFromFile(root + "inheritingrules/child2.sr", null); + grandchild = RuleBase.createFromFile(root + "inheritingrules/grandchild.sr", null); + grandchild.setDefault(true); - searcher=new SemanticSearcher(parent,child1,child2,grandchild); + searcher = new SemanticSearcher(parent, child1, child2, grandchild); + } + catch (Exception e) { + throw new RuntimeException(e); + } } - protected void assertSemantics(String result,String input,RuleBase base) { - assertSemantics(result,input,base,0); + protected void assertSemantics(String result, String input, RuleBase base) { + assertSemantics(result, input, base, 0); } - protected void assertSemantics(String result,String input,RuleBase base,int tracelevel) { - Query query=new Query("?query=" + QueryTestCase.httpEncode(input)); - base.analyze(query,tracelevel); + protected void assertSemantics(String result, String input, RuleBase base, int tracelevel) { + Query query = new Query("?query=" + QueryTestCase.httpEncode(input)); + base.analyze(query, tracelevel); assertEquals(result, query.getModel().getQueryTree().getRoot().toString()); } + @Test public void testInclusion() { assertTrue(grandchild.includes("child1")); assertTrue(grandchild.includes("child2")); @@ -66,58 +76,65 @@ public class InheritanceTestCase extends junit.framework.TestCase { assertTrue(parent.includes("grandmother")); } + @Test public void testInclusionOrderAndContentDump() { - StringTokenizer lines=new StringTokenizer(grandchild.toContentString(),"\n",false); - assertEquals("vw -> audi",lines.nextToken()); - assertEquals("cars -> car",lines.nextToken()); - assertEquals("[brand] [vehicle] -> vehiclebrand:[brand]",lines.nextToken()); - assertEquals("vehiclebrand:bmw +> expensivetv",lines.nextToken()); - assertEquals("vehiclebrand:audi -> vehiclebrand:skoda",lines.nextToken()); - assertEquals("vehiclebrand:vw -> vehiclebrand:audi",lines.nextToken()); - assertEquals("causesphrase -> \"a produced phrase\"",lines.nextToken()); - assertEquals("[vehicle] :- car, motorcycle, bus",lines.nextToken()); - assertEquals("[brand] :- alfa, audi, bmw, skoda",lines.nextToken()); + StringTokenizer lines = new StringTokenizer(grandchild.toContentString(),"\n",false); + assertEquals("vw -> audi", lines.nextToken()); + assertEquals("cars -> car", lines.nextToken()); + assertEquals("[brand] [vehicle] -> vehiclebrand:[brand]", lines.nextToken()); + assertEquals("vehiclebrand:bmw +> expensivetv", lines.nextToken()); + assertEquals("vehiclebrand:audi -> vehiclebrand:skoda", lines.nextToken()); + assertEquals("vehiclebrand:vw -> vehiclebrand:audi", lines.nextToken()); + assertEquals("causesphrase -> \"a produced phrase\"", lines.nextToken()); + assertEquals("[vehicle] :- car, motorcycle, bus", lines.nextToken()); + assertEquals("[brand] :- alfa, audi, bmw, skoda", lines.nextToken()); } - public void testParent() throws Exception { - assertSemantics("vehiclebrand:audi","audi cars",parent); - assertSemantics("vehiclebrand:alfa","alfa bus",parent); - assertSemantics("AND vehiclebrand:bmw expensivetv","bmw motorcycle",parent); - assertSemantics("AND vw car", "vw cars",parent); - assertSemantics("AND skoda car", "skoda cars",parent); + @Test + public void testParent() { + assertSemantics("vehiclebrand:audi", "audi cars", parent); + assertSemantics("vehiclebrand:alfa", "alfa bus", parent); + assertSemantics("AND vehiclebrand:bmw expensivetv", "bmw motorcycle", parent); + assertSemantics("AND vw car", "vw cars", parent); + assertSemantics("AND skoda car", "skoda cars", parent); } - public void testChild1() throws Exception { - assertSemantics("vehiclebrand:skoda","audi cars",child1); - assertSemantics("vehiclebrand:alfa", "alfa bus",child1); - assertSemantics("AND vehiclebrand:bmw expensivetv","bmw motorcycle",child1); - assertSemantics("vehiclebrand:skoda","vw cars",child1); - assertSemantics("AND skoda car", "skoda cars",child1); + @Test + public void testChild1() { + assertSemantics("vehiclebrand:skoda", "audi cars", child1); + assertSemantics("vehiclebrand:alfa", "alfa bus", child1); + assertSemantics("AND vehiclebrand:bmw expensivetv", "bmw motorcycle", child1); + assertSemantics("vehiclebrand:skoda", "vw cars", child1); + assertSemantics("AND skoda car", "skoda cars", child1); } - public void testChild2() throws Exception { - assertSemantics("vehiclebrand:audi","audi cars",child2); - assertSemantics("vehiclebrand:alfa","alfa bus",child2); - assertSemantics("AND vehiclebrand:bmw expensivetv","bmw motorcycle",child2); - assertSemantics("AND vw car","vw cars",child2); - assertSemantics("vehiclebrand:skoda","skoda cars",child2); + @Test + public void testChild2() { + assertSemantics("vehiclebrand:audi","audi cars", child2); + assertSemantics("vehiclebrand:alfa","alfa bus", child2); + assertSemantics("AND vehiclebrand:bmw expensivetv","bmw motorcycle", child2); + assertSemantics("AND vw car","vw cars", child2); + assertSemantics("vehiclebrand:skoda","skoda cars", child2); } - public void testGrandchild() throws Exception { - assertSemantics("vehiclebrand:skoda","audi cars",grandchild); - assertSemantics("vehiclebrand:alfa","alfa bus",grandchild); - assertSemantics("AND vehiclebrand:bmw expensivetv","bmw motorcycle",grandchild); - assertSemantics("vehiclebrand:skoda","vw cars",grandchild); - assertSemantics("vehiclebrand:skoda","skoda cars",grandchild); + @Test + public void testGrandchild() { + assertSemantics("vehiclebrand:skoda","audi cars", grandchild); + assertSemantics("vehiclebrand:alfa","alfa bus", grandchild); + assertSemantics("AND vehiclebrand:bmw expensivetv","bmw motorcycle", grandchild); + assertSemantics("vehiclebrand:skoda","vw cars", grandchild); + assertSemantics("vehiclebrand:skoda","skoda cars", grandchild); } + @Test public void testRuleBaseNames() { - assertEquals("parent",parent.getName()); - assertEquals("child1",child1.getName()); - assertEquals("child2",child2.getName()); - assertEquals("grandchild",grandchild.getName()); + assertEquals("parent", parent.getName()); + assertEquals("child1", child1.getName()); + assertEquals("child2", child2.getName()); + assertEquals("grandchild", grandchild.getName()); } + @Test public void testSearcher() { assertSemantics("vehiclebrand:skoda","vw cars", ""); assertSemantics("vehiclebrand:skoda","vw cars", "&rules.rulebase=grandchild"); @@ -144,7 +161,7 @@ public class InheritanceTestCase extends junit.framework.TestCase { } protected void assertSemantics(String result,String input,String ruleSelection) { - Query query=new Query("?query=" + QueryTestCase.httpEncode(input) + "&tracelevel=0&tracelevel.rules=0" + ruleSelection); + Query query = new Query("?query=" + QueryTestCase.httpEncode(input) + "&tracelevel=0&tracelevel.rules=0" + ruleSelection); doSearch(searcher, query, 0,10); assertEquals(result, query.getModel().getQueryTree().getRoot().toString()); } @@ -156,7 +173,8 @@ public class InheritanceTestCase extends junit.framework.TestCase { } private Execution createExecution(Searcher searcher) { - Execution.Context context = new Execution.Context(null, null, null, new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); + Execution.Context context = new Execution.Context(null, null, null, + new RendererRegistry(MoreExecutors.directExecutor()), new SimpleLinguistics()); return new Execution(chainedAsSearchChain(searcher), context); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/LabelMatchingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/LabelMatchingTestCase.java index 635ca8cd6f9..1f98156c226 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/LabelMatchingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/LabelMatchingTestCase.java @@ -4,6 +4,7 @@ package com.yahoo.prelude.semantics.test; import java.io.IOException; import com.yahoo.prelude.semantics.parser.ParseException; +import org.junit.Test; /** * Tests label-dependent matching @@ -12,11 +13,12 @@ import com.yahoo.prelude.semantics.parser.ParseException; */ public class LabelMatchingTestCase extends RuleBaseAbstractTestCase { - public LabelMatchingTestCase(String name) { - super(name,"labelmatching.sr"); + public LabelMatchingTestCase() { + super("labelmatching.sr"); } /** Tests that matching with no label matches the default label (index) only */ + @Test public void testDefaultLabelMatching() throws IOException, ParseException { assertSemantics("matched:term","term"); assertSemantics("alabel:term","alabel:term"); @@ -25,10 +27,12 @@ public class LabelMatchingTestCase extends RuleBaseAbstractTestCase { assertSemantics("alabel:term2","alabel:term2"); } + @Test public void testSpecificLabelMatchingInConditionReference() throws IOException, ParseException { assertSemantics("+dcattitle:restaurants -dcat:hotel","dcattitle:restaurants"); } + @Test public void testSpecificlabelMatchingInNestedCondition() throws IOException, ParseException { assertSemantics("three","foo:one"); assertSemantics("three","foo:two"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchAllTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchAllTestCase.java index d2ff3b4b348..40927539a2f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchAllTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchAllTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * tersts the ellipsis rule base * @@ -8,16 +10,18 @@ package com.yahoo.prelude.semantics.test; */ public class MatchAllTestCase extends RuleBaseAbstractTestCase { - public MatchAllTestCase(String name) { - super(name,"matchall.sr"); + public MatchAllTestCase() { + super("matchall.sr"); } + @Test public void testMatchAll() { assertSemantics("RANK a normtitle:a","a"); assertSemantics("RANK (AND a b) normtitle:\"a b\"","a b"); assertSemantics("RANK (AND a a b a) normtitle:\"a a b a\"","a a b a"); } + @Test public void testMatchAllFilterIsIgnored() { assertSemantics("RANK a |b normtitle:a","a&filter=b"); assertSemantics("RANK (AND a b) |b |c normtitle:\"a b\"","a b&filter=b c"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchOnlyIfNotOnlyTermTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchOnlyIfNotOnlyTermTestCase.java index 5aad038d2e0..6fd7c78eee0 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchOnlyIfNotOnlyTermTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchOnlyIfNotOnlyTermTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * Experiments with a way to match only if it doesn't remove all hard conditions in the query. * The problem is that a straightforward use case of replacement leads to nonsensical queries as shown. @@ -9,15 +11,17 @@ package com.yahoo.prelude.semantics.test; */ public class MatchOnlyIfNotOnlyTermTestCase extends RuleBaseAbstractTestCase { - public MatchOnlyIfNotOnlyTermTestCase(String name) { - super(name,"match-only-if-not-only-term.sr"); + public MatchOnlyIfNotOnlyTermTestCase() { + super("match-only-if-not-only-term.sr"); } + @Test public void testMatch() { - assertSemantics("RANK (AND justin timberlake) showname:\"saturday night live\"!1000","justin timberlake snl"); - assertSemantics("RANK (AND justin timberlake) showname:\"saturday night live\"!1000","justin timberlake saturday night live"); + assertSemantics("RANK (AND justin timberlake) showname:\"saturday night live\"!1000", "justin timberlake snl"); + assertSemantics("RANK (AND justin timberlake) showname:\"saturday night live\"!1000", "justin timberlake saturday night live"); } + @Test public void testNoMatch() { // TODO: This shows that we do match, i.e that currently the behavior is undesired assertSemantics("showname:\"saturday night live\"!1000", "snl"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NoStemmingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NoStemmingTestCase.java index 970a3246328..be19140cc97 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NoStemmingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NoStemmingTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * Tests a case reported by tularam * @@ -8,21 +10,24 @@ package com.yahoo.prelude.semantics.test; */ public class NoStemmingTestCase extends RuleBaseAbstractTestCase { - public NoStemmingTestCase(String name) { - super(name,"nostemming.sr"); + public NoStemmingTestCase() { + super("nostemming.sr"); } /** Should rewrite correctly */ + @Test public void testCorrectRewriting1() { assertSemantics("+(AND i:arts i:sciences) -i:b","i:as -i:b"); } /** Should rewrite correctly too */ + @Test public void testCorrectRewriting2() { assertSemantics("+(AND i:arts i:sciences i:crafts) -i:b","i:asc -i:b"); } /** Should not rewrite */ + @Test public void testNoRewriting() { assertSemantics("+i:a -i:s","i:a -i:s"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NotTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NotTestCase.java index 06d880f65e2..ae46dfaf55e 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NotTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NotTestCase.java @@ -1,15 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * @author bratseth */ public class NotTestCase extends RuleBaseAbstractTestCase { - public NotTestCase(String name) { - super(name,"not.sr"); + public NotTestCase() { + super("not.sr"); } + @Test public void testLiteralEquals() { assertSemantics("RANK a foo:a","a"); assertSemantics("a","a&ranking=category"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumbersTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumbersTestCase.java index 428f84974f2..d2b3e2443c9 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumbersTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumbersTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * Tests numbers as conditions and productions * @@ -8,10 +10,11 @@ package com.yahoo.prelude.semantics.test; */ public class NumbersTestCase extends RuleBaseAbstractTestCase { - public NumbersTestCase(String name) { - super(name,"numbers.sr"); + public NumbersTestCase() { + super("numbers.sr"); } + @Test public void testNumbers() { assertSemantics("elite","1337"); assertSemantics("1","one"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumericTermsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumericTermsTestCase.java index e0bfc596d67..65c10608658 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumericTermsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/NumericTermsTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * Tests numeric terms * @@ -8,14 +10,16 @@ package com.yahoo.prelude.semantics.test; */ public class NumericTermsTestCase extends RuleBaseAbstractTestCase { - public NumericTermsTestCase(String name) { - super(name,"numericterms.sr"); + public NumericTermsTestCase() { + super("numericterms.sr"); } + @Test public void testNumericProduction() { assertSemantics("+restaurants -ycat2gc:96929265","restaurants"); } + @Test public void testNumericConditionAndProduction() { assertSemantics("48","49"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/OrPhraseTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/OrPhraseTestCase.java index 3a2a7e0af51..dcd52c2735b 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/OrPhraseTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/OrPhraseTestCase.java @@ -1,20 +1,24 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * @author bratseth */ public class OrPhraseTestCase extends RuleBaseAbstractTestCase { - public OrPhraseTestCase(String name) { - super(name,"orphrase.sr"); + public OrPhraseTestCase() { + super("orphrase.sr"); } + @Test public void testReplacing1() { assertSemantics("OR (AND new york) title:\"software engineer\"","software engineer new york"); assertSemantics("title:\"software engineer\"","software engineer"); // Skip or when there is nothing else } + @Test public void testReplacing2() { assertSemantics("OR lotr \"lord of the rings\"","lotr"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/Parameter2TestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/Parameter2TestCase.java index 212f650fb82..4695e048a3b 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/Parameter2TestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/Parameter2TestCase.java @@ -2,6 +2,9 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests parameter matching and production @@ -10,11 +13,12 @@ import com.yahoo.search.Query; */ public class Parameter2TestCase extends RuleBaseAbstractTestCase { - public Parameter2TestCase(String name) { - super(name,"parameter2.sr"); + public Parameter2TestCase() { + super("parameter2.sr"); } /** Tests parameter production */ + @Test public void testParameterProduction() { assertRankParameterSemantics("a","a&ranking=usrank","date",0); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ParameterTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ParameterTestCase.java index 00ef143e8f9..05e6eb226db 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ParameterTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ParameterTestCase.java @@ -2,6 +2,9 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests parameter matching and production @@ -10,11 +13,12 @@ import com.yahoo.search.Query; */ public class ParameterTestCase extends RuleBaseAbstractTestCase { - public ParameterTestCase(String name) { - super(name,"parameter.sr"); + public ParameterTestCase() { + super("parameter.sr"); } /** Tests parameter literal matching */ + @Test public void testLiteralEquals() { assertSemantics("a","a"); assertSemantics("RANK a foo:a","a&ranking=category"); @@ -23,6 +27,7 @@ public class ParameterTestCase extends RuleBaseAbstractTestCase { } /** Tests parameter matching of larger */ + @Test public void testLarger() { assertSemantics("a","a"); assertSemantics("AND a largepage","a&hits=11"); @@ -30,6 +35,7 @@ public class ParameterTestCase extends RuleBaseAbstractTestCase { } /** Tests parameter containment matching */ + @Test public void testContainsAsList() { assertSemantics("a","a"); assertSemantics("AND a intent:music","a&search=music"); @@ -38,6 +44,7 @@ public class ParameterTestCase extends RuleBaseAbstractTestCase { } /** Tests parameter production */ + @Test public void testParameterProduction() { assertParameterSemantics("AND a b c","a b c","search","[letters, alphabet]"); assertParameterSemantics("AND a c d","a c d","search","[letters, someletters]"); @@ -46,6 +53,7 @@ public class ParameterTestCase extends RuleBaseAbstractTestCase { assertParameterSemantics("AND a f g","a f g","grouping.nolearning","true"); } + @Test public void testMultipleAlternativeParameterValuesInCondition() { assertInputRankParameterSemantics("one","foo","cat"); assertInputRankParameterSemantics("one","foo","cat0"); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/PhraseMatchTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/PhraseMatchTestCase.java index 36214e13eab..41f67ed16fc 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/PhraseMatchTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/PhraseMatchTestCase.java @@ -1,6 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Ignore; +import org.junit.Test; + /** * Tests that the phrase produced by an automata match can subsequently be replaced by an AND of the * same terms. @@ -9,12 +12,13 @@ package com.yahoo.prelude.semantics.test; */ public class PhraseMatchTestCase extends RuleBaseAbstractTestCase { - public PhraseMatchTestCase(String name) { - super(name,"phrasematch.sr","semantics.fsa"); + public PhraseMatchTestCase() { + super("phrasematch.sr", "semantics.fsa"); } + @Test + @Ignore // TODO: Work in progress public void testLiteralEquals() { - if (1==1) return; // TODO: Work in progress assertSemantics("AND retailer:digital retailer:camera","keyword:digital keyword:camera"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java index 69f06cd912a..3513904af02 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java @@ -13,40 +13,41 @@ import com.yahoo.prelude.semantics.rule.ReferenceTermProduction; import com.yahoo.prelude.semantics.rule.ReplacingProductionRule; import com.yahoo.prelude.semantics.rule.TermCondition; import com.yahoo.prelude.semantics.rule.TermProduction; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author bratseth */ -public class ProductionRuleTestCase extends junit.framework.TestCase { - - public ProductionRuleTestCase(String name) { - super(name); - } +public class ProductionRuleTestCase { + @Test public void testProductionRule() { - TermCondition term=new TermCondition("sony"); - NamedCondition named=new NamedCondition("brand",term); - ConditionReference reference=new ConditionReference("brand"); + TermCondition term = new TermCondition("sony"); + NamedCondition named = new NamedCondition("brand", term); + ConditionReference reference = new ConditionReference("brand"); - TermProduction termProduction =new ReferenceTermProduction("brand","brand"); - ProductionList productionList =new ProductionList(); + TermProduction termProduction = new ReferenceTermProduction("brand", "brand"); + ProductionList productionList = new ProductionList(); productionList.addProduction(termProduction); - ProductionRule rule=new ReplacingProductionRule(); + ProductionRule rule = new ReplacingProductionRule(); rule.setCondition(reference); rule.setProduction(productionList); // To initialize the condition reference... - RuleBase ruleBase=new RuleBase(); + RuleBase ruleBase = new RuleBase(); ruleBase.setName("test"); ruleBase.addCondition(named); ruleBase.addRule(rule); ruleBase.initialize(); - assertTrue("Brand is referenced",rule.matchReferences().contains("brand")); + assertTrue("Brand is referenced", rule.matchReferences().contains("brand")); - Query query=new Query("?query=sony"); - RuleEvaluation e=new Evaluation(query).freshRuleEvaluation(); + Query query = new Query("?query=sony"); + RuleEvaluation e = new Evaluation(query).freshRuleEvaluation(); assertTrue(rule.matches(e)); rule.produce(e); assertEquals("brand:sony", query.getModel().getQueryTree().getRoot().toString()); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java index 1be6792ac8c..41597a22832 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.prelude.semantics.test; import com.google.common.util.concurrent.MoreExecutors; import com.yahoo.component.chain.Chain; -import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.search.Query; import com.yahoo.prelude.semantics.RuleBase; @@ -16,7 +15,8 @@ import com.yahoo.search.test.QueryTestCase; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Executors; + +import static org.junit.Assert.assertEquals; /** * Tests semantic searching @@ -24,28 +24,24 @@ import java.util.concurrent.Executors; * @author bratseth */ @SuppressWarnings("deprecation") -public abstract class RuleBaseAbstractTestCase extends junit.framework.TestCase { +public abstract class RuleBaseAbstractTestCase { - protected final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; + protected final String root = "src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; protected final SemanticSearcher searcher; - protected RuleBaseAbstractTestCase(String name,String ruleBaseName) { - this(name,ruleBaseName,null); - } - - protected RuleBaseAbstractTestCase(String name,String ruleBaseName,String automataFileName) { - super(name); - searcher = createSearcher(ruleBaseName,automataFileName); + protected RuleBaseAbstractTestCase(String ruleBaseName) { + this(ruleBaseName, null); } - public void setUp() { + protected RuleBaseAbstractTestCase(String ruleBaseName, String automataFileName) { + searcher = createSearcher(ruleBaseName, automataFileName); } protected SemanticSearcher createSearcher(String ruleBaseName,String automataFileName) { try { - if (automataFileName!=null) - automataFileName=root + automataFileName; - RuleBase ruleBase = RuleBase.createFromFile(root + ruleBaseName,automataFileName); + if (automataFileName != null) + automataFileName = root + automataFileName; + RuleBase ruleBase = RuleBase.createFromFile(root + ruleBaseName, automataFileName); return new SemanticSearcher(ruleBase); } catch (Exception e) { throw new RuleBaseException("Initialization of rule base '" + ruleBaseName + "' failed",e); @@ -67,7 +63,6 @@ public abstract class RuleBaseAbstractTestCase extends junit.framework.TestCase } protected Query assertSemantics(String result, Query query) { - System.out.println(query.getModel().getQueryTree()); createExecution(searcher).search(query); assertEquals(result, query.getModel().getQueryTree().getRoot().toString()); return query; diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SegmentSubstitutionTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SegmentSubstitutionTestCase.java index 439bc1314f6..b8db5e4d90f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SegmentSubstitutionTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SegmentSubstitutionTestCase.java @@ -9,13 +9,15 @@ import com.yahoo.search.Query; import com.yahoo.search.query.parser.Parsable; import com.yahoo.search.query.parser.ParserEnvironment; import org.junit.Ignore; +import org.junit.Test; public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { - public SegmentSubstitutionTestCase(String name) { - super(name,"substitution.sr"); + public SegmentSubstitutionTestCase() { + super("substitution.sr"); } + @Test public void testBasicSubstitution() { Item a = parseQuery("firstsecond"); Query q = new Query("?query=ignored&tracelevel=0&tracelevel.rules=0"); @@ -24,6 +26,7 @@ public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { assertSemantics("\"first third\"", q); } + @Test public void testSubstitutionAndMoreTerms() { Item a = parseQuery("bcfirstsecondfg"); Query q = new Query("?query=ignored&tracelevel=0&tracelevel.rules=0"); @@ -32,6 +35,7 @@ public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { assertSemantics("\"bc first third fg\"", q); } + @Test public void testSubstitutionAndNot() { Item a = parseQuery("-firstsecond bc"); Query q = new Query("?query=ignored&tracelevel=0&tracelevel.rules=0"); @@ -40,6 +44,7 @@ public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { assertSemantics("+bc -\"first third\"", q); } + @Test public void testSubstitutionSomeNoise() { Item a = parseQuery("9270bcsecond2389"); Query q = new Query("?query=ignored&tracelevel=0&tracelevel.rules=0"); @@ -52,4 +57,5 @@ public class SegmentSubstitutionTestCase extends RuleBaseAbstractTestCase { AllParser parser = new AllParser(new ParserEnvironment().setLinguistics(TestLinguistics.INSTANCE)); return parser.parse(new Parsable().setQuery(query).setLanguage(Language.CHINESE_SIMPLIFIED)).getRoot(); } + } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java index a3779351a6d..b7754075724 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java @@ -12,10 +12,13 @@ import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; import java.util.ArrayList; import java.util.List; +import static org.junit.Assert.assertEquals; + /** * Tests semantic searching * @@ -24,49 +27,58 @@ import java.util.List; @SuppressWarnings("deprecation") public class SemanticSearcherTestCase extends RuleBaseAbstractTestCase { - public SemanticSearcherTestCase(String name) { - super(name,"rules.sr"); + public SemanticSearcherTestCase() { + super("rules.sr"); } + @Test public void testSingleShopping() { assertSemantics("brand:sony", "sony"); } + @Test public void testCombinedShopping() { assertSemantics("AND brand:sony category:camera", "sony camera"); } + @Test public void testPhrasedShopping() { assertSemantics("AND brand:sony category:\"digital camera\"", "sony digital camera"); } + @Test public void testSimpleLocal() { assertSemantics("AND listing:restaurant place:geary", "restaurant in geary"); } + @Test public void testLocal() { assertSemantics("AND listing:restaurant place:\"geary street san francisco\"", "restaurant in geary street san francisco"); } + @Test public void testLiteralReplacing() { assertSemantics("AND lord of rings","lotr"); } + @Test public void testAddingAnd() { assertSemantics("AND bar foobar:bar", "bar"); } + @Test public void testAddingRank() { assertSemantics("RANK word foobar:word", "word"); } + @Test public void testFilterIsIgnored() { assertSemantics("RANK word |a |word |b foobar:word", "word&filter=a word b"); @@ -74,62 +86,76 @@ public class SemanticSearcherTestCase extends RuleBaseAbstractTestCase { "a&filter=word b"); } + @Test public void testAddingNegative() { assertSemantics("+java -coffee", "java"); } + @Test public void testAddingNegativePluralToSingular() { assertSemantics("+javas -coffee", "javas"); } + @Test public void testCombined() { assertSemantics("AND bar listing:restaurant place:\"geary street san francisco\" foobar:bar", "bar restaurant in geary street san francisco"); } + @Test public void testStopWord() { assertSemantics("strokes","the strokes"); } + @Test public void testStopWords1() { assertSemantics("strokes","be the strokes"); } + @Test public void testStopWords2() { assertSemantics("strokes","the strokes be"); } + @Test public void testDontRemoveEverything() { assertSemantics("the","the the the"); } + @Test public void testMoreStopWordRemoval() { assertSemantics("hamlet","hamlet to be or not to be"); } + @Test public void testTypeChange() { assertSemantics("RANK doors default:typechange","typechange doors"); } + @Test public void testTypeChangeWithSingularToPluralButNonReplaceWillNotSingularify() { assertSemantics("RANK door default:typechange","typechange door"); } + @Test public void testExplicitContext() { assertSemantics("AND from:paris to:texas","paris to texas"); } + @Test public void testPluralReplaceBecomesSingular() { assertSemantics("AND from:paris to:texas","pariss to texass"); } + @Test public void testOrProduction() { assertSemantics("OR something somethingelse","something"); } - //This test is order dependent. Fix it!! + // This test is order dependent. Fix it!! + @Test public void testWeightedSetItem() { Query q = new Query(); WeightedSetItem weightedSet=new WeightedSetItem("fieldName"); @@ -139,6 +165,7 @@ public class SemanticSearcherTestCase extends RuleBaseAbstractTestCase { assertSemantics("WEIGHTEDSET fieldName{[1]:\"a\",[2]:\"b\"}",q); } + @Test public void testNullQuery() { Query query=new Query(""); // Causes a query containing a NullItem doSearch(searcher, query, 0, 10); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/StemmingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/StemmingTestCase.java index d68af2ab4a1..ec64690c574 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/StemmingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/StemmingTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * Tests a case reported by tularam * @@ -8,22 +10,26 @@ package com.yahoo.prelude.semantics.test; */ public class StemmingTestCase extends RuleBaseAbstractTestCase { - public StemmingTestCase(String name) { - super(name,"stemming.sr"); + public StemmingTestCase() { + super("stemming.sr"); } + @Test public void testRewritingDueToStemmingInQuery() { assertSemantics("+i:vehicle -i:s","i:cars -i:s"); } + @Test public void testRewritingDueToStemmingInRule() { assertSemantics("+i:animal -i:s","i:horse -i:s"); } + @Test public void testRewritingDueToExactMatch() { assertSemantics("+(AND i:arts i:sciences) -i:s","i:as -i:s"); } + @Test public void testNoRewritingBecauseShortWordsAreNotStemmed() { assertSemantics("+i:a -i:s","i:a -i:s"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/StopwordTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/StopwordTestCase.java index 57decbdbcd4..d2d87dccf33 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/StopwordTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/StopwordTestCase.java @@ -3,6 +3,7 @@ package com.yahoo.prelude.semantics.test; import com.yahoo.search.Query; import com.yahoo.search.test.QueryTestCase; +import org.junit.Test; /** * Tests numeric terms @@ -11,15 +12,17 @@ import com.yahoo.search.test.QueryTestCase; */ public class StopwordTestCase extends RuleBaseAbstractTestCase { - public StopwordTestCase(String name) { - super(name,"stopwords.sr"); + public StopwordTestCase() { + super("stopwords.sr"); } + @Test public void testStopwords() { assertSemantics("AND mlr:ve mlr:heard mlr:beautiful mlr:world", new Query(QueryTestCase.httpEncode("?query=i don't know if you've heard, but it's a beautiful world&default-index=mlr&tracelevel.rules=0"))); } + @Test public void testStopwordsInPhrase() { assertSemantics("AND mlr:\"ve heard\" mlr:beautiful mlr:world", new Query(QueryTestCase.httpEncode("?query=\"i don't know if you've heard\", but it's a beautiful world&default-index=mlr&tracelevel.rules=0"))); diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/UrlTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/UrlTestCase.java index 7f01dbf5750..2a563362928 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/UrlTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/UrlTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * Tests working with url indexes * @@ -8,10 +10,11 @@ package com.yahoo.prelude.semantics.test; */ public class UrlTestCase extends RuleBaseAbstractTestCase { - public UrlTestCase(String name) { - super(name,"url.sr"); + public UrlTestCase() { + super("url.sr"); } + @Test public void testFromDefaultToUrlIndex() { assertSemantics("fromurl:\"youtube com\"","youtube.com"); } diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/test/WeightingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/test/WeightingTestCase.java index 361ef0e9637..349a3502c0f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/test/WeightingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/semantics/test/WeightingTestCase.java @@ -1,15 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.semantics.test; +import org.junit.Test; + /** * @author bratseth */ public class WeightingTestCase extends RuleBaseAbstractTestCase { - public WeightingTestCase(String name) { - super(name,"weighting.sr"); + public WeightingTestCase() { + super("weighting.sr"); } + @Test public void testWeighting() { assertSemantics("foo!150","foo"); assertSemantics("AND foo!150 snip","foo snip"); diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/GroupedResultTestCase.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/GroupedResultTestCase.java index a29ffdb49b9..07d5dcc9e2d 100644 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/GroupedResultTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/templates/test/GroupedResultTestCase.java @@ -5,18 +5,18 @@ import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests composition of grouped results using the HitGroup class * * @author bratseth */ -public class GroupedResultTestCase extends junit.framework.TestCase { - - public GroupedResultTestCase(String name) { - super(name); - } +public class GroupedResultTestCase { + @Test public void testGroupedResult() { Result result=new Result(new Query("?query=foo")); HitGroup hitGroup1=new HitGroup("group1",300); diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/TemplateTestCase.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/TemplateTestCase.java index 49b1846fba5..6f49ebbdee0 100644 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/TemplateTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/templates/test/TemplateTestCase.java @@ -1,29 +1,31 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.templates.test; - import java.io.ByteArrayOutputStream; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import com.yahoo.io.ByteWriter; import com.yahoo.prelude.templates.UserTemplate; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** - * @author <a href="mailt:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class TemplateTestCase extends junit.framework.TestCase { +public class TemplateTestCase { private CharsetEncoder encoder; private ByteArrayOutputStream stream; - public TemplateTestCase (String name) { - super(name); + public TemplateTestCase () { Charset cs = Charset.forName("UTF-8"); encoder = cs.newEncoder(); stream = new ByteArrayOutputStream(); } + @Test public void testASCIIQuoting() throws java.io.IOException { stream.reset(); byte[] c = new byte[] { 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }; @@ -36,6 +38,7 @@ public class TemplateTestCase extends junit.framework.TestCase { } + @Test public void testXMLQuoting() throws java.io.IOException { stream.reset(); // c = <s>> diff --git a/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java b/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java index 6ec17565668..f86d76a12a4 100644 --- a/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java @@ -17,6 +17,7 @@ import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.File; @@ -25,6 +26,9 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Tests representing a federated and grouped result as a Result object and * rendering a tiled output of the result @@ -32,18 +36,13 @@ import java.nio.charset.CharsetDecoder; * @author bratseth */ @SuppressWarnings("deprecation") -public class TilingTestCase extends junit.framework.TestCase { - - public TilingTestCase(String name) { - super(name); - } +public class TilingTestCase { /** * This result contains two blocks (center and right). * The center block contains multiple subblocks while the right one contains a single block of ads. - * <p> - * Incidentally, this also tests using an old searcher in new search chains. */ + @Test public void testTiling() throws IOException { Chain<Searcher> chain=new Chain<>("tiling", new TiledResultProducer()); @@ -55,9 +54,8 @@ public class TilingTestCase extends junit.framework.TestCase { /** * This result contains center section and meta blocks. - * <p> - * Incidentally, this also tests using an old searcher in new search chains. */ + @Test public void testTiling2() throws IOException { Chain<Searcher> chain= new Chain<>("tiling", new TiledResultProducer2()); @@ -113,8 +111,8 @@ public class TilingTestCase extends junit.framework.TestCase { private static class TiledResultProducer extends Searcher { @Override - public Result search(Query query,Execution execution) { - Result result=new Result(query); + public Result search(Query query, Execution execution) { + Result result = new Result(query); result.setTotalHitCount(2800000000l); // Blocks @@ -307,4 +305,5 @@ public class TilingTestCase extends junit.framework.TestCase { } } + } diff --git a/container-search/src/test/java/com/yahoo/prelude/test/IntegrationTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/IntegrationTestCase.java index 8fb9a8047a1..9fed5e1fa3e 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/IntegrationTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/IntegrationTestCase.java @@ -5,6 +5,7 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; /** * Runs a query thru the configured search chain from a real http channel @@ -13,11 +14,7 @@ import com.yahoo.search.searchchain.Execution; * * @author bratseth */ -public class IntegrationTestCase extends junit.framework.TestCase { - - public IntegrationTestCase (String name) { - super(name); - } +public class IntegrationTestCase { public static class SecondSearcher extends Searcher { public Result search(com.yahoo.search.Query query, Execution execution) { @@ -34,6 +31,7 @@ public class IntegrationTestCase extends junit.framework.TestCase { } } + @Test public void testQuery() throws java.io.IOException { /* TODO: (JSB) This blocks forever on Linux (not Windows) because diff --git a/container-search/src/test/java/com/yahoo/prelude/test/LocationTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/LocationTestCase.java index cbb62b5d555..9ede1bca8ce 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/LocationTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/LocationTestCase.java @@ -2,18 +2,18 @@ package com.yahoo.prelude.test; import com.yahoo.prelude.Location; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests the Location class. Currently does not test all "features" of Location class. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M. R. Rosenvinge</a> + * @author Einar M. R. Rosenvinge */ -public class LocationTestCase extends junit.framework.TestCase { - - public LocationTestCase (String name) { - super(name); - } +public class LocationTestCase { + @Test public void testAspect() { //0 degrees latitude, on the equator Location loc1 = new Location("[2,-1110000,330000,-1160000,340000](2,-1100222,0,300,0,1,0,CalcLatLon)"); diff --git a/container-search/src/test/java/com/yahoo/prelude/test/NullSetMemberTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/NullSetMemberTestCase.java index 2b0cd026987..f66acb2bdc0 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/NullSetMemberTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/NullSetMemberTestCase.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.test; +import org.junit.Test; + import java.util.HashSet; /** @@ -8,16 +10,14 @@ import java.util.HashSet; */ public class NullSetMemberTestCase extends junit.framework.TestCase { - public NullSetMemberTestCase (String name) { - super(name); - } - + @Test public void testNullMember() { - HashSet<?> s = new HashSet<Object>(); + HashSet<?> s = new HashSet<>(); assertEquals(s.size(), 0); assertFalse(s.contains(null)); s.add(null); assertEquals(s.size(), 1); assertTrue(s.contains(null)); } + } diff --git a/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java index 37ee41d4864..3e57c48e7f3 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java @@ -17,6 +17,9 @@ import com.yahoo.search.Result; import com.yahoo.prelude.fastsearch.FastHit; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; /** * Tests that rank features are rendered when requested in the query @@ -24,11 +27,12 @@ import com.yahoo.search.searchchain.Execution; * @author bratseth */ @SuppressWarnings("deprecation") -public class RankFeatureDumpTestCase extends junit.framework.TestCase { +public class RankFeatureDumpTestCase { private static final String rankFeatureString= "{\"match.weight.as1\":10,\"attribute(ai1)\":1.000000,\"proximity(as1, 1, 2)\":2.000000}"; + @Test public void test() throws IOException { Query query=new Query("?query=five&rankfeatures"); assertTrue(query.getRanking().getListFeatures()); // New api diff --git a/container-search/src/test/java/com/yahoo/prelude/test/ResultTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/ResultTestCase.java index ccf54aa7f24..24ce9c9b7b7 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/ResultTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/ResultTestCase.java @@ -6,19 +6,18 @@ import java.util.Iterator; import com.yahoo.search.Query; import com.yahoo.search.result.Hit; import com.yahoo.search.Result; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests the result class * * @author bratseth */ -public class ResultTestCase extends junit.framework.TestCase { - - public ResultTestCase (String name) { - super(name); - - } +public class ResultTestCase { + @Test public void testHitOrdering() { Result result=new Result(new Query("dummy")); result.hits().add(new Hit("test:hit1",80)); @@ -43,6 +42,7 @@ public class ResultTestCase extends junit.framework.TestCase { result.hits().add(new Hit("test:hit9",75)); } + @Test public void testHitTrimming(){ Result result=new Result(new Query("dummy")); @@ -87,7 +87,6 @@ public class ResultTestCase extends junit.framework.TestCase { assertEquals(false,hits.hasNext()); } - //This test is broken /* public void testNavigationalLinks() { |