diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-17 14:40:30 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-17 14:40:30 +0200 |
commit | c8cdfb65631a6814f2d85e18171badc9144ed33e (patch) | |
tree | f807a0a4a9fd288c658611e36e5e9bb25e740b65 /container-search/src/test/java/com/yahoo | |
parent | 6b9f956080484c22e894ee0ccd2692c2f442a333 (diff) |
Remove usage of junit.framework
Diffstat (limited to 'container-search/src/test/java/com/yahoo')
42 files changed, 491 insertions, 219 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/FieldTypeTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/FieldTypeTestCase.java index ed4568c5b94..cb2059c64dd 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/FieldTypeTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/FieldTypeTestCase.java @@ -4,12 +4,16 @@ package com.yahoo.search.query.profile.types.test; import com.yahoo.search.query.profile.types.FieldType; 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; /** * @author bratseth */ -public class FieldTypeTestCase extends junit.framework.TestCase { +public class FieldTypeTestCase { + @Test public void testConvertToFromString() { QueryProfileTypeRegistry registry=new QueryProfileTypeRegistry(); registry.register(new QueryProfileType("foo")); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java index f6374705e5e..da457dba3b0 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java @@ -7,14 +7,19 @@ import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.FieldType; import com.yahoo.search.query.profile.types.QueryProfileType; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * tests creating invalid names * * @author bratseth */ -public class NameTestCase extends junit.framework.TestCase { +public class NameTestCase { + @Test public void testNames() { assertLegalName("aB"); assertIllegalName("a."); @@ -26,6 +31,7 @@ public class NameTestCase extends junit.framework.TestCase { assertIllegalName(""); } + @Test public void testFieldNames() { assertLegalFieldName("aB"); try { diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java index d073efd682b..224b0c82339 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java @@ -8,17 +8,20 @@ import com.yahoo.search.Query; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.yolean.Exceptions; +import org.junit.Test; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; /** * Tests that properties can not be set even if they are native, if declared not settable in the query profile * * @author bratseth */ -public class NativePropertiesTestCase extends junit.framework.TestCase { +public class NativePropertiesTestCase { + @Test public void testNativeInStrict() { QueryProfileType strictType=new QueryProfileType("strict"); strictType.setStrict(true); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/OverrideTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/OverrideTestCase.java index 8e4415ffb61..aa6049a45ec 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/OverrideTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/OverrideTestCase.java @@ -12,19 +12,24 @@ import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.FieldType; import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests overriding of field values * * @author bratseth */ -public class OverrideTestCase extends junit.framework.TestCase { +public class OverrideTestCase { private QueryProfileTypeRegistry registry; private QueryProfileType type, user; - protected @Override void setUp() { + @Before + public void setUp() { type=new QueryProfileType(new ComponentId("testtype")); user=new QueryProfileType(new ComponentId("user")); registry=new QueryProfileTypeRegistry(); @@ -53,6 +58,7 @@ public class OverrideTestCase extends junit.framework.TestCase { } /** Check that a simple non-overridable string cannot be overridden */ + @Test public void testSimpleUnoverridable() { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfile test=new QueryProfile("test"); @@ -72,6 +78,7 @@ public class OverrideTestCase extends junit.framework.TestCase { } /** Check that a query profile cannot be overridden */ + @Test public void testUnoverridableQueryProfile() { QueryProfileRegistry registry = new QueryProfileRegistry(); @@ -99,6 +106,7 @@ public class OverrideTestCase extends junit.framework.TestCase { } /** Check that non-overridables are protected also in nested untyped references */ + @Test public void testUntypedNestedUnoverridable() { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfile topMap = new QueryProfile("topMap"); @@ -129,6 +137,7 @@ public class OverrideTestCase extends junit.framework.TestCase { } /** Tests overridability in an inherited field */ + @Test public void testInheritedNonOverridableInType() { QueryProfileRegistry registry = new QueryProfileRegistry(); @@ -153,6 +162,7 @@ public class OverrideTestCase extends junit.framework.TestCase { } /** Tests overridability in an inherited field */ + @Test public void testInheritedNonOverridableInProfile() { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfile test = new QueryProfile("test"); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/PatchMatchingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/PatchMatchingTestCase.java index a02dbb334d5..bfdc1a2537e 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/PatchMatchingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/PatchMatchingTestCase.java @@ -4,14 +4,19 @@ package com.yahoo.search.query.profile.types.test; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.types.QueryProfileType; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; /** * Tests that matching query profiles by path name works * * @author bratseth */ -public class PatchMatchingTestCase extends junit.framework.TestCase { +public class PatchMatchingTestCase { + @Test public void testPatchMatching() { QueryProfileType type=new QueryProfileType("type"); @@ -43,6 +48,7 @@ public class PatchMatchingTestCase extends junit.framework.TestCase { assertNull(registry.findQueryProfile("abee")); } + @Test public void testNoPatchMatching() { QueryProfileType type=new QueryProfileType("type"); @@ -75,6 +81,7 @@ public class PatchMatchingTestCase extends junit.framework.TestCase { } /** Check that the path matching property is inherited to subtypes */ + @Test public void testPatchMatchingInheritance() { QueryProfileType type=new QueryProfileType("type"); QueryProfileType subType=new QueryProfileType("subType"); @@ -109,6 +116,7 @@ public class PatchMatchingTestCase extends junit.framework.TestCase { } /** Check that the path matching works with versioned profiles */ + @Test public void testPatchMatchingVersions() { QueryProfileType type=new QueryProfileType("type"); @@ -148,6 +156,7 @@ public class PatchMatchingTestCase extends junit.framework.TestCase { assertNull(registry.findQueryProfile("abee")); } + @Test public void testQuirkyNames() { QueryProfileType type=new QueryProfileType("type"); @@ -182,5 +191,4 @@ public class PatchMatchingTestCase extends junit.framework.TestCase { assertNull(registry.findQueryProfile("abee")); } - } diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeInheritanceTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeInheritanceTestCase.java index 52bfe04a05f..7ce8cb803e2 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeInheritanceTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeInheritanceTestCase.java @@ -9,17 +9,25 @@ import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.FieldType; import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; /** * @author bratseth */ -public class QueryProfileTypeInheritanceTestCase extends junit.framework.TestCase { +public class QueryProfileTypeInheritanceTestCase { private QueryProfileTypeRegistry registry; private QueryProfileType type, typeStrict, user, userStrict; - protected @Override void setUp() { + @Before + public void setUp() { type=new QueryProfileType(new ComponentId("testtype")); typeStrict=new QueryProfileType(new ComponentId("testtypeStrict")); typeStrict.setStrict(true); @@ -54,6 +62,7 @@ public class QueryProfileTypeInheritanceTestCase extends junit.framework.TestCas user.addField(new FieldDescription("myUserInteger",FieldType.fromString("integer",registry))); } + @Test public void testInheritance() { type.inherited().add(user); type.freeze(); @@ -73,6 +82,7 @@ public class QueryProfileTypeInheritanceTestCase extends junit.framework.TestCas assertEquals("38", ctest.get("myUnknownInteger")); } + @Test public void testInheritanceStrict() { typeStrict.inherited().add(userStrict); typeStrict.freeze(); @@ -95,6 +105,7 @@ public class QueryProfileTypeInheritanceTestCase extends junit.framework.TestCas assertNull(test.get("myUnknownInteger")); } + @Test public void testStrictIsInherited() { type.inherited().add(userStrict); type.freeze(); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java index db1521a3a7b..8eaf4cc08cb 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java @@ -17,26 +17,32 @@ import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.FieldType; import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry; +import org.junit.Before; +import org.junit.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * tests query profiles with/and types * * @author bratseth */ -public class QueryProfileTypeTestCase extends junit.framework.TestCase { +public class QueryProfileTypeTestCase { private QueryProfileRegistry registry; private QueryProfileType type, typeStrict, user, userStrict; - @Override - protected void setUp() { + @Before + public void setUp() { registry = new QueryProfileRegistry(); type = new QueryProfileType(new ComponentId("testtype")); @@ -81,6 +87,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { user.addField(new FieldDescription("myUserInteger",FieldType.fromString("integer",registry),"uint"), registry); } + @Test public void testTypedOfPrimitivesAssignmentNonStrict() { QueryProfile profile=new QueryProfile("test"); profile.setType(type); @@ -147,6 +154,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { assertEquals(51, properties.get("myInteger")); } + @Test public void testTypedOfPrimitivesAssignmentStrict() { QueryProfile profile=new QueryProfile("test"); profile.setType(typeStrict); @@ -188,6 +196,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { } /** Tests assigning a subprofile directly */ + @Test public void testTypedAssignmentOfQueryProfilesNonStrict() { QueryProfile profile=new QueryProfile("test"); profile.setType(type); @@ -218,6 +227,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { } /** Tests assigning a subprofile directly */ + @Test public void testTypedAssignmentOfQueryProfilesStrict() { QueryProfile profile=new QueryProfile("test"); profile.setType(typeStrict); @@ -248,6 +258,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { } /** Tests assigning a subprofile as an id string */ + @Test public void testTypedAssignmentOfQueryProfileReferencesNonStrict() { QueryProfile profile = new QueryProfile("test"); profile.setType(type); @@ -291,6 +302,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { * Tests overriding a subprofile as an id string through the query. * Here there exists a user profile already, and then a new one is overwritten */ + @Test public void testTypedOverridingOfQueryProfileReferencesNonStrictThroughQuery() { QueryProfile profile=new QueryProfile("test"); profile.setType(type); @@ -324,6 +336,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { * Tests overriding a subprofile as an id string through the query. * Here no user profile is set before it is assigned in the query */ + @Test public void testTypedAssignmentOfQueryProfileReferencesNonStrictThroughQuery() { QueryProfile profile=new QueryProfile("test"); profile.setType(type); @@ -350,6 +363,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { * Tests overriding a subprofile as an id string through the query. * Here no user profile is set before it is assigned in the query */ + @Test public void testTypedAssignmentOfQueryProfileReferencesStrictThroughQuery() { QueryProfile profile=new QueryProfile("test"); profile.setType(typeStrict); @@ -381,6 +395,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { } + @Test public void testTensorRankFeatureInRequest() throws UnsupportedEncodingException { QueryProfile profile=new QueryProfile("test"); profile.setType(type); @@ -400,6 +415,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { return URLEncoder.encode(s, "utf8"); } + @Test public void testIllegalStrictAssignmentFromRequest() { QueryProfile profile=new QueryProfile("test"); profile.setType(typeStrict); @@ -429,6 +445,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { * Here there exists a user profile already, and then a new one is overwritten. * The whole thing is accessed through a two levels of nontyped top-level profiles */ + @Test public void testTypedOverridingOfQueryProfileReferencesNonStrictThroughQueryNestedInAnUntypedProfile() { QueryProfile topMap=new QueryProfile("topMap"); @@ -468,6 +485,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { /** * Same as previous test but using the untyped myQueryProfile reference instead of the typed myUserQueryProfile */ + @Test public void testAnonTypedOverridingOfQueryProfileReferencesNonStrictThroughQueryNestedInAnUntypedProfile() { QueryProfile topMap=new QueryProfile("topMap"); @@ -506,6 +524,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { /** * Tests setting a illegal value in a strict profile nested under untyped maps */ + @Test public void testSettingValueInStrictTypeNestedUnderUntypedMaps() { QueryProfile topMap=new QueryProfile("topMap"); @@ -541,6 +560,7 @@ public class QueryProfileTypeTestCase extends junit.framework.TestCase { * Here, no user profile is set before it is assigned in the query * The whole thing is accessed through a two levels of nontyped top-level profiles */ + @Test public void testTypedSettingOfQueryProfileReferencesNonStrictThroughQueryNestedInAnUntypedProfile() { QueryProfile topMap=new QueryProfile("topMap"); diff --git a/container-search/src/test/java/com/yahoo/search/query/properties/test/PropertyMapTestCase.java b/container-search/src/test/java/com/yahoo/search/query/properties/test/PropertyMapTestCase.java index 419e650a01e..e0ae1b7c4fa 100644 --- a/container-search/src/test/java/com/yahoo/search/query/properties/test/PropertyMapTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/properties/test/PropertyMapTestCase.java @@ -2,21 +2,26 @@ package com.yahoo.search.query.properties.test; import com.yahoo.processing.request.properties.PropertyMap; +import org.junit.Test; import java.util.Collections; import java.util.List; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** * @author bratseth */ -public class PropertyMapTestCase extends junit.framework.TestCase { +public class PropertyMapTestCase { + @Test public void testCloning() { - PropertyMap map=new PropertyMap(); - map.set("clonable",new ClonableObject()); - map.set("nonclonable",new NonClonableObject()); - map.set("clonableArray",new ClonableObject[] {new ClonableObject()}); - map.set("nonclonableArray",new NonClonableObject[] {new NonClonableObject()}); + PropertyMap map = new PropertyMap(); + map.set("clonable", new ClonableObject()); + map.set("nonclonable", new NonClonableObject()); + map.set("clonableArray", new ClonableObject[] {new ClonableObject()}); + map.set("nonclonableArray", new NonClonableObject[] {new NonClonableObject()}); map.set("clonableList", Collections.singletonList(new ClonableObject())); map.set("nonclonableList", Collections.singletonList(new NonClonableObject())); assertNotNull(map.get("clonable")); @@ -57,5 +62,4 @@ public class PropertyMapTestCase extends junit.framework.TestCase { } - } diff --git a/container-search/src/test/java/com/yahoo/search/query/properties/test/RequestContextPropertiesTestCase.java b/container-search/src/test/java/com/yahoo/search/query/properties/test/RequestContextPropertiesTestCase.java index e9789a4523a..caf960065d7 100644 --- a/container-search/src/test/java/com/yahoo/search/query/properties/test/RequestContextPropertiesTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/properties/test/RequestContextPropertiesTestCase.java @@ -5,14 +5,18 @@ import com.yahoo.search.Query; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.test.QueryTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * Tests that dimension arguments in queries are transferred correctly to dimension values * * @author bratseth */ -public class RequestContextPropertiesTestCase extends junit.framework.TestCase { +public class RequestContextPropertiesTestCase { + @Test public void testIt() { QueryProfile p=new QueryProfile("test"); p.setDimensions(new String[] {"x"}); diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/GenericExpansionRewriterTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/GenericExpansionRewriterTestCase.java index 6399c24277e..63599f60ade 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/GenericExpansionRewriterTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/GenericExpansionRewriterTestCase.java @@ -8,13 +8,15 @@ import com.yahoo.search.searchchain.*; import com.yahoo.search.query.rewrite.*; import com.yahoo.search.query.rewrite.rewriters.*; import com.yahoo.search.query.rewrite.RewritesConfig; +import org.junit.Before; +import org.junit.Test; /** * Test Cases for GenericExpansionRewriter * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { +public class GenericExpansionRewriterTestCase { private QueryRewriteSearcherTestUtils utils; private final String CONFIG_PATH = "file:src/test/java/com/yahoo/search/query/rewrite/test/" + @@ -27,7 +29,8 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { * Load the GenericExpansionRewriterSearcher and prepare the * execution object */ - protected void setUp() { + @Before + public void setUp() { RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(CONFIG_PATH); HashMap<String, File> fileList = new HashMap<>(); fileList.put(GenericExpansionRewriter.GENERIC_EXPAND_DICT, new File(GENERIC_EXPAND_DICT_PATH)); @@ -37,13 +40,10 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { utils = new QueryRewriteSearcherTestUtils(execution); } - public GenericExpansionRewriterTestCase(String name) { - super(name); - } - /** * MaxRewrites=3, PartialPhraseMatch is on, type=adv case */ + @Test public void testPartialPhraseMaxRewriteAdvType() { utils.assertRewrittenQuery("?query=(modern new york city travel phone number) OR (travel agency) OR travel&type=adv&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true&" + @@ -56,6 +56,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * PartialPhraseMatch is off, type=adv case */ + @Test public void testPartialPhraseNoMaxRewriteAdvType() { utils.assertRewrittenQuery("?query=(modern new york city travel phone number) OR (travel agency) OR travel&type=adv&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=false", @@ -66,6 +67,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, type=adv, added filter case */ + @Test public void testFullPhraseNoMaxRewriteAdvTypeFilter() { utils.assertRewrittenQuery("?query=ca OR (modern new york city travel phone number) OR (travel agency) OR travel&" + "type=adv&filter=citystate:santa clara ca&" + @@ -77,6 +79,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * MaxRewrites=0 (i.e No MaxRewrites), PartialPhraseMatch is on, type=adv, added filter case */ + @Test public void testPartialPhraseNoMaxRewriteAdvTypeFilter() { utils.assertRewrittenQuery("?query=ca OR (modern new york city travel phone number) OR (travel agency) OR travel&" + "type=adv&filter=citystate:santa clara ca&" + @@ -92,6 +95,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, single word, added filter case */ + @Test public void testFullPhraseNoMaxRewriteSingleWordFilter() { utils.assertRewrittenQuery("?query=ca&" + "filter=citystate:santa clara ca&" + @@ -102,6 +106,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is on, single word, added filter case */ + @Test public void testPartialPhraseNoMaxRewriteSingleWordFilter() { utils.assertRewrittenQuery("?query=ca&" + "filter=citystate:santa clara ca&" + @@ -112,6 +117,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, multi word, added filter case */ + @Test public void testFullPhraseNoMaxRewriteMultiWordFilter() { utils.assertRewrittenQuery("?query=travel agency&" + "filter=citystate:santa clara ca&" + @@ -122,6 +128,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is on, multi word, added filter case */ + @Test public void testPartialPhraseNoMaxRewriteMultiWordFilter() { utils.assertRewrittenQuery("?query=modern new york city travel phone number&" + "filter=citystate:santa clara ca&" + @@ -134,6 +141,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, single word */ + @Test public void testFullPhraseNoMaxRewriteSingleWord() { utils.assertRewrittenQuery("?query=ca&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=false", @@ -143,6 +151,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is on, single word */ + @Test public void testPartialPhraseNoMaxRewriteSingleWord() { utils.assertRewrittenQuery("?query=ca&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true", @@ -152,6 +161,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, multi word */ + @Test public void testFullPhraseNoMaxRewriteMultiWord() { utils.assertRewrittenQuery("?query=travel agency&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=false", @@ -161,6 +171,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is off, multi word, no full match */ + @Test public void testFullPhraseNoMaxRewriteMultiWordNoMatch() { utils.assertRewrittenQuery("?query=nyc travel agency&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=false", @@ -170,6 +181,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { /** * No MaxRewrites, PartialPhraseMatch is on, multi word */ + @Test public void testPartialPhraseNoMaxRewriteMultiWord() { utils.assertRewrittenQuery("?query=modern new york city travel phone number&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true", @@ -182,6 +194,7 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { * Dictionary contain the word "travel agency", the word "agency" and the word "travel" * Should rewrite travel but not travel agency in this case */ + @Test public void testPartialPhraseMultiWordRankTree() { utils.assertRewrittenQuery("?query=travel RANK agency&type=adv&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true", @@ -193,10 +206,12 @@ public class GenericExpansionRewriterTestCase extends junit.framework.TestCase { * Dictionary contain the word "travel agency", the word "agency" and the word "travel" * Should rewrite travel but not travel agency in this case */ + @Test public void testFullPhraseMultiWordRankTree() { utils.assertRewrittenQuery("?query=travel RANK agency&type=adv&" + REWRITER_NAME + "." + RewriterConstants.PARTIAL_PHRASE_MATCH + "=true", "query 'RANK (OR tr travel) agency'"); } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java index 82f548727f6..9a9e9ff52e0 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java @@ -6,13 +6,17 @@ import com.yahoo.search.searchchain.*; import com.yahoo.search.intent.model.*; import com.yahoo.search.query.rewrite.*; import com.yahoo.search.query.rewrite.rewriters.*; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.fail; /** * Test Cases for MisspellRewriter * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class MisspellRewriterTestCase extends junit.framework.TestCase { +public class MisspellRewriterTestCase { private QueryRewriteSearcherTestUtils utils; public final String REWRITER_NAME = MisspellRewriter.REWRITER_NAME; @@ -21,20 +25,18 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * Load the QueryRewriteSearcher and prepare the * execution object */ - protected void setUp() { + @Before + public void setUp() { MisspellRewriter searcher = new MisspellRewriter(); Execution execution = QueryRewriteSearcherTestUtils.createExecutionObj(searcher); utils = new QueryRewriteSearcherTestUtils(execution); } - public MisspellRewriterTestCase(String name) { - super(name); - } - /** * QSSRewrite and QSSSuggest are on * QLAS returns spell correction: qss_rw=0.9 qss_sugg=1.0 */ + @Test public void testQSSRewriteQSSSuggestWithRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("will smith rw", 0.9, @@ -53,6 +55,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * QSSRewrite is on * QLAS returns spell correction: qss_rw=0.9 qss_rw=0.9 qss_sugg=1.0 */ + @Test public void testQSSRewriteWithRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("will smith rw1", 0.9, @@ -72,6 +75,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * QSSSuggest is on * QLAS returns spell correction: qss_rw=1.0 qss_sugg=0.9 qss_sugg=0.8 */ + @Test public void testQSSSuggWithRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("will smith rw", 1.0, @@ -91,6 +95,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * QSSRewrite and QSSSuggest are off * QLAS returns spell correction: qss_rw=1.0 qss_sugg=1.0 */ + @Test public void testFeautureOffWithRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("will smith rw", 1.0, @@ -107,6 +112,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * QSSRewrite and QSSSuggest are on * QLAS returns no spell correction */ + @Test public void testQSSRewriteQSSSuggWithoutRewrite() { IntentModel intentModel = new IntentModel( utils.createInterpretation("use diff query for testing", 1.0, @@ -125,6 +131,7 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { * IntentModel is null * It should throw exception */ + @Test public void testNullIntentModelException() { try { RewriterUtils.getSpellCorrected(new Query("willl smith"), true, true); @@ -132,5 +139,6 @@ public class MisspellRewriterTestCase extends junit.framework.TestCase { } catch (RuntimeException e) { } } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/NameRewriterTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/NameRewriterTestCase.java index c44613f4f49..985ea2da001 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/NameRewriterTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/NameRewriterTestCase.java @@ -8,13 +8,15 @@ import com.yahoo.search.searchchain.*; import com.yahoo.search.query.rewrite.*; import com.yahoo.search.query.rewrite.rewriters.*; import com.yahoo.search.query.rewrite.RewritesConfig; +import org.junit.Before; +import org.junit.Test; /** * Test Cases for NameRewriter * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class NameRewriterTestCase extends junit.framework.TestCase { +public class NameRewriterTestCase { private QueryRewriteSearcherTestUtils utils; private final String CONFIG_PATH = "file:src/test/java/com/yahoo/search/query/rewrite/test/" + @@ -27,7 +29,8 @@ public class NameRewriterTestCase extends junit.framework.TestCase { * Load the NameRewriterSearcher and prepare the * execution object */ - protected void setUp() { + @Before + public void setUp() { RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(CONFIG_PATH); HashMap<String, File> fileList = new HashMap<>(); fileList.put(NameRewriter.NAME_ENTITY_EXPAND_DICT, new File(NAME_ENTITY_EXPAND_DICT_PATH)); @@ -37,13 +40,10 @@ public class NameRewriterTestCase extends junit.framework.TestCase { utils = new QueryRewriteSearcherTestUtils(execution); } - public NameRewriterTestCase(String name) { - super(name); - } - /** * RewritesAsEquiv and OriginalAsUnit are on */ + @Test public void testRewritesAsEquivAndOriginalAsUnit() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&" + @@ -58,6 +58,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * RewritesAsEquiv is on */ + @Test public void testRewritesAsEquiv() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&", @@ -72,6 +73,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { * Complex query with more than two levels for RewritesAsEquiv is on case * Should not rewrite */ + @Test public void testComplextQueryRewritesAsEquiv() { utils.assertRewrittenQuery("?query=((will smith) OR (willl smith)) AND (tom cruise)&type=adv&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&", @@ -81,6 +83,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * Single word query for RewritesAsEquiv and OriginalAsUnit on case */ + @Test public void testSingleWordForRewritesAsEquivAndOriginalAsUnit() { utils.assertRewrittenQuery("?query=obama&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&" + @@ -97,6 +100,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * RewritesAsUnitEquiv and OriginalAsUnitEquiv are on */ + @Test public void testRewritesAsUnitEquivAndOriginalAsUnitEquiv() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_UNIT_EQUIV + @@ -113,6 +117,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * Single word query for RewritesAsUnitEquiv and OriginalAsUnitEquiv on case */ + @Test public void testSingleWordForRewritesAsUnitEquivAndOriginalAsUnitEquiv() { utils.assertRewrittenQuery("?query=obama&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_UNIT_EQUIV + @@ -132,6 +137,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { * Boosting only query (n/a as rewrite in FSA) * for RewritesAsEquiv and OriginalAsUnit on case */ + @Test public void testBoostingQueryForRewritesAsEquivAndOriginalAsUnit() { utils.assertRewrittenQuery("?query=angelina jolie&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&" + @@ -143,6 +149,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { * No match in FSA for the query * RewritesAsEquiv and OriginalAsUnit on case */ + @Test public void testFSANoMatchForRewritesAsEquivAndOriginalAsUnit() { utils.assertRewrittenQuery("?query=tom cruise&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_EQUIV + "=true&" + @@ -153,6 +160,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * RewritesAsUnitEquiv is on */ + @Test public void testRewritesAsUnitEquiv() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_UNIT_EQUIV + @@ -167,6 +175,7 @@ public class NameRewriterTestCase extends junit.framework.TestCase { /** * RewritesAsUnitEquiv is on and MaxRewrites is set to 2 */ + @Test public void testRewritesAsUnitEquivAndMaxRewrites() { utils.assertRewrittenQuery("?query=will smith&" + REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_UNIT_EQUIV + @@ -175,5 +184,6 @@ public class NameRewriterTestCase extends junit.framework.TestCase { "query 'OR (AND will smith) \"will smith movies\" " + "\"will smith news\"'"); } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestCase.java index 9e21df844f2..46693915f95 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestCase.java @@ -10,13 +10,15 @@ import com.yahoo.search.intent.model.*; import com.yahoo.search.query.rewrite.RewritesConfig; import com.yahoo.search.query.rewrite.*; import com.yahoo.search.query.rewrite.rewriters.*; +import org.junit.Before; +import org.junit.Test; /** * Generic Test Cases for QueryRewriteSearcher * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { +public class QueryRewriteSearcherTestCase { private QueryRewriteSearcherTestUtils utils; private final String NAME_REWRITER_CONFIG_PATH = "file:src/test/java/com/yahoo/search/query/rewrite/test/" + @@ -34,7 +36,8 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { * Load the QueryRewriteSearcher and prepare the * execution object */ - protected void setUp() { + @Before + public void setUp() { // Instantiate Name Rewriter RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(NAME_REWRITER_CONFIG_PATH); HashMap<String, File> fileList = new HashMap<>(); @@ -53,14 +56,11 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { utils = new QueryRewriteSearcherTestUtils(execution); } - public QueryRewriteSearcherTestCase(String name) { - super(name); - } - /** * Invalid FSA config path * Query will be passed to next rewriter */ + @Test public void testInvalidFSAConfigPath() { // Instantiate Name Rewriter with fake FSA path RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(FAKE_FSA_CONFIG_PATH); @@ -89,7 +89,8 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { * IntentModel is null and rewriter throws exception * It should skip to the next rewriter */ - public void testExceptionInRewriter() { + @Test + public void testExceptionInRewriter() { utils.assertRewrittenQuery("?query=will smith&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_SUGG + "=true&" + @@ -108,6 +109,7 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { * Two rewrites in chain * Query will be rewritten twice */ + @Test public void testTwoRewritersInChain() { IntentModel intentModel = new IntentModel( utils.createInterpretation("wills smith", 0.9, @@ -129,5 +131,6 @@ public class QueryRewriteSearcherTestCase extends junit.framework.TestCase { "\"will smith biography\"'", intentModel); } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestUtils.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestUtils.java index 0ae9715c377..fc76a27f306 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestUtils.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/QueryRewriteSearcherTestUtils.java @@ -1,24 +1,26 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.rewrite.test; +import com.yahoo.search.Query; +import com.yahoo.search.Result; +import com.yahoo.search.Searcher; +import com.yahoo.search.intent.model.IntentModel; +import com.yahoo.search.searchchain.Execution; import com.yahoo.search.test.QueryTestCase; -import junit.framework.Assert; -import java.util.*; - -import com.yahoo.search.*; -import com.yahoo.search.searchchain.*; import com.yahoo.search.query.rewrite.RewritesConfig; -import com.yahoo.search.intent.model.*; import com.yahoo.text.interpretation.Modification; import com.yahoo.text.interpretation.Interpretation; import com.yahoo.text.interpretation.Annotations; import com.yahoo.config.subscription.ConfigGetter; import com.yahoo.component.chain.Chain; +import org.junit.Assert; + +import java.util.List; /** * Test utilities for QueryRewriteSearcher * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ public class QueryRewriteSearcherTestUtils { @@ -33,16 +35,13 @@ public class QueryRewriteSearcherTestUtils { this.execution = execution; } - /** * Create config object based on config path * * @param configPath path for the searcher config */ public static RewritesConfig createConfigObj(String configPath) { - ConfigGetter<RewritesConfig> getter = new ConfigGetter<>(RewritesConfig.class); - RewritesConfig config = getter.getConfig(configPath); - return config; + return new ConfigGetter<>(RewritesConfig.class).getConfig(configPath); } /** @@ -51,10 +50,7 @@ public class QueryRewriteSearcherTestUtils { * @param searcher searcher to be added to the search chain */ public static Execution createExecutionObj(Searcher searcher) { - @SuppressWarnings("deprecation") - Chain<Searcher> searchChain = new Chain<>(searcher); - Execution myExecution = new Execution(searchChain, Execution.Context.createContextStub()); - return myExecution; + return new Execution(new Chain<>(searcher), Execution.Context.createContextStub()); } /** @@ -63,19 +59,15 @@ public class QueryRewriteSearcherTestUtils { * @param searchers list of searchers to be added to the search chain */ public static Execution createExecutionObj(List<Searcher> searchers) { - @SuppressWarnings("deprecation") - Chain<Searcher> searchChain = new Chain<>(searchers); - Execution myExecution = new Execution(searchChain, Execution.Context.createContextStub()); - return myExecution; + return new Execution(new Chain<>(searchers), Execution.Context.createContextStub()); } /** * Compare the rewritten query returned after executing * the origQuery against the provided finalQuery - * @param origQuery query to be passed to Query object - * e.g. "?query=will%20smith" - * @param finalQuery expected final query from result.getQuery() - * e.g. "query 'AND will smith'" + * + * @param origQuery query to be passed to Query object e.g. "?query=will%20smith" + * @param finalQuery expected final query from result.getQuery() e.g. "query 'AND will smith'" */ public void assertRewrittenQuery(String origQuery, String finalQuery) { Query query = new Query(QueryTestCase.httpEncode(origQuery)); @@ -87,10 +79,9 @@ public class QueryRewriteSearcherTestUtils { * Set the provided intent model * Compare the rewritten query returned after executing * the origQuery against the provided finalQuery - * @param origQuery query to be passed to Query object - * e.g. "?query=will%20smith" - * @param finalQuery expected final query from result.getQuery() - * e.g. "query 'AND will smith'" + * + * @param origQuery query to be passed to Query object e.g. "?query=will%20smith" + * @param finalQuery expected final query from result.getQuery() e.g. "query 'AND will smith'" * @param intentModel IntentModel to be added to the Query */ public void assertRewrittenQuery(String origQuery, String finalQuery, IntentModel intentModel) { @@ -103,14 +94,14 @@ public class QueryRewriteSearcherTestUtils { /** * Create a new interpretation with modification that * contains the passed in query and score + * * @param spellRewrite query to be used as modification * @param score score to be used as modification score * @param isQSSRW whether the modification is qss_rw * @param isQSSSugg whether the modification is qss_sugg * @return newly created interpretation with modification */ - public Interpretation createInterpretation(String spellRewrite, double score, - boolean isQSSRW, boolean isQSSSugg) { + public Interpretation createInterpretation(String spellRewrite, double score, boolean isQSSRW, boolean isQSSSugg) { Modification modification = new Modification(spellRewrite); Annotations annotation = modification.getAnnotation(); annotation.put("score", score); @@ -121,5 +112,6 @@ public class QueryRewriteSearcherTestUtils { Interpretation interpretation = new Interpretation(modification); return interpretation; } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/SearchChainDispatcherSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/SearchChainDispatcherSearcherTestCase.java index af16d892aa2..8142c9032b5 100644 --- a/container-search/src/test/java/com/yahoo/search/query/rewrite/test/SearchChainDispatcherSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/rewrite/test/SearchChainDispatcherSearcherTestCase.java @@ -12,13 +12,15 @@ import com.yahoo.search.searchchain.SearchChainRegistry; import com.yahoo.search.query.rewrite.RewritesConfig; import com.yahoo.search.intent.model.*; import com.yahoo.component.chain.Chain; +import org.junit.Before; +import org.junit.Test; /** * Test Cases for SearchChainDispatcherSearcher * - * @author karenlee@yahoo-inc.com + * @author Karen Lee */ -public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestCase { +public class SearchChainDispatcherSearcherTestCase { private QueryRewriteSearcherTestUtils utils; private final String NAME_REWRITER_CONFIG_PATH = "file:src/test/java/com/yahoo/search/query/rewrite/test/" + @@ -29,13 +31,12 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC private final String MISSPELL_REWRITER_NAME = MisspellRewriter.REWRITER_NAME; private final String US_MARKET_SEARCH_CHAIN = "us_qrw"; - /** * Load the QueryRewriteSearcher and prepare the * execution object */ - @SuppressWarnings("deprecation") - protected void setUp() { + @Before + public void setUp() { // Instantiate Name Rewriter RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(NAME_REWRITER_CONFIG_PATH); HashMap<String, File> fileList = new HashMap<>(); @@ -64,14 +65,11 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC utils = new QueryRewriteSearcherTestUtils(execution); } - public SearchChainDispatcherSearcherTestCase(String name) { - super(name); - } - /** * Execute the market chain * Query will be rewritten twice */ + @Test public void testMarketChain() { IntentModel intentModel = new IntentModel( utils.createInterpretation("wills smith", 0.9, @@ -98,6 +96,7 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC * Market chain is not valid * Query will be passed to next rewriter */ + @Test public void testInvalidMarketChain() { utils.assertRewrittenQuery("?query=will smith&QRWChain=abc&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true&" + @@ -111,6 +110,7 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC * Empty market chain value * Query will be passed to next rewriter */ + @Test public void testEmptyMarketChain() { utils.assertRewrittenQuery("?query=will smith&QRWChain=&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true&" + @@ -124,7 +124,7 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC * Searchers down the chain after SearchChainDispatcher * should be executed */ - @SuppressWarnings("deprecation") + @Test public void testChainContinuation() { // Instantiate Name Rewriter RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(NAME_REWRITER_CONFIG_PATH); @@ -175,5 +175,6 @@ public class SearchChainDispatcherSearcherTestCase extends junit.framework.TestC "\"will smith biography\"'", intentModel); } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/test/ModelTestCase.java b/container-search/src/test/java/com/yahoo/search/query/test/ModelTestCase.java index 9049b863c3e..1794f8989b4 100644 --- a/container-search/src/test/java/com/yahoo/search/query/test/ModelTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/test/ModelTestCase.java @@ -4,26 +4,34 @@ package com.yahoo.search.query.test; import com.yahoo.prelude.query.Item; import com.yahoo.search.Query; import com.yahoo.search.query.Model; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Arrays; import java.util.LinkedHashSet; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + /** - * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a> + * @author Arne Bergene Fossaa */ -public class ModelTestCase extends junit.framework.TestCase { +public class ModelTestCase { String oldConfigId; + @Before public void setUp() { oldConfigId = System.getProperty("config.id"); System.setProperty("config.id", "file:src/test/java/com/yahoo/prelude/test/fieldtypes/field-info.cfg"); } - + @After public void tearDown() { if (oldConfigId == null) System.getProperties().remove("config.id"); @@ -31,6 +39,7 @@ public class ModelTestCase extends junit.framework.TestCase { System.setProperty("config.id", oldConfigId); } + @Test public void testCopyParameters() { Query q1 = new Query("?query=test1&filter=test2&defidx=content&default-index=lala&encoding=iso8859-1"); Query q2 = q1.clone(); @@ -41,6 +50,7 @@ public class ModelTestCase extends junit.framework.TestCase { assertEquals("test1",r2.getQueryString()); } + @Test public void testSetQuery() { Query q1 = new Query("?query=test1"); Item r1 = q1.getModel().getQueryTree(); @@ -52,7 +62,7 @@ public class ModelTestCase extends junit.framework.TestCase { assertEquals(r1,q1.getModel().getQueryTree()); } - + @Test public void testSetofSetters() { Query q1 = new Query("?query=test1&encoding=iso-8859-1&language=en&default-index=subject&filter=" + enc("\u00C5")); Model r1 = q1.getModel(); @@ -71,11 +81,13 @@ public class ModelTestCase extends junit.framework.TestCase { } } + @Test public void testSearchPath() { assertEquals("c6/r8",new Query("?query=test1&model.searchPath=c6/r8").getModel().getSearchPath()); assertEquals("c6/r8",new Query("?query=test1&searchpath=c6/r8").getModel().getSearchPath()); } + @Test public void testClone() { Query q= new Query(); Model sr = new Model(q); @@ -85,6 +97,7 @@ public class ModelTestCase extends junit.framework.TestCase { assertEquals(sr.getRestrict(),new LinkedHashSet<>(Arrays.asList(new String[]{"cheese","music","other"}))); } + @Test public void testEquals() { Query q = new Query(); Model sra = new Model(q); @@ -99,6 +112,7 @@ public class ModelTestCase extends junit.framework.TestCase { assertNotSame(sra,srb); } + @Test public void testSearchRestrictQueryParameters() { Query query=new Query("?query=test&search=news,archive&restrict=fish,bird"); assertTrue(query.getModel().getSources().contains("news")); diff --git a/container-search/src/test/java/com/yahoo/search/query/test/ParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/query/test/ParametersTestCase.java index 13d25274db1..d4847e91987 100644 --- a/container-search/src/test/java/com/yahoo/search/query/test/ParametersTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/test/ParametersTestCase.java @@ -6,49 +6,59 @@ import com.yahoo.search.Query; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.compiled.CompiledQueryProfile; +import org.junit.Test; import static com.yahoo.jdisc.http.HttpRequest.Method; +import static org.junit.Assert.assertEquals; /** * @author bratseth */ -public class ParametersTestCase extends junit.framework.TestCase { +public class ParametersTestCase { + @Test public void testSettingRankProperty() { Query query=new Query("?query=test&ranking.properties.dotProduct.X=(a:1,b:2)"); assertEquals("[(a:1,b:2)]",query.getRanking().getProperties().get("dotProduct.X").toString()); } + @Test public void testSettingRankPropertyAsAlias() { Query query=new Query("?query=test&rankproperty.dotProduct.X=(a:1,b:2)"); assertEquals("[(a:1,b:2)]",query.getRanking().getProperties().get("dotProduct.X").toString()); } + @Test public void testSettingRankFeature() { Query query=new Query("?query=test&ranking.features.matches=3"); assertEquals("3",query.getRanking().getFeatures().get("matches").toString()); } + @Test public void testSettingRankFeatureAsAlias() { Query query=new Query("?query=test&rankfeature.matches=3"); assertEquals("3",query.getRanking().getFeatures().get("matches").toString()); } + @Test public void testSettingRankPropertyWithQueryProfile() { Query query=new Query(HttpRequest.createTestRequest("?query=test&ranking.properties.dotProduct.X=(a:1,b:2)", Method.GET), createProfile()); assertEquals("[(a:1,b:2)]",query.getRanking().getProperties().get("dotProduct.X").toString()); } + @Test public void testSettingRankPropertyAsAliasWithQueryProfile() { Query query=new Query(HttpRequest.createTestRequest("?query=test&rankproperty.dotProduct.X=(a:1,b:2)", Method.GET), createProfile()); assertEquals("[(a:1,b:2)]",query.getRanking().getProperties().get("dotProduct.X").toString()); } + @Test public void testSettingRankFeatureWithQueryProfile() { Query query=new Query(HttpRequest.createTestRequest("?query=test&ranking.features.matches=3", Method.GET), createProfile()); assertEquals("3",query.getRanking().getFeatures().get("matches").toString()); } + @Test public void testSettingRankFeatureAsAliasWithQueryProfile() { Query query=new Query(HttpRequest.createTestRequest("?query=test&rankfeature.matches=3", Method.GET), createProfile()); assertEquals("3",query.getRanking().getFeatures().get("matches").toString()); diff --git a/container-search/src/test/java/com/yahoo/search/query/test/PresentationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/test/PresentationTestCase.java index 1f5ecf778ac..0c7ea28df41 100644 --- a/container-search/src/test/java/com/yahoo/search/query/test/PresentationTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/test/PresentationTestCase.java @@ -4,13 +4,18 @@ package com.yahoo.search.query.test; import com.yahoo.prelude.query.Highlight; import com.yahoo.search.Query; import com.yahoo.search.query.Presentation; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** - * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a> + * @author Arne Bergene Fossaa */ -public class PresentationTestCase extends junit.framework.TestCase { - +public class PresentationTestCase { + @Test public void testClone() { Query q= new Query(""); Presentation p = new Presentation(q); @@ -24,11 +29,7 @@ public class PresentationTestCase extends junit.framework.TestCase { pc.getHighlight().getHighlightItems(); assertTrue(pc.getHighlight().getHighlightItems().containsKey("date")); assertFalse(pc.getHighlight().getHighlightItems().containsKey("title")); - assertEquals(p,pc); - } - - } diff --git a/container-search/src/test/java/com/yahoo/search/query/test/RankingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/test/RankingTestCase.java index 6c65fd79b90..e2f73617eb6 100644 --- a/container-search/src/test/java/com/yahoo/search/query/test/RankingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/test/RankingTestCase.java @@ -2,18 +2,19 @@ package com.yahoo.search.query.test; import com.yahoo.search.Query; -import com.yahoo.search.query.Ranking; import com.yahoo.search.query.Sorting; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** - * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a> + * @author Arne Bergene Fossaa */ -public class RankingTestCase extends junit.framework.TestCase { +public class RankingTestCase { /** tests setting rank feature values */ + @Test public void testRankFeatures() { // Check initializing from query Query query = new Query("?query=test&ranking.features.query(name)=0.1&ranking.features.fieldMatch(foo)=0.2"); @@ -43,6 +44,7 @@ public class RankingTestCase extends junit.framework.TestCase { } //This test is order dependent. Fix this!! + @Test public void test_setting_rank_feature_values() { // Check initializing from query Query query = new Query("?query=test&ranking.properties.foo=bar1&ranking.properties.foo2=bar2&ranking.properties.other=10"); @@ -69,6 +71,7 @@ public class RankingTestCase extends junit.framework.TestCase { } /** Test setting sorting to null does not cause an exception. */ + @Test public void testResetSorting() { Query q=new Query(); q.getRanking().setSorting((Sorting)null); diff --git a/container-search/src/test/java/com/yahoo/search/query/textserialize/item/test/ParseItemTestCase.java b/container-search/src/test/java/com/yahoo/search/query/textserialize/item/test/ParseItemTestCase.java index 8d4d4baccbb..7208626253c 100644 --- a/container-search/src/test/java/com/yahoo/search/query/textserialize/item/test/ParseItemTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/textserialize/item/test/ParseItemTestCase.java @@ -10,15 +10,16 @@ import org.junit.Test; import java.io.StringReader; -import static junit.framework.Assert.assertNull; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; /** * @author tonytv */ public class ParseItemTestCase { + public static Object parse(String input) throws ParseException { ItemContext context = new ItemContext(); Object result = new Parser(new StringReader(input.replace("'", "\"")), new ItemFormHandler(), context).start(); diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/BooleanAttributeParserTest.java b/container-search/src/test/java/com/yahoo/search/querytransform/BooleanAttributeParserTest.java index 7900ec471e8..8bf41c1cf64 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/BooleanAttributeParserTest.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/BooleanAttributeParserTest.java @@ -7,19 +7,16 @@ import org.junit.Test; import java.math.BigInteger; import java.util.Iterator; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** - * Created with IntelliJ IDEA. - * User: magnarn - * Date: 2/5/13 - * Time: 3:52 PM + * @author magnarn */ public class BooleanAttributeParserTest { @Test - public void requireThatParseHandlesAllFormats() throws Exception { + public void requireThatParseHandlesAllFormats() { assertParse(null, 0); assertParse("{}", 0); assertParse("{foo:bar}", 1); @@ -40,7 +37,7 @@ public class BooleanAttributeParserTest { } @Test - public void requireThatIllegalStringsFail() throws Exception { + public void requireThatIllegalStringsFail() { assertException("{foo:[bar:[baz]}"); assertException("{foo:[bar:baz}"); assertException("{foo:bar:[0,1,2}"); @@ -63,7 +60,7 @@ public class BooleanAttributeParserTest { } @Test - public void requireThatTermsCanHaveBitmaps() throws Exception { + public void requireThatTermsCanHaveBitmaps() { PredicateQueryItem q = assertParse("{foo:bar:0x1}", 1); PredicateQueryItem.Entry[] features = new PredicateQueryItem.Entry[q.getFeatures().size()]; q.getFeatures().toArray(features); @@ -98,4 +95,5 @@ public class BooleanAttributeParserTest { assertEquals(numFeatures, item.getFeatures().size()); return item; } + } diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/BooleanSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/BooleanSearcherTestCase.java index 952f002a1d1..03b32831886 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/BooleanSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/BooleanSearcherTestCase.java @@ -13,7 +13,7 @@ import org.junit.Test; import java.util.Collection; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertEquals; /** * Test BooleanSearcher @@ -118,4 +118,5 @@ public class BooleanSearcherTestCase { } return q; } + } diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/LegacyCombinatorTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/LegacyCombinatorTestCase.java index 502f7f21d8f..4796937eb65 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/LegacyCombinatorTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/LegacyCombinatorTestCase.java @@ -5,8 +5,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import junit.framework.TestCase; - import com.yahoo.container.protect.Error; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.query.AndItem; @@ -14,19 +12,28 @@ import com.yahoo.prelude.query.WordItem; import com.yahoo.search.Query; import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * Unit testing of the searcher com.yahoo.search.querytransform.LegacyCombinator. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class LegacyCombinatorTestCase extends TestCase { +public class LegacyCombinatorTestCase { + Searcher searcher; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { searcher = new LegacyCombinator(); } + @Test public void testStraightForwardSearch() { Query q = new Query("?query=a&query.juhu=b"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -46,6 +53,7 @@ public class LegacyCombinatorTestCase extends TestCase { assertEquals("AND a c b", q.getModel().getQueryTree().toString()); } + @Test public void testNoBaseQuery() { Query q = new Query("?query.juhu=b"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -53,6 +61,7 @@ public class LegacyCombinatorTestCase extends TestCase { assertEquals("b", q.getModel().getQueryTree().toString()); } + @Test public void testIncompatibleNewAndOldQuery() { Query q = new Query("?query.juhu=b&defidx.juhu=a&query.juhu.defidx=c"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -63,6 +72,7 @@ public class LegacyCombinatorTestCase extends TestCase { Error.INVALID_QUERY_PARAMETER.code, q.errors().get(0).getCode()); } + @Test public void testNotCombinatorWithoutRoot() { Query q = new Query("?query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=not"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -74,6 +84,7 @@ public class LegacyCombinatorTestCase extends TestCase { Error.INVALID_QUERY_PARAMETER.code, q.errors().get(0).getCode()); } + @Test public void testRankCombinator() { Query q = new Query("?query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=rank"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -81,6 +92,7 @@ public class LegacyCombinatorTestCase extends TestCase { assertEquals("nalle:b", q.getModel().getQueryTree().toString()); } + @Test public void testRankAndNot() { Query q = new Query("?query.yahoo=2&query.yahoo.defidx=1&query.yahoo.operator=not&query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=rank"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -88,6 +100,7 @@ public class LegacyCombinatorTestCase extends TestCase { assertEquals("+nalle:b -1:2", q.getModel().getQueryTree().toString()); } + @Test public void testReqAndRankAndNot() { Query q = new Query("?query.yahoo=2&query.yahoo.defidx=1&query.yahoo.operator=not&query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=rank&query.bamse=z&query.bamse.defidx=y"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -95,6 +108,7 @@ public class LegacyCombinatorTestCase extends TestCase { assertEquals("+(RANK y:z nalle:b) -1:2", q.getModel().getQueryTree().toString()); } + @Test public void testReqAndRank() { Query q = new Query("?query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=rank&query.bamse=z&query.bamse.defidx=y"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -102,6 +116,7 @@ public class LegacyCombinatorTestCase extends TestCase { assertEquals("RANK y:z nalle:b", q.getModel().getQueryTree().toString()); } + @Test public void testReqAndNot() { Query q = new Query("?query.juhu=b&query.juhu.defidx=nalle&query.juhu.operator=not&query.bamse=z&query.bamse.defidx=y"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -109,6 +124,7 @@ public class LegacyCombinatorTestCase extends TestCase { assertEquals("+y:z -nalle:b", q.getModel().getQueryTree().toString()); } + @Test public void testNewAndOld() { Query q = new Query("?query.juhu=b&defidx.juhu=nalle&query.bamse=z&query.bamse.defidx=y"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -125,13 +141,14 @@ public class LegacyCombinatorTestCase extends TestCase { nastierItems.remove(asPair); } else { assertFalse("Got unexpected item in query tree: (" - + word.getIndexName() + ", " + word.stringValue() + ")", - true); + + word.getIndexName() + ", " + word.stringValue() + ")", + true); } } assertEquals("Not all expected items found in query.", 0, nastierItems.size()); } + @Test public void testReqAndNotWithQuerySyntaxAll() { Query q = new Query("?query.juhu=b+c&query.juhu.defidx=nalle&query.juhu.operator=not&query.juhu.type=any&query.bamse=z&query.bamse.defidx=y"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -139,6 +156,7 @@ public class LegacyCombinatorTestCase extends TestCase { assertEquals("+y:z -(OR nalle:b nalle:c)", q.getModel().getQueryTree().toString()); } + @Test public void testDefaultIndexWithoutQuery() { Query q = new Query("?defidx.juhu=b"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -151,6 +169,7 @@ public class LegacyCombinatorTestCase extends TestCase { } private static class StringPair { + public final String index; public final String value; @@ -193,6 +212,7 @@ public class LegacyCombinatorTestCase extends TestCase { } + @Test public void testMultiPart() { Query q = new Query("?query=a&query.juhu=b&query.nalle=c"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -238,8 +258,6 @@ public class LegacyCombinatorTestCase extends TestCase { } } assertEquals("Not all expected items found in query.", 0, nastierItems.size()); - } - } diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/WandSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/WandSearcherTestCase.java index 8f89290a794..be6256c1711 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/WandSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/WandSearcherTestCase.java @@ -4,7 +4,14 @@ package com.yahoo.search.querytransform; import com.yahoo.component.chain.Chain; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; -import com.yahoo.prelude.query.*; +import com.yahoo.prelude.query.AndItem; +import com.yahoo.prelude.query.DotProductItem; +import com.yahoo.prelude.query.Item; +import com.yahoo.prelude.query.OrItem; +import com.yahoo.prelude.query.WandItem; +import com.yahoo.prelude.query.WeakAndItem; +import com.yahoo.prelude.query.WeightedSetItem; +import com.yahoo.prelude.query.WordItem; import com.yahoo.processing.request.ErrorMessage; import com.yahoo.search.Query; import com.yahoo.search.Result; @@ -16,10 +23,10 @@ import org.junit.Test; import java.util.ListIterator; import static com.yahoo.container.protect.Error.INVALID_QUERY_PARAMETER; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; /** * Testing of WandSearcher. @@ -27,9 +34,11 @@ import static org.junit.Assert.assertNotNull; public class WandSearcherTestCase { private static final String VESPA_FIELD = "vespa-field"; + private static final double delta = 0.0000001; private Execution exec; + @SuppressWarnings("deprecation") private IndexFacts buildIndexFacts() { IndexFacts retval = new IndexFacts(); retval.addIndex("test", new Index(VESPA_FIELD)); @@ -201,8 +210,8 @@ public class WandSearcherTestCase { WandItem root = (WandItem)TestUtils.getQueryTreeRoot(r); assertEquals(VESPA_FIELD, root.getIndexName()); assertEquals(100, root.getTargetNumHits()); - assertEquals(0.0, root.getScoreThreshold()); - assertEquals(1.0, root.getThresholdBoostFactor()); + assertEquals(0.0, root.getScoreThreshold(), delta); + assertEquals(1.0, root.getThresholdBoostFactor(), delta); assertWeightedSetItem(root); } @@ -214,8 +223,8 @@ public class WandSearcherTestCase { WandItem root = (WandItem)TestUtils.getQueryTreeRoot(r); assertEquals(VESPA_FIELD, root.getIndexName()); assertEquals(50, root.getTargetNumHits()); - assertEquals(70.5, root.getScoreThreshold()); - assertEquals(2.3, root.getThresholdBoostFactor()); + assertEquals(70.5, root.getScoreThreshold(), delta); + assertEquals(2.3, root.getThresholdBoostFactor(), delta); assertWeightedSetItem(root); } diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java index 80a52b55928..99b7eeff9a0 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java @@ -8,11 +8,9 @@ import java.util.Map; import com.yahoo.component.chain.Chain; import com.yahoo.language.Language; -import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; -import com.yahoo.prelude.IndexModel; import com.yahoo.prelude.hitfield.JSONString; import com.yahoo.prelude.hitfield.XMLString; import com.yahoo.prelude.query.AndItem; @@ -30,18 +28,23 @@ import com.yahoo.search.querytransform.NGramSearcher; import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; import com.yahoo.search.searchchain.Execution; +import org.junit.Before; +import org.junit.Test; import static com.yahoo.search.searchchain.Execution.Context.createContextStub; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author bratseth */ -public class NGramSearcherTestCase extends junit.framework.TestCase { +public class NGramSearcherTestCase { private Searcher searcher; private IndexFacts indexFacts; - @Override + @Before public void setUp() { searcher=new NGramSearcher(new SimpleLinguistics()); indexFacts=new IndexFacts(); @@ -88,6 +91,7 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { return indexFacts; } + @Test public void testMixedDocTypes() { final IndexFacts mixedSetup = getMixedSetup(); { @@ -117,6 +121,7 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { } } + @Test public void testMixedClusters() { final IndexFacts mixedSetup = getMixedSetup(); { @@ -141,41 +146,48 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { } } + @Test public void testClusterMappingWithMixedDoctypes() { final IndexFacts mixedSetup = getMixedSetup(); } + @Test public void testNGramRewritingMixedQuery() { Query q=new Query("?query=foo+gram3:engul+test:bar"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); assertEquals("AND foo (AND gram3:eng gram3:ngu gram3:gul) test:bar",q.getModel().getQueryTree().toString()); } + @Test public void testNGramRewritingNGramOnly() { Query q=new Query("?query=gram3:engul"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); assertEquals("AND gram3:eng gram3:ngu gram3:gul",q.getModel().getQueryTree().toString()); } + @Test public void testNGramRewriting2NGramsOnly() { Query q=new Query("?query=gram3:engul+gram2:123"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); assertEquals("AND (AND gram3:eng gram3:ngu gram3:gul) (AND gram2:12 gram2:23)",q.getModel().getQueryTree().toString()); } + @Test public void testNGramRewritingShortOnly() { Query q=new Query("?query=gram3:en"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); assertEquals("gram3:en",q.getModel().getQueryTree().toString()); } + @Test public void testNGramRewritingShortInMixes() { Query q=new Query("?query=test:a+gram3:en"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); assertEquals("AND test:a gram3:en",q.getModel().getQueryTree().toString()); } + @Test public void testNGramRewritingPhrase() { Query q=new Query("?query=gram3:%22engul+a+holi%22"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); @@ -186,12 +198,14 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { * Note that single-term phrases are simplified to just the term at parse time, * so the ngram rewriter cannot know to keep the grams as a phrase in this case. */ + @Test public void testNGramRewritingPhraseSingleTerm() { Query q=new Query("?query=gram3:%22engul%22"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); assertEquals("AND gram3:eng gram3:ngu gram3:gul",q.getModel().getQueryTree().toString()); } + @Test public void testNGramRewritingAdditionalTermInfo() { Query q=new Query("?query=gram3:engul!50+foo+gram2:123!150"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); @@ -214,23 +228,27 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { assertFalse(gram.isFromQuery()); } + @Test public void testNGramRewritingExplicitDefault() { Query q=new Query("?query=default:engul"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); assertEquals("AND default:eng default:ngu default:gul",q.getModel().getQueryTree().toString()); } + @Test public void testNGramRewritingImplicitDefault() { Query q=new Query("?query=engul"); new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); assertEquals("AND eng ngu gul",q.getModel().getQueryTree().toString()); } + @Test public void testGramsWithSegmentation() { assertGramsWithSegmentation(new Chain<>(searcher)); assertGramsWithSegmentation(new Chain<>(new CJKSearcher(),searcher)); assertGramsWithSegmentation(new Chain<>(searcher,new CJKSearcher())); } + public void assertGramsWithSegmentation(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("gram14:firstsecondthird", Query.Type.ANY); @@ -241,11 +259,13 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { assertEquals("AND gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird",q.getModel().getQueryTree().toString()); } + @Test public void testGramsWithSegmentationSingleSegment() { assertGramsWithSegmentationSingleSegment(new Chain<>(searcher)); assertGramsWithSegmentationSingleSegment(new Chain<>(new CJKSearcher(),searcher)); assertGramsWithSegmentationSingleSegment(new Chain<>(searcher,new CJKSearcher())); } + public void assertGramsWithSegmentationSingleSegment(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("gram14:first", Query.Type.ANY); @@ -256,11 +276,13 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { assertEquals("gram14:first",q.getModel().getQueryTree().toString()); } + @Test public void testGramsWithSegmentationSubstringSegmented() { assertGramsWithSegmentationSubstringSegmented(new Chain<>(searcher)); assertGramsWithSegmentationSubstringSegmented(new Chain<>(new CJKSearcher(),searcher)); assertGramsWithSegmentationSubstringSegmented(new Chain<>(searcher,new CJKSearcher())); } + public void assertGramsWithSegmentationSubstringSegmented(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("gram14:afirstsecondthirdo", Query.Type.ANY); @@ -271,11 +293,13 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { assertEquals("AND gram14:afirstsecondth gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird gram14:stsecondthirdo",q.getModel().getQueryTree().toString()); } + @Test public void testGramsWithSegmentationMixed() { assertGramsWithSegmentationMixed(new Chain<>(searcher)); assertGramsWithSegmentationMixed(new Chain<>(new CJKSearcher(),searcher)); assertGramsWithSegmentationMixed(new Chain<>(searcher,new CJKSearcher())); } + public void assertGramsWithSegmentationMixed(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("a gram14:afirstsecondthird b gram14:hi", Query.Type.ALL); @@ -286,11 +310,13 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { assertEquals("AND a (AND gram14:afirstsecondth gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird) b gram14:hi",q.getModel().getQueryTree().toString()); } + @Test public void testGramsWithSegmentationMixedAndPhrases() { assertGramsWithSegmentationMixedAndPhrases(new Chain<>(searcher)); assertGramsWithSegmentationMixedAndPhrases(new Chain<>(new CJKSearcher(),searcher)); assertGramsWithSegmentationMixedAndPhrases(new Chain<>(searcher,new CJKSearcher())); } + public void assertGramsWithSegmentationMixedAndPhrases(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("a gram14:\"afirstsecondthird b hi\"", Query.Type.ALL); @@ -301,6 +327,7 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { assertEquals("AND a gram14:\"afirstsecondth firstsecondthi irstsecondthir rstsecondthird b hi\"",q.getModel().getQueryTree().toString()); } + @Test public void testNGramRecombining() { Query q=new Query("?query=ignored"); Result r=new Execution(new Chain<>(searcher,new MockBackend1()),createContextStub(indexFacts)).search(q); @@ -364,6 +391,4 @@ public class NGramSearcherTestCase extends junit.framework.TestCase { } - - } diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/test/QueryCombinatorTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/test/QueryCombinatorTestCase.java index e2cbe500191..995c1cc7a72 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/test/QueryCombinatorTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/test/QueryCombinatorTestCase.java @@ -14,25 +14,28 @@ import com.yahoo.search.Searcher; import com.yahoo.search.querytransform.QueryCombinator; import com.yahoo.search.searchchain.Execution; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** * Unit testing of the searcher com.yahoo.search.querytransform.QueryCombinator. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class QueryCombinatorTestCase extends TestCase { +public class QueryCombinatorTestCase { + Searcher searcher; - protected void setUp() throws Exception { - super.setUp(); + @Before + @SuppressWarnings("deprecation") + public void setUp() throws Exception { searcher = new QueryCombinator(new ComponentId("combinationTest")); } - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testStraightForwardSearch() { Query q = new Query("?query=a&query.juhu=b"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -52,6 +55,7 @@ public class QueryCombinatorTestCase extends TestCase { assertEquals("AND a c b", q.getModel().getQueryTree().toString()); } + @Test public void testNoBaseQuery() { Query q = new Query("?query.juhu=b"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -59,6 +63,7 @@ public class QueryCombinatorTestCase extends TestCase { assertEquals("b", q.getModel().getQueryTree().toString()); } + @Test public void testDefaultIndexWithoutQuery() { Query q = new Query("?defidx.juhu=b"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -71,6 +76,7 @@ public class QueryCombinatorTestCase extends TestCase { } private static class StringPair { + public final String index; public final String value; @@ -113,6 +119,7 @@ public class QueryCombinatorTestCase extends TestCase { } + @Test public void testMultiPart() { Query q = new Query("?query=a&query.juhu=b&query.nalle=c"); Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())); @@ -158,8 +165,6 @@ public class QueryCombinatorTestCase extends TestCase { } } assertEquals("Not all expected items found in query.", 0, nastierItems.size()); - } - } diff --git a/container-search/src/test/java/com/yahoo/search/result/test/ArrayOutputTestCase.java b/container-search/src/test/java/com/yahoo/search/result/test/ArrayOutputTestCase.java index 6dec91382b6..11d163373ac 100644 --- a/container-search/src/test/java/com/yahoo/search/result/test/ArrayOutputTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/result/test/ArrayOutputTestCase.java @@ -8,12 +8,16 @@ import com.yahoo.prelude.templates.test.TilingTestCase; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.result.Hit; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author bratseth */ -public class ArrayOutputTestCase extends junit.framework.TestCase { +public class ArrayOutputTestCase { + @Test public void testArrayOutput() throws IOException { Result r=new Result(new Query("?query=ignored")); Hit hit=new Hit("test"); diff --git a/container-search/src/test/java/com/yahoo/search/result/test/CoverageTestCase.java b/container-search/src/test/java/com/yahoo/search/result/test/CoverageTestCase.java index 8ac18c119d8..68399e6bfc4 100644 --- a/container-search/src/test/java/com/yahoo/search/result/test/CoverageTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/result/test/CoverageTestCase.java @@ -4,18 +4,24 @@ package com.yahoo.search.result.test; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.result.Coverage; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; /** - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class CoverageTestCase extends junit.framework.TestCase { +public class CoverageTestCase { + @Test public void testZeroCoverage() { Coverage c = new Coverage(0L, 0, false, 0); assertEquals(0, c.getResultPercentage()); assertEquals(0, c.getResultSets()); } + @Test public void testActiveCoverage() { Coverage c = new Coverage(6, 5); assertEquals(5, c.getActive()); @@ -27,6 +33,7 @@ public class CoverageTestCase extends junit.framework.TestCase { assertEquals(13, c.getDocs()); } + @Test public void testDefaultCoverage() { boolean create=true; @@ -38,6 +45,7 @@ public class CoverageTestCase extends junit.framework.TestCase { assertEquals(0,r1.getCoverage(create).getResultSets()); } + @Test public void testDefaultSearchScenario() { boolean create=true; @@ -48,6 +56,7 @@ public class CoverageTestCase extends junit.framework.TestCase { assertEquals(0,federationSearcherResult.getCoverage(create).getResultSets()); } + @Test public void testRequestingCoverageSearchScenario() { boolean create=true; diff --git a/container-search/src/test/java/com/yahoo/search/result/test/DeepHitIteratorTestCase.java b/container-search/src/test/java/com/yahoo/search/result/test/DeepHitIteratorTestCase.java index 7d18c64a531..a46b15b525c 100644 --- a/container-search/src/test/java/com/yahoo/search/result/test/DeepHitIteratorTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/result/test/DeepHitIteratorTestCase.java @@ -7,14 +7,21 @@ import java.util.NoSuchElementException; import com.yahoo.search.result.DeepHitIterator; import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; +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; /** * Ensure that the {@link DeepHitIterator} works as intended. * - * @author havardpe + * @author havardpe */ -public class DeepHitIteratorTestCase extends junit.framework.TestCase { +public class DeepHitIteratorTestCase { + @Test public void testEmpty() { HitGroup hits = new HitGroup(); Iterator<Hit> it = hits.deepIterator(); @@ -27,6 +34,7 @@ public class DeepHitIteratorTestCase extends junit.framework.TestCase { } } + @Test public void testRemove() { HitGroup hits = new HitGroup(); hits.add(new Hit("foo")); @@ -53,6 +61,7 @@ public class DeepHitIteratorTestCase extends junit.framework.TestCase { assertFalse(it.hasNext()); } + @Test public void testShallow() { HitGroup hits = new HitGroup(); hits.add(new Hit("foo")); @@ -69,6 +78,7 @@ public class DeepHitIteratorTestCase extends junit.framework.TestCase { assertFalse(it.hasNext()); } + @Test public void testDeep() { HitGroup grandParent = new HitGroup(); grandParent.add(new Hit("a")); @@ -103,6 +113,7 @@ public class DeepHitIteratorTestCase extends junit.framework.TestCase { assertFalse(it.hasNext()); } + @Test public void testFirstHitIsGroup() { HitGroup root = new HitGroup(); HitGroup group = new HitGroup(); @@ -118,6 +129,7 @@ public class DeepHitIteratorTestCase extends junit.framework.TestCase { assertFalse(it.hasNext()); } + @Test public void testSecondHitIsGroup() { HitGroup root = new HitGroup(); root.add(new Hit("foo")); @@ -133,6 +145,7 @@ public class DeepHitIteratorTestCase extends junit.framework.TestCase { assertFalse(it.hasNext()); } + @Test public void testOrder() { HitGroup root = new HitGroup(); MyHitGroup group = new MyHitGroup(); @@ -169,4 +182,5 @@ public class DeepHitIteratorTestCase extends junit.framework.TestCase { return super.unorderedIterator(); } } + } diff --git a/container-search/src/test/java/com/yahoo/search/result/test/DefaultErrorHitTestCase.java b/container-search/src/test/java/com/yahoo/search/result/test/DefaultErrorHitTestCase.java index 29199cf3ef9..14e127ec72c 100644 --- a/container-search/src/test/java/com/yahoo/search/result/test/DefaultErrorHitTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/result/test/DefaultErrorHitTestCase.java @@ -4,16 +4,19 @@ package com.yahoo.search.result.test; import com.yahoo.prelude.templates.SearchRendererAdaptor; import com.yahoo.search.result.DefaultErrorHit; import com.yahoo.search.result.ErrorMessage; +import org.junit.Test; import java.io.IOException; import java.io.StringWriter; +import static org.junit.Assert.assertEquals; + /** * @author bratseth */ -public class DefaultErrorHitTestCase extends junit.framework.TestCase { +public class DefaultErrorHitTestCase { - @SuppressWarnings("null") + @Test public void testErrorHitRenderingWithException() throws IOException { NullPointerException cause=null; try { diff --git a/container-search/src/test/java/com/yahoo/search/result/test/FillingTestCase.java b/container-search/src/test/java/com/yahoo/search/result/test/FillingTestCase.java index 4a0e8a0a88c..01383ba29f2 100644 --- a/container-search/src/test/java/com/yahoo/search/result/test/FillingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/result/test/FillingTestCase.java @@ -3,12 +3,17 @@ package com.yahoo.search.result.test; import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author bratseth */ -public class FillingTestCase extends junit.framework.TestCase { +public class FillingTestCase { + @Test public void testFillingAPIConsistency() { HitGroup group=new HitGroup(); group.add(new Hit("hit:1")); @@ -16,6 +21,7 @@ public class FillingTestCase extends junit.framework.TestCase { assertTrue(group.isFilled("summary")); } + @Test public void testFillingAPIConsistencyTwoPhase() { HitGroup group=new HitGroup(); group.add(createNonFilled("hit:1")); @@ -26,6 +32,7 @@ public class FillingTestCase extends junit.framework.TestCase { assertTrue(group.isFilled("summary")); // consistent again } + @Test public void testFillingAPIConsistencyThreePhase() { HitGroup group=new HitGroup(); group.add(createNonFilled("hit:1")); diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionOfOneChainTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionOfOneChainTestCase.java index 44d5dc29a2d..182ec7568f3 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionOfOneChainTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionOfOneChainTestCase.java @@ -10,19 +10,24 @@ import com.yahoo.search.result.HitGroup; import com.yahoo.search.searchchain.AsyncExecution; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.FutureResult; -import junit.framework.TestCase; +import org.junit.Test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import static org.junit.Assert.assertEquals; + /** * @author bratseth */ -public class AsyncExecutionOfOneChainTestCase extends TestCase { +public class AsyncExecutionOfOneChainTestCase { + + private static final double delta = 0.0000001; /** Tests having a result with some slow source data which should pass directly to rendering */ + @Test public void testParallelExecutionOfOneChain() { // Setup Chain<Searcher> mainChain=new Chain<>(new ParallelExecutor(),new ResultProcessor(),new RegularProvider()); @@ -32,12 +37,12 @@ public class AsyncExecutionOfOneChainTestCase extends TestCase { // Verify assertEquals("Received 2 hits from 3 threads",3*2,result.hits().size()); - assertEquals(1.0, result.hits().get("thread-0:hit-0").getRelevance().getScore()); - assertEquals(1.0, result.hits().get("thread-1:hit-0").getRelevance().getScore()); - assertEquals(1.0, result.hits().get("thread-2:hit-0").getRelevance().getScore()); - assertEquals(0.5, result.hits().get("thread-0:hit-1").getRelevance().getScore()); - assertEquals(0.5, result.hits().get("thread-1:hit-1").getRelevance().getScore()); - assertEquals(0.5, result.hits().get("thread-2:hit-1").getRelevance().getScore()); + assertEquals(1.0, result.hits().get("thread-0:hit-0").getRelevance().getScore(), delta); + assertEquals(1.0, result.hits().get("thread-1:hit-0").getRelevance().getScore(), delta); + assertEquals(1.0, result.hits().get("thread-2:hit-0").getRelevance().getScore(), delta); + assertEquals(0.5, result.hits().get("thread-0:hit-1").getRelevance().getScore(), delta); + assertEquals(0.5, result.hits().get("thread-1:hit-1").getRelevance().getScore(), delta); + assertEquals(0.5, result.hits().get("thread-2:hit-1").getRelevance().getScore(), delta); } private class ParallelExecutor extends Searcher { diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionTestCase.java index c5d756e81e1..9ea637a5554 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionTestCase.java @@ -10,17 +10,24 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.AsyncExecution; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.FutureResult; +import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + /** * Test for aynchrounous execution - * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a> + * + * @author Arne Bergene Fossaa */ -public class AsyncExecutionTestCase extends junit.framework.TestCase { +public class AsyncExecutionTestCase { public class WaitingSearcher extends Searcher { @@ -50,7 +57,8 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { } - //This should take ~50+ ms + // This should take ~50+ ms + @Test public void testAsync() { List<Searcher> searchList = new ArrayList<>(); searchList.add(new WaitingSearcher("one",60000)); @@ -64,6 +72,7 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { assertTrue(result.hits().getError() != null); } + @Test public void testWaitForAll() { Chain<Searcher> slowChain = new Chain<>( new ComponentId("slow"), @@ -89,6 +98,7 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { assertNull(results.get(1).hits().getErrorHit()); } + @Test public void testSync() { Query query=new Query("?query=test"); Searcher searcher=new ResultProducingSearcher(); @@ -98,6 +108,7 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { assertEquals("hello",result.hits().get(0).getField("test")); } + @Test public void testSyncThroughSync() { Query query=new Query("?query=test"); Searcher searcher=new ResultProducingSearcher(); @@ -107,6 +118,7 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { assertEquals("hello",result.hits().get(0).getField("test")); } + @Test public void testAsyncThroughSync() { Query query=new Query("?query=test"); Searcher searcher=new ResultProducingSearcher(); @@ -134,7 +146,6 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { } - @SuppressWarnings("deprecation") public void testAsyncExecutionTimeout() { Chain<Searcher> chain = new Chain<>(new Searcher() { @Override diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/test/ExecutionTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/test/ExecutionTestCase.java index fb9af72a715..c3ccccdc5be 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/test/ExecutionTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/test/ExecutionTestCase.java @@ -19,14 +19,21 @@ 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; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + /** * Tests basic search chain execution functionality * * @author bratseth */ -@SuppressWarnings("deprecation") -public class ExecutionTestCase extends junit.framework.TestCase { +public class ExecutionTestCase { + @Test public void testLinearExecutions() { // Make a chain List<Searcher> searchers1=new ArrayList<>(); @@ -58,6 +65,7 @@ public class ExecutionTestCase extends junit.framework.TestCase { assertNotNull(result2.hits().get("searcher6-1")); } + @Test public void testNestedExecution() { // Make a chain List<Searcher> searchers1=new ArrayList<>(); @@ -81,6 +89,7 @@ public class ExecutionTestCase extends junit.framework.TestCase { assertNotNull(result1.hits().get("searcher3-2-filled")); } + @Test public void testContextCacheSingleLengthSearchChain() { IndexFacts[] contextsBefore = new IndexFacts[1]; IndexFacts[] contextsAfter = new IndexFacts[1]; @@ -93,6 +102,7 @@ public class ExecutionTestCase extends junit.framework.TestCase { assertSame(contextsBefore[0], contextsAfter[0]); } + @Test public void testContextCache() { IndexFacts[] contextsBefore = new IndexFacts[5]; IndexFacts[] contextsAfter = new IndexFacts[5]; @@ -118,6 +128,7 @@ public class ExecutionTestCase extends junit.framework.TestCase { assertSame(contextsBefore[3], contextsBefore[4]); } + @Test public void testContextCacheMoreSearchers() { IndexFacts[] contextsBefore = new IndexFacts[7]; IndexFacts[] contextsAfter = new IndexFacts[7]; @@ -299,5 +310,4 @@ public class ExecutionTestCase extends junit.framework.TestCase { } - } diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/test/VespaAsyncSearcherTest.java b/container-search/src/test/java/com/yahoo/search/searchchain/test/VespaAsyncSearcherTest.java index 9c7be743460..567b73783b1 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/test/VespaAsyncSearcherTest.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/test/VespaAsyncSearcherTest.java @@ -8,17 +8,18 @@ import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.AsyncExecution; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.FutureResult; +import org.junit.Test; + import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - /** * Externally provided test for async execution of search chains. * - * @author <a href="mailto:pthomas@yahoo-inc.com">Peter Thomas</a> + * @author Peter Thomas */ -public class VespaAsyncSearcherTest extends TestCase { +public class VespaAsyncSearcherTest { + private static class FirstSearcher extends Searcher { @Override @@ -46,13 +47,13 @@ public class VespaAsyncSearcherTest extends TestCase { } + @Test public void testAsyncExecution() { - Chain<Searcher> chain = new Chain<>(new FirstSearcher(), - new SecondSearcher()); - Execution execution = new Execution(chain, - Execution.Context.createContextStub(null)); + Chain<Searcher> chain = new Chain<>(new FirstSearcher(), new SecondSearcher()); + Execution execution = new Execution(chain, Execution.Context.createContextStub(null)); Query query = new Query(); // fails with exception on old versions execution.search(query); } + } diff --git a/container-search/src/test/java/com/yahoo/search/searchers/test/CacheControlSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/searchers/test/CacheControlSearcherTestCase.java index 14fc0da7d02..89ca224682d 100644 --- a/container-search/src/test/java/com/yahoo/search/searchers/test/CacheControlSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchers/test/CacheControlSearcherTestCase.java @@ -9,6 +9,7 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchers.CacheControlSearcher; import junit.framework.TestCase; +import org.junit.Test; import java.util.List; @@ -19,7 +20,6 @@ import static com.yahoo.search.searchers.CacheControlSearcher.CACHE_CONTROL_HEAD * * @author frodelu */ -@SuppressWarnings("deprecation") public class CacheControlSearcherTestCase extends TestCase { private Searcher getDocSource() { @@ -60,6 +60,7 @@ public class CacheControlSearcherTestCase extends TestCase { } } + @Test public void testNoHeader() { Chain<Searcher> chain = getSearchChain(); Query query = new Query("?query=foo&custid=foo"); @@ -67,6 +68,7 @@ public class CacheControlSearcherTestCase extends TestCase { assertEquals(0, getCacheControlHeaders(result).size()); } + @Test public void testInvalidAgeParams() { Chain<Searcher> chain = getSearchChain(); @@ -91,6 +93,7 @@ public class CacheControlSearcherTestCase extends TestCase { } } + @Test public void testMaxAge() { Chain<Searcher> chain = getSearchChain(); @@ -99,6 +102,7 @@ public class CacheControlSearcherTestCase extends TestCase { assertCacheHeaders(new String[]{"max-age=120"}, getCacheControlHeaders(result)); } + @Test public void testNoCache() { Chain<Searcher> chain = getSearchChain(); @@ -111,6 +115,7 @@ public class CacheControlSearcherTestCase extends TestCase { assertCacheHeaders(new String[]{"no-cache"}, getCacheControlHeaders(result)); } + @Test public void testStateWhileRevalidate() { Chain<Searcher> chain = getSearchChain(); @@ -119,6 +124,7 @@ public class CacheControlSearcherTestCase extends TestCase { assertCacheHeaders(new String[]{"stale-while-revalidate=3600"}, getCacheControlHeaders(result)); } + @Test public void testStaleAndMaxAge() { Chain<Searcher> chain = getSearchChain(); diff --git a/container-search/src/test/java/com/yahoo/search/statistics/ElapsedTimeTestCase.java b/container-search/src/test/java/com/yahoo/search/statistics/ElapsedTimeTestCase.java index 42a6a7e00d0..e9bb2365de1 100644 --- a/container-search/src/test/java/com/yahoo/search/statistics/ElapsedTimeTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/statistics/ElapsedTimeTestCase.java @@ -10,17 +10,20 @@ import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; -import com.yahoo.search.statistics.ElapsedTime; -import com.yahoo.search.statistics.TimeTracker; import com.yahoo.search.statistics.TimeTracker.Activity; import com.yahoo.search.statistics.TimeTracker.SearcherTimer; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * Check sanity of TimeTracker and ElapsedTime. * - * @author <a href="steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class ElapsedTimeTestCase extends TestCase { +public class ElapsedTimeTestCase { private static final long[] SEARCH_TIMESEQUENCE = new long[] { 1L, 2L, 3L, 4L, 5L, 6L, 7L }; @@ -137,6 +140,7 @@ public class ElapsedTimeTestCase extends TestCase { } } + @Test public void testBasic() { TimeTracker t = new TimeTracker(null); t.injectTimeSource(new CreativeTimeSource(new long[] {1L, 2L, 3L, 4L})); @@ -155,6 +159,7 @@ public class ElapsedTimeTestCase extends TestCase { assertEquals(3L, t.totalTime()); } + @Test public void testMultiSearchAndPing() { TimeTracker t = new TimeTracker(null); t.injectTimeSource(new CreativeTimeSource(new long[] {1L, 4L, 16L, 32L, 64L, 128L, 256L})); @@ -193,6 +198,7 @@ public class ElapsedTimeTestCase extends TestCase { assertEquals(2L, e.firstFill()); } + @Test public void testBasicBreakdown() { TimeTracker t = new TimeTracker(new Chain<Searcher>( new UselessSearcher("first"), new UselessSearcher("second"), @@ -212,6 +218,7 @@ public class ElapsedTimeTestCase extends TestCase { // This test is to make sure the other tests correctly simulate the call // order into the TimeTracker + @Test public void testBasicBreakdownFullyWiredIn() { Chain<? extends Searcher> chain = new Chain<Searcher>( new UselessSearcher("first"), new UselessSearcher("second"), @@ -238,6 +245,7 @@ public class ElapsedTimeTestCase extends TestCase { assertEquals(Long.valueOf(1L), searchers[0 + offset].getReturning(Activity.SEARCH)); } + @Test public void testBasicBreakdownWithFillFullyWiredIn() { Chain<? extends Searcher> chain = new Chain<>( new UselessSearcher("first"), new UselessSearcher("second"), @@ -266,6 +274,7 @@ public class ElapsedTimeTestCase extends TestCase { assertEquals(Long.valueOf(1L), searchers[0 + offset].getReturning(Activity.FILL)); } + @Test public void testBasicBreakdownFullyWiredInFirstSearcherNotFirstInChain() { Chain<? extends Searcher> chain = new Chain<>( new TestingSearcher(), @@ -275,6 +284,7 @@ public class ElapsedTimeTestCase extends TestCase { exec.search(new Query()); } + @Test public void testBasicBreakdownWithFillFullyWiredInFirstSearcherNotFirstInChain() { Chain<? extends Searcher> chain = new Chain<>( new SecondTestingSearcher(), @@ -284,6 +294,7 @@ public class ElapsedTimeTestCase extends TestCase { exec.search(new Query()); } + @Test public void testTimingWithShortChain() { Chain<? extends Searcher> chain = new Chain<>( new ShortChainTestingSearcher(), @@ -292,6 +303,7 @@ public class ElapsedTimeTestCase extends TestCase { exec.search(new Query()); } + @Test public void testBasicBreakdownReturnInsideSearchChain() { TimeTracker t = new TimeTracker(new Chain<Searcher>( new UselessSearcher("first"), new UselessSearcher("second"), @@ -313,6 +325,7 @@ public class ElapsedTimeTestCase extends TestCase { assertEquals(Long.valueOf(1L) ,searchers[0].getReturning(Activity.SEARCH)); } + @Test public void testBasicBreakdownWithFill() { TimeTracker t = new TimeTracker(new Chain<Searcher>( new UselessSearcher("first"), new UselessSearcher("second"), @@ -343,7 +356,6 @@ public class ElapsedTimeTestCase extends TestCase { assertEquals(Long.valueOf(1L), searchers[0].getReturning(Activity.FILL)); } - private void runSomeTraffic(TimeTracker t) { t.injectTimeSource(new CreativeTimeSource(new long[] { 1L, 2L, 3L, @@ -383,6 +395,7 @@ public class ElapsedTimeTestCase extends TestCase { t.sampleSearchReturn(0, true, null); } + @Test public void testMixedActivity() { TimeTracker t = new TimeTracker(new Chain<Searcher>( new UselessSearcher("first"), new UselessSearcher("second"), @@ -406,6 +419,7 @@ public class ElapsedTimeTestCase extends TestCase { assertNull(searchers[2].getReturning(Activity.FILL)); } + @Test public void testReportGeneration() { TimeTracker t = new TimeTracker(new Chain<Searcher>( new UselessSearcher("first"), new UselessSearcher("second"), @@ -430,4 +444,5 @@ public class ElapsedTimeTestCase extends TestCase { public static void doInjectTimeSource(TimeTracker t, TimeTracker.TimeSource s) { t.injectTimeSource(s); } + } diff --git a/container-search/src/test/java/com/yahoo/search/statistics/TimingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/statistics/TimingSearcherTestCase.java index fabd8ed9fa3..acdfd6370d6 100644 --- a/container-search/src/test/java/com/yahoo/search/statistics/TimingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/statistics/TimingSearcherTestCase.java @@ -1,8 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.statistics; -import junit.framework.TestCase; - import com.yahoo.component.ComponentId; import com.yahoo.prelude.Ping; import com.yahoo.search.Query; @@ -12,8 +10,12 @@ import com.yahoo.search.searchchain.Execution; import com.yahoo.search.statistics.TimingSearcher.Parameters; import com.yahoo.statistics.Statistics; import com.yahoo.statistics.Value; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class TimingSearcherTestCase { -public class TimingSearcherTestCase extends TestCase { public static class MockValue extends Value { public int putCount = 0; @@ -27,6 +29,7 @@ public class TimingSearcherTestCase extends TestCase { } } + @Test public void testMeasurementSearchPath() { Parameters p = new Parameters("timingtest", TimeTracker.Activity.SEARCH); TimingSearcher ts = new TimingSearcher(new ComponentId("lblblbl"), p, Statistics.nullImplementation); @@ -45,6 +48,7 @@ public class TimingSearcherTestCase extends TestCase { assertEquals(1, v.putCount); } + @Test public void testMeasurementFillPath() { Parameters p = new Parameters("timingtest", TimeTracker.Activity.FILL); TimingSearcher ts = new TimingSearcher(new ComponentId("lblblbl"), p, Statistics.nullImplementation); @@ -63,6 +67,7 @@ public class TimingSearcherTestCase extends TestCase { assertEquals(2, v.putCount); } + @Test public void testMeasurementPingPath() { Parameters p = new Parameters("timingtest", TimeTracker.Activity.PING); TimingSearcher ts = new TimingSearcher(new ComponentId("lblblbl"), p, Statistics.nullImplementation); @@ -80,4 +85,5 @@ public class TimingSearcherTestCase extends TestCase { exec.ping(new Ping()); assertEquals(3, v.putCount); } + } diff --git a/container-search/src/test/java/com/yahoo/search/test/RequestParameterPreservationTestCase.java b/container-search/src/test/java/com/yahoo/search/test/RequestParameterPreservationTestCase.java index 3f2d67083a9..fda3d4144ea 100644 --- a/container-search/src/test/java/com/yahoo/search/test/RequestParameterPreservationTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/RequestParameterPreservationTestCase.java @@ -2,12 +2,16 @@ package com.yahoo.search.test; import com.yahoo.search.Query; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author bratseth */ -public class RequestParameterPreservationTestCase extends junit.framework.TestCase { +public class RequestParameterPreservationTestCase { + @Test public void testPreservation() { Query query=new Query("?query=test...&offset=15&hits=10"); query.setWindow(25,13); diff --git a/container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java b/container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java index a947e46a40e..4427d5856d8 100644 --- a/container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java +++ b/container-search/src/test/java/com/yahoo/text/interpretation/test/AnnotationTestCase.java @@ -7,18 +7,23 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import junit.framework.TestCase; - import com.yahoo.text.interpretation.AnnotationClass; import com.yahoo.text.interpretation.Annotations; import com.yahoo.text.interpretation.Interpretation; import com.yahoo.text.interpretation.Span; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** - * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a> + * @author Arne Bergene Fossaa */ -public class AnnotationTestCase extends TestCase { +public class AnnotationTestCase { + @Test public void testSimpleAnnotations() { Interpretation i= new Interpretation("new york hotel"); i.annotate("sentence").put("isValid",true); @@ -31,6 +36,7 @@ public class AnnotationTestCase extends TestCase { assertNotNull(i.get("sentence")); } + @Test public void testAnnotationAPI() { Interpretation a = new Interpretation("new york hotel"); @@ -80,6 +86,7 @@ public class AnnotationTestCase extends TestCase { } //The following testcase is a test with the api on a use_case, no cornercases here + @Test public void testUsability() { Interpretation interpretation = new Interpretation("new york crab pizza"); @@ -118,6 +125,6 @@ public class AnnotationTestCase extends TestCase { assertEquals(2459115,woe_id); } - } + } diff --git a/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/ListMergerTestCase.java b/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/ListMergerTestCase.java index 5fb4232eca3..732ad5c1f5d 100644 --- a/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/ListMergerTestCase.java +++ b/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/ListMergerTestCase.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.vespa.streamingvisitors; -import com.yahoo.vespa.streamingvisitors.ListMerger; +import org.junit.Test; import java.util.List; import java.util.LinkedList; +import static org.junit.Assert.assertEquals; + /** - * @author <a href="mailto:ulf@yahoo-inc.com">Ulf Carlin</a> + * @author Ulf Carlin */ -public class ListMergerTestCase extends junit.framework.TestCase { +public class ListMergerTestCase { + private void initializeLists(List<String> list1, List<String> list2, int entryCount, int padding) { for (int i = 0; i < entryCount; i++) { if ((i % 2) == 0) { @@ -27,6 +30,7 @@ public class ListMergerTestCase extends junit.framework.TestCase { } } + @Test public void testMergeLists() { int entryCount = 6; int padding = (int)Math.log10(entryCount) + 1; @@ -45,6 +49,7 @@ public class ListMergerTestCase extends junit.framework.TestCase { verifyList(list1, entryCount/2, padding); } + @Test public void testMergeListsReversed() { int entryCount = 6; int padding = (int)Math.log10(entryCount) + 1; @@ -63,25 +68,4 @@ public class ListMergerTestCase extends junit.framework.TestCase { verifyList(list1, entryCount/2, padding); } - /* - public void testMergeListsPerformance() { - int entryCount = 2000000; // 2000000 - int padding = (int)Math.log10(entryCount) + 1; - - List<String> list1 = new LinkedList<String>(); - List<String> list2 = new LinkedList<String>(); - initializeLists(list1, list2, entryCount, padding); - - long startTime = System.currentTimeMillis(); - //List<String> newList = ListMerger.mergeIntoArrayList(list1, list2); - //List<String> newList = ListMerger.mergeIntoArrayList(list1, list2, entryCount/2); - ListMerger.mergeLinkedLists(list1, list2, entryCount); - //ListMerger.mergeLinkedLists(list1, list2, entryCount/2); - long endTime = System.currentTimeMillis(); - long elapsedTime = endTime - startTime; - double seconds = elapsedTime / 1.0E03; - System.out.println ("Elapsed Time = " + seconds + " seconds"); - //assertEquals(entryCount/2, newList.size()); - } - */ } diff --git a/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/MetricsSearcherTestCase.java b/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/MetricsSearcherTestCase.java index 469ce203c0b..13acd70b67d 100644 --- a/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/MetricsSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/vespa/streamingvisitors/MetricsSearcherTestCase.java @@ -11,7 +11,7 @@ import com.yahoo.search.searchchain.Execution; import com.yahoo.vdslib.VisitorStatistics; import org.junit.Test; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue; * @author Ulf Carlin */ public class MetricsSearcherTestCase { + private MetricsSearcher metricsSearcher = new MetricsSearcher(); private MockBackend backend = new MockBackend(); private Chain<Searcher> chain = new Chain<>(metricsSearcher, backend); @@ -139,4 +140,5 @@ public class MetricsSearcherTestCase { } } } + } |