summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-04-13 22:18:11 +0200
committerJon Bratseth <bratseth@oath.com>2018-04-13 22:18:11 +0200
commit8c54be83e36fa4ba28c747fec2b8040832002b49 (patch)
treec63d75c05930352205e46fd405b2ddc5272dcd1f
parent41969051757a99e5c8ed09fac31fa0658f039c7c (diff)
Remove usage of old junit
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/searcher/test/QuerySnapshotSearcherTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/searcher/test/QueryValidatingSearcherTestCase.java14
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/searcher/test/QuotingSearcherTestCase.java17
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/AlibabaTestCase.java10
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/AnchorTestCase.java27
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataNotTestCase.java15
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/AutomataTestCase.java27
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/BacktrackingTestCase.java34
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/BlendingTestCase.java15
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/CJKTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonTestCase.java9
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/ComparisonsTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/ConditionTestCase.java56
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/ConfigurationTestCase.java24
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/DuplicateRuleTestCase.java11
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/Ellipsis2TestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/EllipsisTestCase.java10
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/ExactMatchTrickTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/InheritanceTestCase.java134
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/LabelMatchingTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchAllTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/MatchOnlyIfNotOnlyTermTestCase.java12
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/NoStemmingTestCase.java9
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/NotTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/NumbersTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/NumericTermsTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/OrPhraseTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/Parameter2TestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/ParameterTestCase.java12
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/PhraseMatchTestCase.java10
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/ProductionRuleTestCase.java31
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/RuleBaseAbstractTestCase.java27
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/SegmentSubstitutionTestCase.java10
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/SemanticSearcherTestCase.java33
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/StemmingTestCase.java10
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/StopwordTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/UrlTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/semantics/test/WeightingTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/templates/test/GroupedResultTestCase.java10
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/templates/test/TemplateTestCase.java13
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/templates/test/TilingTestCase.java21
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/test/IntegrationTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/test/LocationTestCase.java12
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/test/NullSetMemberTestCase.java10
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/test/RankFeatureDumpTestCase.java6
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/test/ResultTestCase.java13
-rw-r--r--container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java9
-rw-r--r--container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/FederationResultTest.java3
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java13
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java16
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java5
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java2
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java4
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java19
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java13
-rw-r--r--container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java23
-rw-r--r--container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/MapPageTemplateXMLReadingTestCase.java13
-rw-r--r--container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/PageTemplateXMLReadingTestCase.java11
-rw-r--r--container-search/src/test/java/com/yahoo/search/pagetemplates/test/PageTemplateSearcherTestCase.java11
-rw-r--r--container-search/src/test/java/com/yahoo/search/pagetemplates/test/SourceParametersTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/context/test/LoggingTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/context/test/PropertiesTestCase.java9
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/context/test/TraceTestCase.java13
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/MultiProfileTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java10
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/CloningTestCase.java15
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java13
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/QueryFromProfileTestCase.java8
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java64
73 files changed, 721 insertions, 368 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>&gt;
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() {
diff --git a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java
index 00202e433e3..2992d8ab896 100644
--- a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java
@@ -4,8 +4,6 @@ package com.yahoo.search.cluster.test;
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
-
import com.yahoo.component.ComponentId;
import com.yahoo.prelude.Ping;
import com.yahoo.prelude.Pong;
@@ -18,10 +16,11 @@ import com.yahoo.search.cluster.PingableSearcher;
import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.result.Hit;
import com.yahoo.search.searchchain.Execution;
+import org.junit.Test;
-// TODO: Author!
-public class ClusterSearcherTestCase extends TestCase {
+import static org.junit.Assert.assertEquals;
+public class ClusterSearcherTestCase {
class TestingBackendSearcher extends PingableSearcher {
@@ -145,7 +144,7 @@ public class ClusterSearcherTestCase extends TestCase {
}
-
+ @Test
public void testSimple() {
Hit blockingHit = new Hit("blocking");
Hit nonblockingHit = new Hit("nonblocking");
diff --git a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java
index 4c3ed56cd44..a565c171b98 100644
--- a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java
@@ -11,16 +11,21 @@ import com.yahoo.search.cluster.ClusterSearcher;
import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.result.Hit;
import com.yahoo.search.searchchain.Execution;
+import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
/**
* @author bratseth
*/
-public class ClusteredConnectionTestCase extends junit.framework.TestCase {
+public class ClusteredConnectionTestCase {
+ @Test
public void testClustering() {
Connection connection0=new Connection("0");
Connection connection1=new Connection("1");
@@ -88,6 +93,7 @@ public class ClusteredConnectionTestCase extends junit.framework.TestCase {
assertEquals("from:0",r.hits().get(0).getId().stringValue());
}
+ @Test
public void testClusteringWithPing() {
Connection connection0=new Connection("0");
Connection connection1=new Connection("1");
diff --git a/container-search/src/test/java/com/yahoo/search/federation/FederationResultTest.java b/container-search/src/test/java/com/yahoo/search/federation/FederationResultTest.java
index b0087a173f8..a1e85a454fb 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/FederationResultTest.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/FederationResultTest.java
@@ -13,14 +13,13 @@ import com.yahoo.search.searchchain.model.federation.FederationOptions;
import com.yahoo.test.ManualClock;
import org.junit.Test;
-import java.time.Clock;
import java.time.Duration;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author bratseth
diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java
index 6b9b36800e5..b4f3c13b8e2 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java
@@ -10,6 +10,9 @@ import com.yahoo.search.result.HitGroup;
import com.yahoo.search.searchchain.Execution;
import com.yahoo.statistics.Statistics;
import com.yahoo.text.Utf8;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import javax.xml.bind.JAXBException;
import java.io.IOException;
@@ -19,16 +22,19 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import static org.junit.Assert.assertEquals;
+
/**
* Rudimentary http searcher test.
*
* @author bratseth
*/
-public class HttpTestCase extends junit.framework.TestCase {
+public class HttpTestCase {
private StupidSingleThreadedHttpServer httpServer;
private TestHTTPClientSearcher searcher;
+ @Test
public void testSearcher() throws JAXBException {
Result result = searchUsingLocalhost();
@@ -44,6 +50,7 @@ public class HttpTestCase extends junit.framework.TestCase {
return searcher.search(query, new Execution(searcher, Execution.Context.createContextStub()));
}
+ @Test
public void test_that_ip_address_set_on_meta_hit() {
Result result = searchUsingLocalhost();
Hit metaHit = getFirstMetaHit(result.hits());
@@ -61,7 +68,7 @@ public class HttpTestCase extends junit.framework.TestCase {
return null;
}
- @Override
+ @Before
public void setUp() throws Exception {
httpServer = new StupidSingleThreadedHttpServer(0, 0) {
@Override
@@ -81,7 +88,7 @@ public class HttpTestCase extends junit.framework.TestCase {
return httpServer.getServerPort();
}
- @Override
+ @After
public void tearDown() throws Exception {
httpServer.stop();
if (searcher != null) {
diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java
index 75110ce1161..8c1ff69666b 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java
@@ -13,6 +13,7 @@ import com.yahoo.statistics.Statistics;
import com.yahoo.text.Utf8;
import com.yahoo.yolean.Exceptions;
import org.apache.http.HttpEntity;
+import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
@@ -24,14 +25,20 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
* Check for different keep-alive scenarios. What we really want to test
* is the server does not hang.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
-public class PingTestCase extends junit.framework.TestCase {
- static final int TIMEOUT_MS = 60000;
+public class PingTestCase {
+
+ private static final int TIMEOUT_MS = 60000;
+
+ @Test
public void testNiceCase() throws Exception {
NiceStupidServer server = new NiceStupidServer();
server.start();
@@ -82,6 +89,7 @@ public class PingTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testUselessCase() throws Exception {
UselessStupidServer server = new UselessStupidServer();
server.start();
@@ -89,6 +97,7 @@ public class PingTestCase extends junit.framework.TestCase {
server.stop();
}
+ @Test
public void testGrumpyCase() throws Exception {
GrumpyStupidServer server = new GrumpyStupidServer();
server.start();
@@ -96,6 +105,7 @@ public class PingTestCase extends junit.framework.TestCase {
server.stop();
}
+ @Test
public void testPassiveAggressiveCase() throws Exception {
PassiveAggressiveStupidServer server = new PassiveAggressiveStupidServer();
server.start();
diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java
index 6efa6692574..19750cf84cc 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java
@@ -4,22 +4,24 @@ package com.yahoo.search.federation.http;
import com.yahoo.component.ComponentId;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
-import com.yahoo.search.federation.vespa.VespaSearcher;
import com.yahoo.search.searchchain.Execution;
import com.yahoo.statistics.Statistics;
import com.yahoo.vespa.defaults.Defaults;
+import org.junit.Test;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
+import static org.junit.Assert.assertEquals;
+
/**
* Tests that source and backend specific parameters from the query are added correctly to the backend requests
*
* @author bratseth
*/
-public class QueryParametersTestCase extends junit.framework.TestCase {
+public class QueryParametersTestCase {
+ @Test
public void testQueryParameters() {
Query query=new Query();
query.properties().set("a","a-value");
diff --git a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java
index 3df5151de0b..4485a016ee6 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SearchChainResolverTestCase.java
@@ -16,10 +16,10 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.SortedSet;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.fail;
import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
/**
* @author tonytv
@@ -149,4 +149,5 @@ public class SearchChainResolverTestCase {
assertThat(res.federationOptions, is(federationOptions));
return res;
}
+
}
diff --git a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java
index de468a2be2d..714d1803605 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/sourceref/test/SourceRefResolverTestCase.java
@@ -20,9 +20,9 @@ import java.util.Set;
import java.util.TreeMap;
import static com.yahoo.search.federation.sourceref.test.SearchChainResolverTestCase.emptySourceToProviderMap;
-import static junit.framework.Assert.fail;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
import static org.junit.matchers.JUnitMatchers.hasItems;
diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java
index 2f7ea531f13..8d1ecf4085e 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java
@@ -5,12 +5,14 @@ import com.yahoo.search.Query;
import com.yahoo.search.federation.vespa.VespaSearcher;
import java.util.Map;
+import static org.junit.Assert.assertEquals;
+
/**
* Tests that source and backend specific parameters from the query are added correctly to the backend requests
*
* @author bratseth
*/
-public class QueryParametersTestCase extends junit.framework.TestCase {
+public class QueryParametersTestCase {
public void testQueryParameters() {
Query query=new Query();
diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java
index 8edab711a93..494e3f06a61 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java
@@ -3,8 +3,6 @@ package com.yahoo.search.federation.vespa.test;
import java.util.Iterator;
-import junit.framework.TestCase;
-
import com.yahoo.net.URI;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
@@ -12,18 +10,19 @@ import com.yahoo.search.federation.vespa.ResultBuilder;
import com.yahoo.search.result.ErrorHit;
import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.result.HitGroup;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
/**
* Test XML parsing of results.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
@SuppressWarnings("deprecation")
-public class ResultBuilderTestCase extends TestCase {
-
- public ResultBuilderTestCase (String name) {
- super(name);
- }
+public class ResultBuilderTestCase {
private boolean quickCompare(double a, double b) {
double z = Math.min(Math.abs(a), Math.abs(b));
@@ -34,6 +33,7 @@ public class ResultBuilderTestCase extends TestCase {
}
}
+ @Test
public void testSimpleResult() {
boolean gotErrorDetails = false;
ResultBuilder r = new ResultBuilder();
@@ -62,6 +62,7 @@ public class ResultBuilderTestCase extends TestCase {
+ "<x><y><z /></y></x>", res.hits().get(3).getField("annoying").toString());
}
+ @Test
public void testNestedResult() {
ResultBuilder r = new ResultBuilder();
Result res = r.parse("file:src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml", new Query("?query=a"));
@@ -79,6 +80,7 @@ public class ResultBuilderTestCase extends TestCase {
assertEquals("badge/Topic Explorer 5", g3.get(0).getField("name").toString());
}
+ @Test
public void testWeirdDocumentID() {
ResultBuilder r = new ResultBuilder();
Result res = r.parse("file:src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml", new Query("?query=a"));
@@ -88,4 +90,5 @@ public class ResultBuilderTestCase extends TestCase {
assertEquals(new URI("tralle"), res.hits().get(1).getId());
assertEquals(new URI("kalle"), res.hits().get(2).getId());
}
+
}
diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java
index 4ca41f9aa8b..7fbe883bfb7 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java
@@ -7,19 +7,22 @@ import com.yahoo.search.Result;
import com.yahoo.search.Searcher;
import com.yahoo.search.federation.vespa.VespaSearcher;
import com.yahoo.search.searchchain.Execution;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* @author bratseth
*/
-@SuppressWarnings("deprecation")
-public class VespaIntegrationTestCase extends junit.framework.TestCase {
+public class VespaIntegrationTestCase {
// TODO: Setup the answering vespa searcher from this test....
+ @Test
public void testIt() {
if (System.currentTimeMillis() > 0) return;
- Chain<Searcher> chain=new Chain<>(new VespaSearcher("test","example.yahoo.com",19010,""));
- Result result=new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=test"));
- assertEquals(23,result.hits().size());
+ Chain<Searcher> chain = new Chain<>(new VespaSearcher("test","example.yahoo.com",19010,""));
+ Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=test"));
+ assertEquals(23, result.hits().size());
}
}
diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java
index 8156232f4a4..2db949b8317 100644
--- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java
@@ -11,30 +11,36 @@ import com.yahoo.search.query.parser.ParserEnvironment;
import com.yahoo.search.query.parser.ParserFactory;
import com.yahoo.search.result.Hit;
import com.yahoo.search.searchchain.Execution;
-import junit.framework.TestCase;
import org.apache.http.HttpEntity;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.IOException;
import java.net.URI;
+import static org.junit.Assert.assertEquals;
+
/**
* Check query marshaling in VespaSearcher works.
*
* @author Steinar Knutsen
*/
-public class VespaSearcherTestCase extends TestCase {
-
- // TODO: More tests
+public class VespaSearcherTestCase {
private VespaSearcher searcher;
- protected @Override void setUp() {
+ @Before
+ protected void setUp() {
searcher = new VespaSearcher("cache1","",0,"");
}
- protected @Override void tearDown() {
+ @After
+ protected void tearDown() {
searcher.deconstruct();
}
+ @Test
public void testMarshalQuery() {
RankItem root = new RankItem();
QueryTree r = new QueryTree(root);
@@ -59,6 +65,7 @@ public class VespaSearcherTestCase extends TestCase {
assertEquals("( \"new york\" AND shoes AND silly ) RANK nike RANK adidas RANK \"bloody expensive\"", searcher.marshalQuery(r));
}
+ @Test
public void testMarshalQuerySmallTree() {
RankItem root = new RankItem();
QueryTree r = new QueryTree(root);
@@ -83,6 +90,7 @@ public class VespaSearcherTestCase extends TestCase {
// assertMarshals(root)
}
+ @Test
public void testWandMarshalling() {
WeakAndItem root = new WeakAndItem();
root.setN(32);
@@ -92,6 +100,7 @@ public class VespaSearcherTestCase extends TestCase {
assertMarshals(root);
}
+ @Test
public void testWandMarshalling2() {
// AND (WAND(10) a!1 the!10) source:yahoonews
AndItem root = new AndItem();
@@ -121,6 +130,7 @@ public class VespaSearcherTestCase extends TestCase {
return parser.parse(new Parsable().setQuery(query).setFilter(filter));
}
+ @Test
public void testSourceProviderProperties() throws Exception {
/* TODO: update test
Server httpServer = new Server();
@@ -163,6 +173,7 @@ public class VespaSearcherTestCase extends TestCase {
*/
}
+ @Test
public void testVespaSearcher() {
VespaSearcher v=new VespaSearcherValidatingSubclass();
new Execution(v, Execution.Context.createContextStub()).search(new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&filter=myfilter")));
diff --git a/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/MapPageTemplateXMLReadingTestCase.java b/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/MapPageTemplateXMLReadingTestCase.java
index 8d31814f82a..51f87538aa5 100644
--- a/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/MapPageTemplateXMLReadingTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/MapPageTemplateXMLReadingTestCase.java
@@ -4,17 +4,26 @@ package com.yahoo.search.pagetemplates.config.test;
import com.yahoo.search.pagetemplates.PageTemplate;
import com.yahoo.search.pagetemplates.PageTemplateRegistry;
import com.yahoo.search.pagetemplates.config.PageTemplateXMLReader;
-import com.yahoo.search.pagetemplates.model.*;
+import com.yahoo.search.pagetemplates.model.MapChoice;
+import com.yahoo.search.pagetemplates.model.Placeholder;
+import com.yahoo.search.pagetemplates.model.Section;
+import com.yahoo.search.pagetemplates.model.Source;
+import org.junit.Test;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
/**
* @author bratseth
*/
-public class MapPageTemplateXMLReadingTestCase extends junit.framework.TestCase {
+public class MapPageTemplateXMLReadingTestCase {
private String root="src/test/java/com/yahoo/search/pagetemplates/config/test/examples/mapexamples/";
+ @Test
public void testMap1() {
PageTemplateRegistry registry=new PageTemplateXMLReader().read(root);
assertCorrectMap1(registry.getComponent("map1"));
diff --git a/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/PageTemplateXMLReadingTestCase.java b/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/PageTemplateXMLReadingTestCase.java
index 109e7e75885..a7f79a0ee93 100644
--- a/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/PageTemplateXMLReadingTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/pagetemplates/config/test/PageTemplateXMLReadingTestCase.java
@@ -13,17 +13,24 @@ import com.yahoo.search.pagetemplates.model.Choice;
import com.yahoo.search.pagetemplates.model.Renderer;
import com.yahoo.search.pagetemplates.model.Section;
import com.yahoo.search.pagetemplates.model.Source;
+import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
/**
* @author bratseth
*/
-public class PageTemplateXMLReadingTestCase extends junit.framework.TestCase {
+public class PageTemplateXMLReadingTestCase {
private String root="src/test/java/com/yahoo/search/pagetemplates/config/test/";
+ @Test
public void testExamples() {
PageTemplateRegistry registry=new PageTemplateXMLReader().read(root + "examples");
assertCorrectSerp(registry.getComponent("serp"));
@@ -34,6 +41,7 @@ public class PageTemplateXMLReadingTestCase extends junit.framework.TestCase {
assertCorrectGeneric(registry.getComponent("generic"));
}
+ @Test
public void testConfigReading() {
PageTemplatesConfig config = new PageTemplatesConfig(new PageTemplatesConfig.Builder()
.page("<page id=\"slottingSerp\" layout=\"mainAndRight\">\n <section layout=\"column\" region=\"main\" source=\"*\" order=\"-[rank]\"/>\n <section layout=\"column\" region=\"right\" source=\"ads\"/>\n</page>\n")
@@ -48,6 +56,7 @@ public class PageTemplateXMLReadingTestCase extends junit.framework.TestCase {
assertCorrectRicherSerp(registry.getComponent("richerSerp"));
}
+ @Test
public void testInvalidFilename() {
try {
PageTemplateRegistry registry=new PageTemplateXMLReader().read(root + "examples/invalidfilename");
diff --git a/container-search/src/test/java/com/yahoo/search/pagetemplates/test/PageTemplateSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/pagetemplates/test/PageTemplateSearcherTestCase.java
index 74b483bfaba..3efaf9a6132 100644
--- a/container-search/src/test/java/com/yahoo/search/pagetemplates/test/PageTemplateSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/pagetemplates/test/PageTemplateSearcherTestCase.java
@@ -18,15 +18,22 @@ import com.yahoo.search.result.Hit;
import com.yahoo.search.result.HitGroup;
import com.yahoo.search.searchchain.Execution;
import com.yahoo.text.interpretation.Interpretation;
+import org.junit.Test;
import java.util.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
/**
* @author bratseth
*/
-@SuppressWarnings("deprecation")
-public class PageTemplateSearcherTestCase extends junit.framework.TestCase {
+public class PageTemplateSearcherTestCase {
+ @Test
public void testSearcher() {
PageTemplateSearcher s = new PageTemplateSearcher(createPageTemplateRegistry(), new FirstChoiceResolver());
Chain<Searcher> chain = new Chain<>(s,new MockFederator());
diff --git a/container-search/src/test/java/com/yahoo/search/pagetemplates/test/SourceParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/pagetemplates/test/SourceParametersTestCase.java
index 74891137dab..7a2d3d782a3 100644
--- a/container-search/src/test/java/com/yahoo/search/pagetemplates/test/SourceParametersTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/pagetemplates/test/SourceParametersTestCase.java
@@ -7,14 +7,19 @@ import com.yahoo.search.pagetemplates.PageTemplateRegistry;
import com.yahoo.search.pagetemplates.PageTemplateSearcher;
import com.yahoo.search.pagetemplates.config.PageTemplateXMLReader;
import com.yahoo.search.searchchain.Execution;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
/**
* @author bratseth
*/
-public class SourceParametersTestCase extends junit.framework.TestCase {
+public class SourceParametersTestCase {
private static final String root="src/test/java/com/yahoo/search/pagetemplates/test/";
+ @Test
public void testSourceParametersWithSourcesDeterminedByTemplate() {
// Create the page template
PageTemplateRegistry pageTemplateRegistry=new PageTemplateRegistry();
@@ -31,6 +36,7 @@ public class SourceParametersTestCase extends junit.framework.TestCase {
assertEquals("We get the correct number of parameters",5,query.properties().listProperties("source").size());
}
+ @Test
public void testSourceParametersWithSourcesDeterminedByParameter() {
// Create the page template
PageTemplateRegistry pageTemplateRegistry=new PageTemplateRegistry();
diff --git a/container-search/src/test/java/com/yahoo/search/query/context/test/LoggingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/context/test/LoggingTestCase.java
index b1b9b05eb54..5a48bc1425c 100644
--- a/container-search/src/test/java/com/yahoo/search/query/context/test/LoggingTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/context/test/LoggingTestCase.java
@@ -8,12 +8,17 @@ import java.util.Set;
import com.yahoo.processing.execution.Execution;
import com.yahoo.search.Query;
import com.yahoo.search.query.context.QueryContext;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author bratseth
*/
-public class LoggingTestCase extends junit.framework.TestCase {
+public class LoggingTestCase {
+ @Test
public void testLogging() {
Query query=new Query();
QueryContext queryContext = query.getContext(true);
diff --git a/container-search/src/test/java/com/yahoo/search/query/context/test/PropertiesTestCase.java b/container-search/src/test/java/com/yahoo/search/query/context/test/PropertiesTestCase.java
index 57e4c8701d0..e7c6f016ee8 100644
--- a/container-search/src/test/java/com/yahoo/search/query/context/test/PropertiesTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/context/test/PropertiesTestCase.java
@@ -3,12 +3,17 @@ package com.yahoo.search.query.context.test;
import com.yahoo.search.Query;
import com.yahoo.search.query.context.QueryContext;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
/**
* @author bratseth
*/
-public class PropertiesTestCase extends junit.framework.TestCase {
+public class PropertiesTestCase {
+ @Test
public void testProperties() {
Query query=new Query();
QueryContext h = query.getContext(true);
@@ -33,7 +38,7 @@ public class PropertiesTestCase extends junit.framework.TestCase {
h2.setProperty("c","c3");
h.setProperty("c","c4");
- assertEquals("a2",h.getProperty("a"));
+ assertEquals("a@2",h.getProperty("a"));
assertEquals("b5",h.getProperty("b"));
assertEquals("c4",h.getProperty("c"));
assertEquals("d1",h.getProperty("d"));
diff --git a/container-search/src/test/java/com/yahoo/search/query/context/test/TraceTestCase.java b/container-search/src/test/java/com/yahoo/search/query/context/test/TraceTestCase.java
index e64b1054f41..5882ded367e 100644
--- a/container-search/src/test/java/com/yahoo/search/query/context/test/TraceTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/context/test/TraceTestCase.java
@@ -3,17 +3,22 @@ package com.yahoo.search.query.context.test;
import com.yahoo.search.Query;
import com.yahoo.search.query.context.QueryContext;
+import org.junit.Test;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Iterator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
-public class TraceTestCase extends junit.framework.TestCase {
+public class TraceTestCase {
+ @Test
public void testBasicTracing() {
Query query=new Query();
QueryContext h = query.getContext(true);
@@ -22,6 +27,7 @@ public class TraceTestCase extends junit.framework.TestCase {
assertEquals("trace: [ [ first message second message ] ]", h.toString());
}
+ @Test
public void testCloning() throws IOException {
Query query=new Query();
QueryContext h = query.getContext(true);
@@ -53,6 +59,7 @@ public class TraceTestCase extends junit.framework.TestCase {
assertEquals("fifth message",i.next());
}
+ @Test
public void testEmpty() throws IOException {
Query query=new Query();
QueryContext h = query.getContext(true);
@@ -61,6 +68,7 @@ public class TraceTestCase extends junit.framework.TestCase {
assertEquals("", w.toString());
}
+ @Test
public void testEmptySubSequence() {
Query query=new Query();
QueryContext h = query.getContext(true);
@@ -73,6 +81,7 @@ public class TraceTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testAttachedTraces() throws IOException {
String needle0 = "nalle";
String needle1 = "tralle";
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/MultiProfileTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/MultiProfileTestCase.java
index db874ab3a81..c355186ba44 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/MultiProfileTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/MultiProfileTestCase.java
@@ -7,12 +7,17 @@ import java.util.Map;
import com.yahoo.search.query.profile.QueryProfile;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.search.query.profile.config.QueryProfileXMLReader;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
/**
* @author bratseth
*/
-public class MultiProfileTestCase extends junit.framework.TestCase {
+public class MultiProfileTestCase {
+ @Test
public void testValid() {
QueryProfileRegistry registry=
new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/multiprofile");
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java
index 5650a7d3e22..67fb5da10a0 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java
@@ -14,19 +14,24 @@ import com.yahoo.search.handler.HttpSearchResponse;
import com.yahoo.search.handler.SearchHandler;
import com.yahoo.search.result.Hit;
import com.yahoo.search.searchchain.Execution;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
/**
* Tests using query profiles in searches
*
* @author bratseth
*/
-public class QueryProfileIntegrationTestCase extends junit.framework.TestCase {
+public class QueryProfileIntegrationTestCase {
- @Override
+ @org.junit.After
public void tearDown() {
System.getProperties().remove("config.id");
}
+ @Test
public void testUntyped() {
String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/untyped";
System.setProperty("config.id", configId);
@@ -69,6 +74,7 @@ public class QueryProfileIntegrationTestCase extends junit.framework.TestCase {
configurer.shutdown();
}
+ @Test
public void testTyped() {
String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/typed";
System.setProperty("config.id", configId);
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java
index 7907c747a31..9a74e1b6766 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java
@@ -6,13 +6,19 @@ import com.yahoo.search.query.profile.config.QueryProfileConfigurer;
import com.yahoo.search.query.profile.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileType;
import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* @author bratseth
*/
-public class TypedProfilesConfigurationTestCase extends junit.framework.TestCase {
+public class TypedProfilesConfigurationTestCase {
/** Asserts that everything is read correctly from this configuration */
+ @Test
public void testIt() {
QueryProfileConfigurer configurer=
new QueryProfileConfigurer("file:src/test/java/com/yahoo/search/query/profile/config/test/typed-profiles.cfg");
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/CloningTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/CloningTestCase.java
index 0a62581eca0..3e01c79b61f 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/test/CloningTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/CloningTestCase.java
@@ -6,12 +6,16 @@ import com.yahoo.search.Query;
import com.yahoo.search.query.profile.QueryProfile;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.jdisc.http.HttpRequest.Method;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* @author bratseth
*/
-public class CloningTestCase extends junit.framework.TestCase {
+public class CloningTestCase {
+ @Test
public void testCloningWithVariants() {
QueryProfile test = new QueryProfile("test");
test.setDimensions(new String[] {"x"} );
@@ -24,6 +28,7 @@ public class CloningTestCase extends junit.framework.TestCase {
assertEquals("a2",q2.properties().get("a"));
}
+ @Test
public void testShallowCloning() {
QueryProfile test = new QueryProfile("test");
test.freeze();
@@ -35,6 +40,7 @@ public class CloningTestCase extends junit.framework.TestCase {
assertEquals("a2",q2.properties().get("a").toString());
}
+ @Test
public void testShallowCloningWithVariants() {
QueryProfile test = new QueryProfile("test");
test.setDimensions(new String[] {"x"} );
@@ -47,6 +53,7 @@ public class CloningTestCase extends junit.framework.TestCase {
assertEquals("a2",q2.properties().get("a").toString());
}
+ @Test
public void testDeepCloning() {
QueryProfile test=new QueryProfile("test");
test.freeze();
@@ -58,6 +65,7 @@ public class CloningTestCase extends junit.framework.TestCase {
assertEquals("a2",q2.properties().get("a").toString());
}
+ @Test
public void testDeepCloningWithVariants() {
QueryProfile test=new QueryProfile("test");
test.setDimensions(new String[] {"x"} );
@@ -70,6 +78,7 @@ public class CloningTestCase extends junit.framework.TestCase {
assertEquals("a2",q2.properties().get("a").toString());
}
+ @Test
public void testReAssignment() {
QueryProfile test=new QueryProfile("test");
test.setDimensions(new String[] {"x"} );
@@ -80,6 +89,7 @@ public class CloningTestCase extends junit.framework.TestCase {
assertEquals("a2",q1.properties().get("a"));
}
+ @Test
public void testThreeLevelsOfCloning() {
QueryProfile test = new QueryProfile("test");
test.set("a", "config-a", (QueryProfileRegistry)null);
@@ -105,6 +115,7 @@ public class CloningTestCase extends junit.framework.TestCase {
assertEquals("q32-a",q32.properties().get("a").toString());
}
+ @Test
public void testThreeLevelsOfCloningReverseSetOrder() {
QueryProfile test = new QueryProfile("test");
test.set("a", "config-a", (QueryProfileRegistry)null);
@@ -130,6 +141,7 @@ public class CloningTestCase extends junit.framework.TestCase {
assertEquals("q32-a",q32.properties().get("a").toString());
}
+ @Test
public void testThreeLevelsOfCloningMiddleFirstSetOrder1() {
QueryProfile test = new QueryProfile("test");
test.set("a", "config-a", (QueryProfileRegistry)null);
@@ -155,6 +167,7 @@ public class CloningTestCase extends junit.framework.TestCase {
assertEquals("q32-a",q32.properties().get("a").toString());
}
+ @Test
public void testThreeLevelsOfCloningMiddleFirstSetOrder2() {
QueryProfile test = new QueryProfile("test");
test.set("a", "config-a", (QueryProfileRegistry)null);
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java
index 3d422767a66..46d574f1713 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java
@@ -2,33 +2,40 @@
package com.yahoo.search.query.profile.test;
import com.yahoo.search.query.profile.DumpTool;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
/**
* @author bratseth
*/
-public class DumpToolTestCase extends junit.framework.TestCase {
+public class DumpToolTestCase {
String profileDir="src/test/java/com/yahoo/search/query/profile/config/test/multiprofile";
+ @Test
public void testNoParameters() {
assertTrue(new DumpTool().resolveAndDump().startsWith("Dumps all resolved"));
}
+ @Test
public void testHelpParameter() {
assertTrue(new DumpTool().resolveAndDump("-help").startsWith("Dumps all resolved"));
}
+ @Test
public void testNoDimensionValues() {
assertTrue(new DumpTool().resolveAndDump("multiprofile1",profileDir).startsWith("a=general-a\n"));
}
+ @Test
public void testAllParametersSet() {
assertTrue(new DumpTool().resolveAndDump("multiprofile1",profileDir,"").startsWith("a=general-a\n"));
}
- //This test is order dependent. Fix this!!
+ // This test is order dependent. Fix this!!
+ @Test
public void testVariant() {
- System.out.println(new DumpTool().resolveAndDump("multiprofile1",profileDir,"region=us"));
assertTrue(new DumpTool().resolveAndDump("multiprofile1",profileDir,"region=us").startsWith("a=us-a\nb=us-b\nregion=us"));
}
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryFromProfileTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryFromProfileTestCase.java
index f75444108ff..b4fe6b62d44 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryFromProfileTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryFromProfileTestCase.java
@@ -8,14 +8,18 @@ import com.yahoo.search.Query;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
import com.yahoo.search.query.profile.types.QueryProfileType;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* Test using the profile to set the query to execute
*
* @author bratseth
*/
-public class QueryFromProfileTestCase extends junit.framework.TestCase {
+public class QueryFromProfileTestCase {
+ @Test
public void testQueryFromProfile1() {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfile topLevel = new QueryProfile("topLevel");
@@ -34,6 +38,7 @@ public class QueryFromProfileTestCase extends junit.framework.TestCase {
assertEquals("best", query.getModel().getQueryTree().toString());
}
+ @Test
public void testQueryFromProfile2() {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfileType rootType = new QueryProfileType("root");
@@ -56,6 +61,7 @@ public class QueryFromProfileTestCase extends junit.framework.TestCase {
assertEquals("overrides", query.getModel().getQueryTree().toString());
}
+ @Test
public void testQueryFromProfile3() {
QueryProfileRegistry registry = new QueryProfileRegistry();
QueryProfileType rootType = new QueryProfileType("root");
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java
index 27960aac56c..7ff120ddc70 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java
@@ -7,42 +7,49 @@ import com.yahoo.yolean.Exceptions;
import com.yahoo.search.query.profile.QueryProfile;
import com.yahoo.search.query.profile.QueryProfileProperties;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfile;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* @author bratseth
*/
-public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase {
+public class QueryProfileSubstitutionTestCase {
+ @Test
public void testSingleSubstitution() {
QueryProfile p=new QueryProfile("test");
- p.set("message","Hello %{world}!", (QueryProfileRegistry)null);
- p.set("world", "world", (QueryProfileRegistry)null);
+ p.set("message","Hello %{world}!", null);
+ p.set("world", "world", null);
assertEquals("Hello world!",p.compile(null).get("message"));
QueryProfile p2=new QueryProfile("test2");
p2.addInherited(p);
- p2.set("world", "universe", (QueryProfileRegistry)null);
+ p2.set("world", "universe", null);
assertEquals("Hello universe!",p2.compile(null).get("message"));
}
+ @Test
public void testMultipleSubstitutions() {
QueryProfile p=new QueryProfile("test");
- p.set("message","%{greeting} %{entity}%{exclamation}", (QueryProfileRegistry)null);
- p.set("greeting","Hola", (QueryProfileRegistry)null);
- p.set("entity","local group", (QueryProfileRegistry)null);
- p.set("exclamation","?", (QueryProfileRegistry)null);
+ p.set("message","%{greeting} %{entity}%{exclamation}", null);
+ p.set("greeting","Hola", null);
+ p.set("entity","local group", null);
+ p.set("exclamation","?", null);
assertEquals("Hola local group?",p.compile(null).get("message"));
QueryProfile p2=new QueryProfile("test2");
p2.addInherited(p);
- p2.set("entity","milky way", (QueryProfileRegistry)null);
+ p2.set("entity","milky way", null);
assertEquals("Hola milky way?",p2.compile(null).get("message"));
}
+ @Test
public void testUnclosedSubstitution1() {
try {
QueryProfile p=new QueryProfile("test");
- p.set("message1","%{greeting} %{entity}%{exclamation", (QueryProfileRegistry)null);
+ p.set("message1","%{greeting} %{entity}%{exclamation", null);
fail("Should have produced an exception");
}
catch (IllegalArgumentException e) {
@@ -51,10 +58,11 @@ public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testUnclosedSubstitution2() {
try {
QueryProfile p=new QueryProfile("test");
- p.set("message1","%{greeting} %{entity%{exclamation}", (QueryProfileRegistry)null);
+ p.set("message1","%{greeting} %{entity%{exclamation}", null);
fail("Should have produced an exception");
}
catch (IllegalArgumentException e) {
@@ -63,23 +71,25 @@ public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase {
}
}
+ @Test
public void testNullSubstitution() {
QueryProfile p=new QueryProfile("test");
- p.set("message","%{greeting} %{entity}%{exclamation}", (QueryProfileRegistry)null);
- p.set("greeting","Hola", (QueryProfileRegistry)null);
+ p.set("message","%{greeting} %{entity}%{exclamation}", null);
+ p.set("greeting","Hola", null);
assertEquals("Hola ", p.compile(null).get("message"));
QueryProfile p2=new QueryProfile("test2");
p2.addInherited(p);
- p2.set("greeting","Hola", (QueryProfileRegistry)null);
- p2.set("exclamation", "?", (QueryProfileRegistry)null);
+ p2.set("greeting","Hola", null);
+ p2.set("exclamation", "?", null);
assertEquals("Hola ?",p2.compile(null).get("message"));
}
+ @Test
public void testNoOverridingOfPropertiesSetAtRuntime() {
QueryProfile p=new QueryProfile("test");
- p.set("message","Hello %{world}!", (QueryProfileRegistry)null);
- p.set("world","world", (QueryProfileRegistry)null);
+ p.set("message","Hello %{world}!", null);
+ p.set("world","world", null);
p.freeze();
Properties runtime=new QueryProfileProperties(p.compile(null));
@@ -88,27 +98,30 @@ public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase {
assertEquals("Hello %{world}!",runtime.get("runtimeMessage"));
}
+ @Test
public void testButPropertiesSetAtRuntimeAreUsedInSubstitutions() {
QueryProfile p=new QueryProfile("test");
- p.set("message","Hello %{world}!", (QueryProfileRegistry)null);
- p.set("world","world", (QueryProfileRegistry)null);
+ p.set("message","Hello %{world}!", null);
+ p.set("world","world", null);
Properties runtime=new QueryProfileProperties(p.compile(null));
runtime.set("world","Earth");
assertEquals("Hello Earth!",runtime.get("message"));
}
+ @Test
public void testInspection() {
QueryProfile p=new QueryProfile("test");
- p.set("message", "%{greeting} %{entity}%{exclamation}", (QueryProfileRegistry)null);
+ p.set("message", "%{greeting} %{entity}%{exclamation}", null);
assertEquals("message","%{greeting} %{entity}%{exclamation}",
p.declaredContent().entrySet().iterator().next().getValue().toString());
}
+ @Test
public void testVariants() {
QueryProfile p=new QueryProfile("test");
- p.set("message","Hello %{world}!", (QueryProfileRegistry)null);
- p.set("world","world", (QueryProfileRegistry)null);
+ p.set("message","Hello %{world}!", null);
+ p.set("world","world", null);
p.setDimensions(new String[] {"x"});
p.set("message","Halo %{world}!",new String[] {"x1"}, null);
p.set("world","Europe",new String[] {"x2"}, null);
@@ -119,11 +132,12 @@ public class QueryProfileSubstitutionTestCase extends junit.framework.TestCase {
assertEquals("Hello Europe!", cp.get("message", QueryProfileVariantsTestCase.toMap("x=x2")));
}
+ @Test
public void testRecursion() {
QueryProfile p=new QueryProfile("test");
- p.set("message","Hello %{world}!", (QueryProfileRegistry)null);
- p.set("world","sol planet number %{number}", (QueryProfileRegistry)null);
- p.set("number",3, (QueryProfileRegistry)null);
+ p.set("message","Hello %{world}!", null);
+ p.set("world","sol planet number %{number}", null);
+ p.set("number",3, null);
assertEquals("Hello sol planet number 3!",p.compile(null).get("message"));
}