diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-03-23 16:56:34 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-03-23 16:56:34 +0100 |
commit | f86aedaee7c84fff85bd97099b7e08db3e4d5313 (patch) | |
tree | afec2e7155e2a371ec53b8e2d87d0c0a5c9257a4 /config-model/src/test/java/com/yahoo/searchdefinition | |
parent | 6494e643950b07e2b45262e6d915e39771eb14b1 (diff) |
Simplify tests.
Diffstat (limited to 'config-model/src/test/java/com/yahoo/searchdefinition')
-rw-r--r-- | config-model/src/test/java/com/yahoo/searchdefinition/processing/DictionaryTestCase.java | 109 |
1 files changed, 48 insertions, 61 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/DictionaryTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/DictionaryTestCase.java index 9b3c02cecc3..256858b372e 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/DictionaryTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/DictionaryTestCase.java @@ -2,6 +2,7 @@ package com.yahoo.searchdefinition.processing; +import com.yahoo.config.model.test.TestUtil; import com.yahoo.searchdefinition.Search; import com.yahoo.searchdefinition.SearchBuilder; import com.yahoo.searchdefinition.derived.AttributeFields; @@ -25,79 +26,65 @@ public class DictionaryTestCase { attributes.getConfig(builder); return builder.build(); } + private Search createSearch(String def) throws ParseException { + SearchBuilder sb = SearchBuilder.createFromString(def); + return sb.getSearch(); + } @Test public void testDefaultDictionarySettings() throws ParseException { - String def = - "search test {\n" + - " document test {\n" + - " field s1 type string {\n" + - " indexing: attribute | summary\n" + - " }\n" + - "\n" + - " field n1 type int {\n" + - " indexing: summary | attribute\n" + - " }\n" + - " }\n" + - "}\n"; - SearchBuilder sb = SearchBuilder.createFromString(def); - Search search = sb.getSearch(); + String def = TestUtil.joinLines( + "search test {", + " document test {", + " field s1 type string {", + " indexing: attribute | summary", + " }", + " field n1 type int {", + " indexing: summary | attribute", + " }", + " }", + "}"); + Search search = createSearch(def); assertEquals(Dictionary.Type.BTREE, search.getAttribute("s1").getDictionary().getType()); assertEquals(Dictionary.Type.BTREE, search.getAttribute("n1").getDictionary().getType()); } + + void verifyNumericDictionaryControl(Dictionary.Type expected, + AttributesConfig.Attribute.Dictionary.Type.Enum expectedConfig, + String ... cfg) throws ParseException + { + String def = TestUtil.joinLines( + "search test {", + " document test {", + " field n1 type int {", + " indexing: summary | attribute", + " attribute:fast-search", + TestUtil.joinLines(cfg), + " }", + " }", + "}"); + Search search = createSearch(def); + assertEquals(expected, search.getAttribute("n1").getDictionary().getType()); + assertEquals(expectedConfig, + getConfig(search).attribute().get(0).dictionary().type()); + } + @Test public void testNumericBtreeSettings() throws ParseException { - String def = - "search test {\n" + - " document test {\n" + - " field n1 type int {\n" + - " indexing: summary | attribute\n" + - " attribute:fast-search\n" + - " dictionary:btree\n" + - " }\n" + - " }\n" + - "}\n"; - SearchBuilder sb = SearchBuilder.createFromString(def); - Search search = sb.getSearch(); - assertEquals(Dictionary.Type.BTREE, search.getAttribute("n1").getDictionary().getType()); - assertEquals(AttributesConfig.Attribute.Dictionary.Type.BTREE, - getConfig(search).attribute().get(0).dictionary().type()); + verifyNumericDictionaryControl(Dictionary.Type.BTREE, + AttributesConfig.Attribute.Dictionary.Type.BTREE, + "dictionary:btree"); } @Test public void testNumericHashSettings() throws ParseException { - String def = - "search test {\n" + - " document test {\n" + - " field n1 type int {\n" + - " indexing: summary | attribute\n" + - " attribute:fast-search\n" + - " dictionary:hash\n" + - " }\n" + - " }\n" + - "}\n"; - SearchBuilder sb = SearchBuilder.createFromString(def); - Search search = sb.getSearch(); - assertEquals(Dictionary.Type.HASH, search.getAttribute("n1").getDictionary().getType()); - assertEquals(AttributesConfig.Attribute.Dictionary.Type.HASH, - getConfig(search).attribute().get(0).dictionary().type()); + verifyNumericDictionaryControl(Dictionary.Type.HASH, + AttributesConfig.Attribute.Dictionary.Type.HASH, + "dictionary:hash"); } @Test public void testNumericBtreeAndHashSettings() throws ParseException { - String def = - "search test {\n" + - " document test {\n" + - " field n1 type int {\n" + - " indexing: summary | attribute\n" + - " attribute:fast-search\n" + - " dictionary:hash\n" + - " dictionary:btree\n" + - " }\n" + - " }\n" + - "}\n"; - SearchBuilder sb = SearchBuilder.createFromString(def); - Search search = sb.getSearch(); - assertEquals(Dictionary.Type.BTREE_AND_HASH, search.getAttribute("n1").getDictionary().getType()); - assertEquals(AttributesConfig.Attribute.Dictionary.Type.BTREE_AND_HASH, - getConfig(search).attribute().get(0).dictionary().type()); + verifyNumericDictionaryControl(Dictionary.Type.BTREE_AND_HASH, + AttributesConfig.Attribute.Dictionary.Type.BTREE_AND_HASH, + "dictionary:btree", "dictionary:hash"); } @Test public void testNonNumericFieldsFailsDictionaryControl() throws ParseException { @@ -132,7 +119,7 @@ public class DictionaryTestCase { SearchBuilder sb = SearchBuilder.createFromString(def); fail("Controlling dictionary for non-fast-search fields are not allowed."); } catch (IllegalArgumentException e) { - assertEquals("For search 'test', field 'n1': You must specify attribute:fast-search to allow dictionary control", e.getMessage()); + assertEquals("For search 'test', field 'n1': You must specify 'attribute:fast-search' to allow dictionary control", e.getMessage()); } } } |