diff options
author | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-28 14:44:47 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-28 14:51:35 +0200 |
commit | 695209a356ecae42536fd394189a98cf5274518e (patch) | |
tree | fff14a30ce9efde18a83d15ff08bbdb672119477 /config-model/src/test/java/com/yahoo/schema/processing | |
parent | 9dab1e67022884f6644b3d8c9b02c6b3c466a879 (diff) |
Convert config-model to junit5
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/processing')
49 files changed, 884 insertions, 900 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java b/config-model/src/test/java/com/yahoo/schema/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java index 0d64dd5c953..fe7edf5e433 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java @@ -17,11 +17,11 @@ import com.yahoo.schema.document.SDField; import com.yahoo.vespa.documentmodel.DocumentSummary; import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.vespa.documentmodel.SummaryTransform; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author bjorncs @@ -33,7 +33,7 @@ public class AddAttributeTransformToSummaryOfImportedFieldsTest { private static final String SUMMARY_NAME = "mysummary"; @Test - public void attribute_summary_transform_applied_to_summary_field_of_imported_field() { + void attribute_summary_transform_applied_to_summary_field_of_imported_field() { Schema schema = createSearchWithDocument(DOCUMENT_NAME); schema.setImportedFields(createSingleImportedField(IMPORTED_FIELD_NAME)); schema.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME, schema)); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/AdjustPositionSummaryFieldsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/AdjustPositionSummaryFieldsTestCase.java index 103d08b39a8..06d6e347f29 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/AdjustPositionSummaryFieldsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/AdjustPositionSummaryFieldsTestCase.java @@ -7,19 +7,14 @@ import com.yahoo.schema.Schema; import com.yahoo.vespa.documentmodel.DocumentSummary; import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.vespa.documentmodel.SummaryTransform; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class AdjustPositionSummaryFieldsTestCase { @Test - public void test_pos_summary() { + void test_pos_summary() { SearchModel model = new SearchModel(false); model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos"); model.resolve(); @@ -29,7 +24,7 @@ public class AdjustPositionSummaryFieldsTestCase { } @Test - public void test_imported_pos_summary() { + void test_imported_pos_summary() { SearchModel model = new SearchModel(); model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); model.resolve(); @@ -39,7 +34,7 @@ public class AdjustPositionSummaryFieldsTestCase { } @Test - public void test_imported_pos_summary_bad_source() { + void test_imported_pos_summary_bad_source() { SearchModel model = new SearchModel(); model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos"); model.resolve(); @@ -50,7 +45,7 @@ public class AdjustPositionSummaryFieldsTestCase { } @Test - public void test_imported_pos_summary_bad_datatype() { + void test_imported_pos_summary_bad_datatype() { SearchModel model = new SearchModel(); model.addSummaryField("my_pos", DataType.getArray(PositionDataType.INSTANCE), null, "pos"); model.resolve(); @@ -60,7 +55,7 @@ public class AdjustPositionSummaryFieldsTestCase { } @Test - public void test_pos_summary_no_attr_no_rename() { + void test_pos_summary_no_attr_no_rename() { SearchModel model = new SearchModel(false, false, false); model.addSummaryField("pos", PositionDataType.INSTANCE, null, "pos"); model.resolve(); @@ -70,14 +65,14 @@ public class AdjustPositionSummaryFieldsTestCase { } @Test - public void test_pos_default_summary_no_attr_no_rename() { + void test_pos_default_summary_no_attr_no_rename() { SearchModel model = new SearchModel(false, false, false); model.resolve(); assertNull(model.childSchema.getSummary("default")); // ImplicitSummaries processing not run in this test } @Test - public void test_pos_summary_no_rename() { + void test_pos_summary_no_rename() { SearchModel model = new SearchModel(false, true, false); model.addSummaryField("pos", PositionDataType.INSTANCE, null, "pos"); model.resolve(); @@ -86,79 +81,82 @@ public class AdjustPositionSummaryFieldsTestCase { model.assertSummaryField("pos.distance", DataType.INT, SummaryTransform.DISTANCE, "pos_zcurve"); } - @SuppressWarnings("deprecation") - @Rule - public final ExpectedException exceptionRule = ExpectedException.none(); - @Test - public void test_pos_summary_no_attr() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', field 'my_pos': No position attribute 'pos_zcurve'"); - SearchModel model = new SearchModel(false, false, false); - model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos"); - model.resolve(); + void test_pos_summary_no_attr() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + SearchModel model = new SearchModel(false, false, false); + model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos"); + model.resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', field 'my_pos': No position attribute 'pos_zcurve'")); } @Test - public void test_pos_summary_bad_attr() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', field 'my_pos': No position attribute 'pos_zcurve'"); - SearchModel model = new SearchModel(false, false, true); - model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos"); - model.resolve(); + void test_pos_summary_bad_attr() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + SearchModel model = new SearchModel(false, false, true); + model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, "pos"); + model.resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', field 'my_pos': No position attribute 'pos_zcurve'")); } @Test - public void test_imported_pos_summary_no_attr() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', import field 'my_pos_zcurve': " - + "Field 'pos_zcurve' via reference field 'ref': Not found"); - SearchModel model = new SearchModel(true, false, false); - model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); - model.resolve(); + void test_imported_pos_summary_no_attr() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + SearchModel model = new SearchModel(true, false, false); + model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); + model.resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_pos_zcurve': " + + "Field 'pos_zcurve' via reference field 'ref': Not found")); } @Test - public void test_imported_pos_summary_bad_attr() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', field 'my_pos': " - + "No position attribute 'my_pos_zcurve'"); - SearchModel model = new SearchModel(true, false, true); - model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); - model.resolve(); + void test_imported_pos_summary_bad_attr() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + SearchModel model = new SearchModel(true, false, true); + model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); + model.resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', field 'my_pos': " + + "No position attribute 'my_pos_zcurve'")); } @Test - public void test_my_pos_position_summary_bad_datatype() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', field 'my_pos.position': " - + "exists with type 'datatype string (code: 2)', should be of type 'datatype Array<string> (code: -1486737430)"); - SearchModel model = new SearchModel(); - model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); - model.addSummaryField("my_pos.position", DataType.STRING, null, "pos"); - model.resolve(); + void test_my_pos_position_summary_bad_datatype() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + SearchModel model = new SearchModel(); + model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); + model.addSummaryField("my_pos.position", DataType.STRING, null, "pos"); + model.resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', field 'my_pos.position': " + + "exists with type 'datatype string (code: 2)', should be of type 'datatype Array<string> (code: -1486737430)")); } @Test - public void test_my_pos_position_summary_bad_transform() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', field 'my_pos.position': " - + "has summary transform 'none', should have transform 'positions'"); - SearchModel model = new SearchModel(); - model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); - model.addSummaryField("my_pos.position", DataType.getArray(DataType.STRING), null, "pos"); - model.resolve(); + void test_my_pos_position_summary_bad_transform() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + SearchModel model = new SearchModel(); + model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); + model.addSummaryField("my_pos.position", DataType.getArray(DataType.STRING), null, "pos"); + model.resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', field 'my_pos.position': " + + "has summary transform 'none', should have transform 'positions'")); } @Test - public void test_my_pos_position_summary_bad_source() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', field 'my_pos.position': " - + "has source '[source field 'pos']', should have source 'source field 'my_pos_zcurve''"); - SearchModel model = new SearchModel(); - model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); - model.addSummaryField("my_pos.position", DataType.getArray(DataType.STRING), SummaryTransform.POSITIONS, "pos"); - model.resolve(); + void test_my_pos_position_summary_bad_source() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + SearchModel model = new SearchModel(); + model.addSummaryField("my_pos", PositionDataType.INSTANCE, null, null); + model.addSummaryField("my_pos.position", DataType.getArray(DataType.STRING), SummaryTransform.POSITIONS, "pos"); + model.resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', field 'my_pos.position': " + + "has source '[source field 'pos']', should have source 'source field 'my_pos_zcurve''")); } static class SearchModel extends ParentChildSearchModel { diff --git a/config-model/src/test/java/com/yahoo/schema/processing/AssertIndexingScript.java b/config-model/src/test/java/com/yahoo/schema/processing/AssertIndexingScript.java index 82650598f29..f9c1e992347 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/AssertIndexingScript.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/AssertIndexingScript.java @@ -9,8 +9,8 @@ import com.yahoo.vespa.indexinglanguage.parser.ParseException; import java.util.LinkedList; import java.util.List; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Simon Thoresen Hult @@ -36,8 +36,8 @@ public abstract class AssertIndexingScript { } for (Expression actualExp : actual) { String str = actualExp.toString(); - assertTrue("Unexpected: " + str, parsedExpected.remove(str)); + assertTrue(parsedExpected.remove(str), "Unexpected: " + str); } - assertTrue("Missing: " + parsedExpected.toString(), parsedExpected.isEmpty()); + assertTrue(parsedExpected.isEmpty(), "Missing: " + parsedExpected.toString()); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java b/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java index 0b4d7c3a2b6..12da3f0797b 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java @@ -6,7 +6,7 @@ import com.yahoo.schema.parser.ParseException; import java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult diff --git a/config-model/src/test/java/com/yahoo/schema/processing/AttributesExactMatchTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/AttributesExactMatchTestCase.java index 40ebe458c74..a01aa11264b 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/AttributesExactMatchTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/AttributesExactMatchTestCase.java @@ -6,12 +6,13 @@ import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.document.MatchType; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + /** * Attributes should be implicitly exact-match in some cases * @author vegardh @@ -19,7 +20,7 @@ import static org.junit.Assert.assertFalse; */ public class AttributesExactMatchTestCase extends AbstractSchemaTestCase { @Test - public void testAttributesExactMatch() throws IOException, ParseException { + void testAttributesExactMatch() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/attributesexactmatch.sd"); assertEquals(schema.getConcreteField("color").getMatching().getType(), MatchType.EXACT); assertEquals(schema.getConcreteField("artist").getMatching().getType(), MatchType.WORD); @@ -28,12 +29,12 @@ public class AttributesExactMatchTestCase extends AbstractSchemaTestCase { assertEquals(schema.getConcreteField("saxophonist_arr").getMatching().getType(), MatchType.WORD); assertEquals(schema.getConcreteField("flutist").getMatching().getType(), MatchType.TEXT); - assertFalse(schema.getConcreteField("genre").getMatching().getType().equals(MatchType.EXACT)); - assertFalse(schema.getConcreteField("title").getMatching().getType().equals(MatchType.EXACT)); - assertFalse(schema.getConcreteField("trumpetist").getMatching().getType().equals(MatchType.EXACT)); - assertFalse(schema.getConcreteField("genre").getMatching().getType().equals(MatchType.WORD)); - assertFalse(schema.getConcreteField("title").getMatching().getType().equals(MatchType.WORD)); - assertFalse(schema.getConcreteField("trumpetist").getMatching().getType().equals(MatchType.WORD)); + assertNotEquals(schema.getConcreteField("genre").getMatching().getType(), MatchType.EXACT); + assertNotEquals(schema.getConcreteField("title").getMatching().getType(), MatchType.EXACT); + assertNotEquals(schema.getConcreteField("trumpetist").getMatching().getType(), MatchType.EXACT); + assertNotEquals(schema.getConcreteField("genre").getMatching().getType(), MatchType.WORD); + assertNotEquals(schema.getConcreteField("title").getMatching().getType(), MatchType.WORD); + assertNotEquals(schema.getConcreteField("trumpetist").getMatching().getType(), MatchType.WORD); } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/BoldingTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/BoldingTestCase.java index c37bc8085c7..fe38ea1f1b1 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/BoldingTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/BoldingTestCase.java @@ -4,10 +4,10 @@ package com.yahoo.schema.processing; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author bratseth @@ -29,13 +29,13 @@ public class BoldingTestCase extends AbstractSchemaTestCase { "}\n"; @Test - public void testBoldOnNonString() throws ParseException { + void testBoldOnNonString() throws ParseException { try { ApplicationBuilder.createFromString(boldonnonstring); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals("'bolding: on' for non-text field 'year4' (datatype int (code: 0)) is not allowed", - e.getMessage()); + e.getMessage()); } } @@ -50,13 +50,13 @@ public class BoldingTestCase extends AbstractSchemaTestCase { "}\n"; @Test - public void testBoldOnArray() throws ParseException { + void testBoldOnArray() throws ParseException { try { ApplicationBuilder.createFromString(boldonarray); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals("'bolding: on' for non-text field 'myarray' (datatype Array<string> (code: -1486737430)) is not allowed", - e.getMessage()); + e.getMessage()); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/BoolAttributeValidatorTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/BoolAttributeValidatorTestCase.java index 287cc6559d1..f19b1f43115 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/BoolAttributeValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/BoolAttributeValidatorTestCase.java @@ -2,12 +2,12 @@ package com.yahoo.schema.processing; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.schema.ApplicationBuilder.createFromString; +import static org.junit.jupiter.api.Assertions.assertEquals; import static com.yahoo.config.model.test.TestUtil.joinLines; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * @author geirst @@ -15,19 +15,19 @@ import static org.junit.Assert.fail; public class BoolAttributeValidatorTestCase { @Test - public void array_of_bool_attribute_is_not_supported() throws ParseException { + void array_of_bool_attribute_is_not_supported() throws ParseException { try { createFromString(getSd("field b type array<bool> { indexing: attribute }")); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals("For schema 'test', field 'b': Only single value bool attribute fields are supported", - e.getMessage()); + e.getMessage()); } } @Test - public void weigtedset_of_bool_attribute_is_not_supported() throws ParseException { + void weigtedset_of_bool_attribute_is_not_supported() throws ParseException { try { createFromString(getSd("field b type weightedset<bool> { indexing: attribute }")); fail("Expected exception"); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/DictionaryTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/DictionaryTestCase.java index 45a546259ae..ef1716c80e6 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/DictionaryTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/DictionaryTestCase.java @@ -11,11 +11,9 @@ import com.yahoo.schema.document.Dictionary; import com.yahoo.schema.document.ImmutableSDField; import com.yahoo.schema.parser.ParseException; import com.yahoo.vespa.config.search.AttributesConfig; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * Test configuration of dictionary control. @@ -33,19 +31,20 @@ public class DictionaryTestCase { ApplicationBuilder sb = ApplicationBuilder.createFromString(def); return sb.getSchema(); } + @Test - public void testDefaultDictionarySettings() throws ParseException { + void testDefaultDictionarySettings() throws ParseException { String def = TestUtil.joinLines( - "search test {", - " document test {", - " field s1 type string {", - " indexing: attribute | summary", - " }", - " field n1 type int {", - " indexing: summary | attribute", - " }", - " }", - "}"); + "search test {", + " document test {", + " field s1 type string {", + " indexing: attribute | summary", + " }", + " field n1 type int {", + " indexing: summary | attribute", + " }", + " }", + "}"); Schema schema = createSearch(def); assertNull(schema.getAttribute("s1").getDictionary()); assertNull(schema.getAttribute("n1").getDictionary()); @@ -103,64 +102,75 @@ public class DictionaryTestCase { } @Test - public void testCasedBtreeSettings() throws ParseException { + void testCasedBtreeSettings() throws ParseException { verifyDictionaryControl(Dictionary.Type.BTREE, "int", "dictionary:cased"); } @Test - public void testNumericBtreeSettings() throws ParseException { + void testNumericBtreeSettings() throws ParseException { verifyDictionaryControl(Dictionary.Type.BTREE, "int", "dictionary:btree"); } + @Test - public void testNumericHashSettings() throws ParseException { + void testNumericHashSettings() throws ParseException { verifyDictionaryControl(Dictionary.Type.HASH, "int", "dictionary:hash"); } + @Test - public void testNumericBtreeAndHashSettings() throws ParseException { + void testNumericBtreeAndHashSettings() throws ParseException { verifyDictionaryControl(Dictionary.Type.BTREE_AND_HASH, "int", "dictionary:btree", "dictionary:hash"); } + @Test - public void testNumericArrayBtreeAndHashSettings() throws ParseException { + void testNumericArrayBtreeAndHashSettings() throws ParseException { verifyDictionaryControl(Dictionary.Type.BTREE_AND_HASH, "array<int>", "dictionary:btree", "dictionary:hash"); } + @Test - public void testNumericWSetBtreeAndHashSettings() throws ParseException { + void testNumericWSetBtreeAndHashSettings() throws ParseException { verifyDictionaryControl(Dictionary.Type.BTREE_AND_HASH, "weightedset<int>", "dictionary:btree", "dictionary:hash"); } + @Test - public void testStringBtreeSettings() throws ParseException { + void testStringBtreeSettings() throws ParseException { verifyStringDictionaryControl(Dictionary.Type.BTREE, Case.UNCASED, Case.UNCASED, "dictionary:btree"); } + @Test - public void testStringBtreeUnCasedSettings() throws ParseException { + void testStringBtreeUnCasedSettings() throws ParseException { verifyStringDictionaryControl(Dictionary.Type.BTREE, Case.UNCASED, Case.UNCASED, "dictionary { btree\nuncased\n}"); } + @Test - public void testStringBtreeCasedSettings() throws ParseException { + void testStringBtreeCasedSettings() throws ParseException { verifyStringDictionaryControl(Dictionary.Type.BTREE, Case.CASED, Case.CASED, "dictionary { btree\ncased\n}", "match:cased"); } + @Test - public void testStringHashSettings() throws ParseException { + void testStringHashSettings() throws ParseException { try { verifyStringDictionaryControl(Dictionary.Type.HASH, Case.UNCASED, Case.UNCASED, "dictionary:hash"); } catch (IllegalArgumentException e) { assertEquals("For schema 'test', field 'n1': hash dictionary require cased match", e.getMessage()); } } + @Test - public void testStringHashUnCasedSettings() throws ParseException { + void testStringHashUnCasedSettings() throws ParseException { try { verifyStringDictionaryControl(Dictionary.Type.HASH, Case.UNCASED, Case.UNCASED, "dictionary { hash\nuncased\n}"); } catch (IllegalArgumentException e) { assertEquals("For schema 'test', field 'n1': hash dictionary require cased match", e.getMessage()); } } + @Test - public void testStringHashBothCasedSettings() throws ParseException { + void testStringHashBothCasedSettings() throws ParseException { verifyStringDictionaryControl(Dictionary.Type.HASH, Case.CASED, Case.CASED, "dictionary { hash\ncased\n}", "match:cased"); } + @Test - public void testStringHashCasedSettings() throws ParseException { + void testStringHashCasedSettings() throws ParseException { try { verifyStringDictionaryControl(Dictionary.Type.HASH, Case.CASED, Case.CASED, "dictionary { hash\ncased\n}"); fail(); @@ -168,24 +178,28 @@ public class DictionaryTestCase { assertEquals("For schema 'test', field 'n1': Dictionary casing 'CASED' does not match field match casing 'UNCASED'", e.getMessage()); } } + @Test - public void testStringBtreeHashSettings() throws ParseException { + void testStringBtreeHashSettings() throws ParseException { verifyStringDictionaryControl(Dictionary.Type.BTREE_AND_HASH, Case.UNCASED, Case.UNCASED, "dictionary{hash\nbtree\n}"); } + @Test - public void testStringBtreeHashUnCasedSettings() throws ParseException { + void testStringBtreeHashUnCasedSettings() throws ParseException { verifyStringDictionaryControl(Dictionary.Type.BTREE_AND_HASH, Case.UNCASED, Case.UNCASED, "dictionary { hash\nbtree\nuncased\n}"); } + @Test - public void testStringBtreeHashCasedSettings() throws ParseException { + void testStringBtreeHashCasedSettings() throws ParseException { try { verifyStringDictionaryControl(Dictionary.Type.BTREE_AND_HASH, Case.CASED, Case.CASED, "dictionary { btree\nhash\ncased\n}"); } catch (IllegalArgumentException e) { assertEquals("For schema 'test', field 'n1': Dictionary casing 'CASED' does not match field match casing 'UNCASED'", e.getMessage()); } } + @Test - public void testNonNumericFieldsFailsDictionaryControl() throws ParseException { + void testNonNumericFieldsFailsDictionaryControl() throws ParseException { String def = TestUtil.joinLines( "schema test {", " document test {", @@ -202,8 +216,9 @@ public class DictionaryTestCase { assertEquals("For schema 'test', field 'n1': You can only specify 'dictionary:' for numeric or string fields", e.getMessage()); } } + @Test - public void testNonFastSearchNumericFieldsFailsDictionaryControl() throws ParseException { + void testNonFastSearchNumericFieldsFailsDictionaryControl() throws ParseException { String def = TestUtil.joinLines( "schema test {", " document test {", @@ -222,7 +237,7 @@ public class DictionaryTestCase { } @Test - public void testCasingForNonFastSearch() throws ParseException { + void testCasingForNonFastSearch() throws ParseException { String def = TestUtil.joinLines( "schema test {", " document test {", diff --git a/config-model/src/test/java/com/yahoo/schema/processing/DisallowComplexMapAndWsetKeyTypesTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/DisallowComplexMapAndWsetKeyTypesTestCase.java index 64b0a437b1d..4efd20a06f1 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/DisallowComplexMapAndWsetKeyTypesTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/DisallowComplexMapAndWsetKeyTypesTestCase.java @@ -4,41 +4,53 @@ package com.yahoo.schema.processing; import com.yahoo.schema.RankProfileRegistry; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author lesters */ public class DisallowComplexMapAndWsetKeyTypesTestCase { - @Test(expected = IllegalArgumentException.class) - public void requireThatComplexTypesForMapKeysFail() throws ParseException { - testFieldType("map<mystruct,string>"); + @Test + void requireThatComplexTypesForMapKeysFail() throws ParseException { + assertThrows(IllegalArgumentException.class, () -> { + testFieldType("map<mystruct,string>"); + }); } - @Test(expected = IllegalArgumentException.class) - public void requireThatComplexTypesForWsetFail() throws ParseException { - testFieldType("weightedset<mystruct>"); + @Test + void requireThatComplexTypesForWsetFail() throws ParseException { + assertThrows(IllegalArgumentException.class, () -> { + testFieldType("weightedset<mystruct>"); + }); } - @Test(expected = IllegalArgumentException.class) - public void requireThatNestedComplexTypesForMapFail() throws ParseException { - testFieldType("array<map<mystruct,string>>"); + @Test + void requireThatNestedComplexTypesForMapFail() throws ParseException { + assertThrows(IllegalArgumentException.class, () -> { + testFieldType("array<map<mystruct,string>>"); + }); } @Test - public void requireThatNestedComplexValuesForMapSucceed() throws ParseException { + void requireThatNestedComplexValuesForMapSucceed() throws ParseException { testFieldType("array<map<string,mystruct>>"); } - @Test(expected = IllegalArgumentException.class) - public void requireThatNestedComplexTypesForWsetFail() throws ParseException { - testFieldType("array<weightedset<mystruct>>"); + @Test + void requireThatNestedComplexTypesForWsetFail() throws ParseException { + assertThrows(IllegalArgumentException.class, () -> { + testFieldType("array<weightedset<mystruct>>"); + }); } - @Test(expected = IllegalArgumentException.class) - public void requireThatDeepNestedComplexTypesForMapFail() throws ParseException { - testFieldType("map<string,map<mystruct,string>>"); + @Test + void requireThatDeepNestedComplexTypesForMapFail() throws ParseException { + assertThrows(IllegalArgumentException.class, () -> { + testFieldType("map<string,map<mystruct,string>>"); + }); } private void testFieldType(String fieldType) throws ParseException { diff --git a/config-model/src/test/java/com/yahoo/schema/processing/FastAccessValidatorTest.java b/config-model/src/test/java/com/yahoo/schema/processing/FastAccessValidatorTest.java index b249b407c7b..ebf79a4a7d5 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/FastAccessValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/FastAccessValidatorTest.java @@ -5,57 +5,54 @@ import com.yahoo.config.model.test.TestUtil; import com.yahoo.schema.RankProfileRegistry; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author bjorncs */ public class FastAccessValidatorTest { - @SuppressWarnings("deprecation") - @Rule - public final ExpectedException exceptionRule = ExpectedException.none(); - @Test - public void throws_exception_on_incompatible_use_of_fastaccess() throws ParseException { - ApplicationBuilder builder = new ApplicationBuilder(new RankProfileRegistry()); - builder.addSchema( - TestUtil.joinLines( - "schema parent {", - " document parent {", - " field int_field type int { indexing: attribute }", - " }", - "}")); - builder.addSchema( - TestUtil.joinLines( - "schema test {", - " document test { ", - " field int_attribute type int { ", - " indexing: attribute ", - " attribute: fast-access", - " }", - " field predicate_attribute type predicate {", - " indexing: attribute ", - " attribute: fast-access", - " }", - " field tensor_attribute type tensor(x[5]) {", - " indexing: attribute ", - " attribute: fast-access", - " }", - " field reference_attribute type reference<parent> {", - " indexing: attribute ", - " attribute: fast-access", - " }", - " }", - "}")); - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage( - "For schema 'test': The following attributes have a type that is incompatible " + - "with fast-access: predicate_attribute, tensor_attribute, reference_attribute. " + - "Predicate, tensor and reference attributes are incompatible with fast-access."); - builder.build(true); + void throws_exception_on_incompatible_use_of_fastaccess() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + ApplicationBuilder builder = new ApplicationBuilder(new RankProfileRegistry()); + builder.addSchema( + TestUtil.joinLines( + "schema parent {", + " document parent {", + " field int_field type int { indexing: attribute }", + " }", + "}")); + builder.addSchema( + TestUtil.joinLines( + "schema test {", + " document test { ", + " field int_attribute type int { ", + " indexing: attribute ", + " attribute: fast-access", + " }", + " field predicate_attribute type predicate {", + " indexing: attribute ", + " attribute: fast-access", + " }", + " field tensor_attribute type tensor(x[5]) {", + " indexing: attribute ", + " attribute: fast-access", + " }", + " field reference_attribute type reference<parent> {", + " indexing: attribute ", + " attribute: fast-access", + " }", + " }", + "}")); + builder.build(true); + }); + assertTrue(exception.getMessage().contains("For schema 'test': The following attributes have a type that is incompatible " + + "with fast-access: predicate_attribute, tensor_attribute, reference_attribute. " + + "Predicate, tensor and reference attributes are incompatible with fast-access.")); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSchemaFieldsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSchemaFieldsTestCase.java index 594124c9500..c758d49f79f 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSchemaFieldsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSchemaFieldsTestCase.java @@ -7,17 +7,17 @@ import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.derived.DerivedConfiguration; import com.yahoo.schema.document.SDDocumentType; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class ImplicitSchemaFieldsTestCase extends AbstractSchemaTestCase { @Test - public void testRequireThatExtraFieldsAreIncluded() throws IOException, ParseException { + void testRequireThatExtraFieldsAreIncluded() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/extrafield.sd"); assertNotNull(schema); @@ -29,7 +29,7 @@ public class ImplicitSchemaFieldsTestCase extends AbstractSchemaTestCase { } @Test - public void testRequireThatSummaryFieldsAreIncluded() throws IOException, ParseException { + void testRequireThatSummaryFieldsAreIncluded() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/summaryfield.sd"); assertNotNull(schema); @@ -44,7 +44,7 @@ public class ImplicitSchemaFieldsTestCase extends AbstractSchemaTestCase { } @Test - public void testRequireThatBoldedSummaryFieldsAreIncluded() throws IOException, ParseException { + void testRequireThatBoldedSummaryFieldsAreIncluded() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/boldedsummaryfields.sd"); assertNotNull(schema); @@ -58,7 +58,7 @@ public class ImplicitSchemaFieldsTestCase extends AbstractSchemaTestCase { } @Test - public void testRequireThatUntransformedSummaryFieldsAreIgnored() throws IOException, ParseException { + void testRequireThatUntransformedSummaryFieldsAreIgnored() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/untransformedsummaryfields.sd"); assertNotNull(schema); @@ -71,7 +71,7 @@ public class ImplicitSchemaFieldsTestCase extends AbstractSchemaTestCase { } @Test - public void testRequireThatDynamicSummaryFieldsAreIgnored() throws IOException, ParseException { + void testRequireThatDynamicSummaryFieldsAreIgnored() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/dynamicsummaryfields.sd"); assertNotNull(schema); @@ -83,7 +83,7 @@ public class ImplicitSchemaFieldsTestCase extends AbstractSchemaTestCase { } @Test - public void testRequireThatDerivedConfigurationWorks() throws IOException, ParseException { + void testRequireThatDerivedConfigurationWorks() throws IOException, ParseException { ApplicationBuilder sb = new ApplicationBuilder(); sb.addSchemaFile("src/test/examples/nextgen/simple.sd"); sb.build(true); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ImplicitStructTypesTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/ImplicitStructTypesTestCase.java index 111ed266d74..243ec0243c8 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ImplicitStructTypesTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ImplicitStructTypesTestCase.java @@ -8,14 +8,15 @@ import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.document.SDDocumentType; import com.yahoo.schema.document.SDField; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; + public class ImplicitStructTypesTestCase extends AbstractSchemaTestCase { @Test - public void testRequireThatImplicitStructsAreCreated() throws IOException, ParseException { + void testRequireThatImplicitStructsAreCreated() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/toggleon.sd"); assertNotNull(schema); @@ -23,8 +24,9 @@ public class ImplicitStructTypesTestCase extends AbstractSchemaTestCase { assertNotNull(docType); assertStruct(docType, PositionDataType.INSTANCE); } + @Test - public void testRequireThatImplicitStructsAreUsed() throws IOException, ParseException { + void testRequireThatImplicitStructsAreUsed() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/implicitstructtypes.sd"); assertNotNull(schema); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSummariesTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSummariesTestCase.java index 50deb5d5b42..37bc064c19e 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSummariesTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSummariesTestCase.java @@ -5,7 +5,7 @@ import com.yahoo.schema.Schema; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; import com.yahoo.vespa.documentmodel.SummaryTransform; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.ArrayList; @@ -15,9 +15,7 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author Simon Thoresen Hult @@ -25,7 +23,7 @@ import static org.junit.Assert.assertTrue; public class ImplicitSummariesTestCase { @Test - public void requireThatSummaryFromAttributeDoesNotWarn() throws IOException, ParseException { + void requireThatSummaryFromAttributeDoesNotWarn() throws IOException, ParseException { LogHandler log = new LogHandler(); Logger.getLogger("").addHandler(log); @@ -59,19 +57,19 @@ public class ImplicitSummariesTestCase { } @Test - public void attribute_combiner_transform_is_set_on_array_of_struct_with_only_struct_field_attributes() throws IOException, ParseException { + void attribute_combiner_transform_is_set_on_array_of_struct_with_only_struct_field_attributes() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/derived/array_of_struct_attribute/test.sd"); assertEquals(SummaryTransform.ATTRIBUTECOMBINER, schema.getSummaryField("elem_array").getTransform()); } @Test - public void attribute_combiner_transform_is_set_on_map_of_struct_with_only_struct_field_attributes() throws IOException, ParseException { + void attribute_combiner_transform_is_set_on_map_of_struct_with_only_struct_field_attributes() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/derived/map_of_struct_attribute/test.sd"); assertEquals(SummaryTransform.ATTRIBUTECOMBINER, schema.getSummaryField("str_elem_map").getTransform()); } @Test - public void attribute_combiner_transform_is_not_set_when_map_of_struct_has_some_struct_field_attributes() throws IOException, ParseException { + void attribute_combiner_transform_is_not_set_when_map_of_struct_has_some_struct_field_attributes() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/derived/map_of_struct_attribute/test.sd"); assertEquals(SummaryTransform.NONE, schema.getSummaryField("int_elem_map").getTransform()); } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSummaryFieldsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSummaryFieldsTestCase.java index f32c9079d36..bc7513b4662 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSummaryFieldsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSummaryFieldsTestCase.java @@ -6,17 +6,17 @@ import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.parser.ParseException; import com.yahoo.vespa.documentmodel.DocumentSummary; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class ImplicitSummaryFieldsTestCase extends AbstractSchemaTestCase { @Test - public void testRequireThatImplicitFieldsAreCreated() throws IOException, ParseException { + void testRequireThatImplicitFieldsAreCreated() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/implicitsummaryfields.sd"); assertNotNull(schema); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ImportedFieldsResolverTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/ImportedFieldsResolverTestCase.java index 5baa64d06d4..853cb1d1a79 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ImportedFieldsResolverTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ImportedFieldsResolverTestCase.java @@ -11,24 +11,15 @@ import com.yahoo.schema.document.ImportedFields; import com.yahoo.schema.document.SDField; import com.yahoo.schema.document.TemporarySDField; import com.yahoo.tensor.TensorType; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.*; /** * @author geirst */ public class ImportedFieldsResolverTestCase { - @SuppressWarnings("deprecation") - @Rule - public final ExpectedException exceptionRule = ExpectedException.none(); - private void resolve_imported_field(String fieldName, String targetFieldName) { SearchModel model = new SearchModel(); model.addImportedField(fieldName, "ref", targetFieldName).resolve(); @@ -52,54 +43,57 @@ public class ImportedFieldsResolverTestCase { } @Test - public void valid_imported_fields_are_resolved() { + void valid_imported_fields_are_resolved() { resolve_imported_field("my_attribute_field", "attribute_field"); resolve_imported_field("my_tensor_field", "tensor_field"); resolve_imported_field("my_ancient_field", "ancient_field"); } @Test - public void resolver_fails_if_document_reference_is_not_found() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', import field 'my_attribute_field': " - + "Reference field 'not_ref' not found"); - new SearchModel().addImportedField("my_attribute_field", "not_ref", "budget").resolve(); + void resolver_fails_if_document_reference_is_not_found() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + new SearchModel().addImportedField("my_attribute_field", "not_ref", "budget").resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_attribute_field': " + + "Reference field 'not_ref' not found")); } @Test - public void resolver_fails_if_referenced_field_is_not_found() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', import field 'my_attribute_field': " - + "Field 'not_existing' via reference field 'ref': Not found"); - new SearchModel().addImportedField("my_attribute_field", "ref", "not_existing").resolve(); + void resolver_fails_if_referenced_field_is_not_found() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + new SearchModel().addImportedField("my_attribute_field", "ref", "not_existing").resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_attribute_field': " + + "Field 'not_existing' via reference field 'ref': Not found")); } @Test - public void resolver_fails_if_imported_field_is_not_an_attribute() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'child', import field 'my_not_attribute': " - + "Field 'not_attribute' via reference field 'ref': Is not an attribute field. Only attribute fields supported"); - new SearchModel().addImportedField("my_not_attribute", "ref", "not_attribute").resolve(); + void resolver_fails_if_imported_field_is_not_an_attribute() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + new SearchModel().addImportedField("my_not_attribute", "ref", "not_attribute").resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_not_attribute': " + + "Field 'not_attribute' via reference field 'ref': Is not an attribute field. Only attribute fields supported")); } @Test - public void resolver_fails_if_imported_field_is_indexing() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage( - "For schema 'child', import field 'my_attribute_and_index': " + - "Field 'attribute_and_index' via reference field 'ref': Is an index field. Not supported"); - new SearchModel() - .addImportedField("my_attribute_and_index", "ref", "attribute_and_index") - .resolve(); + void resolver_fails_if_imported_field_is_indexing() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + new SearchModel() + .addImportedField("my_attribute_and_index", "ref", "attribute_and_index") + .resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_attribute_and_index': " + + "Field 'attribute_and_index' via reference field 'ref': Is an index field. Not supported")); } @Test - public void resolver_fails_if_imported_field_is_of_type_predicate() { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage( - "For schema 'child', import field 'my_predicate_field': " + - "Field 'predicate_field' via reference field 'ref': Is of type 'predicate'. Not supported"); - new SearchModel().addImportedField("my_predicate_field", "ref", "predicate_field").resolve(); + void resolver_fails_if_imported_field_is_of_type_predicate() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + new SearchModel().addImportedField("my_predicate_field", "ref", "predicate_field").resolve(); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_predicate_field': " + + "Field 'predicate_field' via reference field 'ref': Is of type 'predicate'. Not supported")); } static class SearchModel extends ParentChildSearchModel { diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ImportedFieldsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/ImportedFieldsTestCase.java index ab702154527..6c23d1ecf91 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ImportedFieldsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ImportedFieldsTestCase.java @@ -7,15 +7,10 @@ import com.yahoo.schema.derived.AttributeFields; import com.yahoo.schema.document.ImportedComplexField; import com.yahoo.schema.document.ImportedField; import com.yahoo.schema.parser.ParseException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; import static com.yahoo.config.model.test.TestUtil.joinLines; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author geirst @@ -23,7 +18,7 @@ import static org.junit.Assert.assertTrue; public class ImportedFieldsTestCase { @Test - public void fields_can_be_imported_from_referenced_document_types() throws ParseException { + void fields_can_be_imported_from_referenced_document_types() throws ParseException { Schema schema = buildAdSearch(joinLines( "search ad {", " document ad {", @@ -38,33 +33,31 @@ public class ImportedFieldsTestCase { assertSearchContainsImportedField("my_name", "person_ref", "person", "name", schema); } - @SuppressWarnings("deprecation") - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test - public void field_reference_spec_must_include_dot() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Illegal field reference spec 'campaignrefbudget': Does not include a single '.'"); - buildAdSearch(joinLines( - "search ad {", - " document ad {}", - " import field campaignrefbudget as budget {}", - "}")); + void field_reference_spec_must_include_dot() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + buildAdSearch(joinLines( + "search ad {", + " document ad {}", + " import field campaignrefbudget as budget {}", + "}")); + }); + assertTrue(exception.getMessage().contains("Illegal field reference spec 'campaignrefbudget': Does not include a single '.'")); } @Test - public void fail_duplicate_import() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For schema 'ad', import field as 'my_budget': Field already imported"); - Schema schema = buildAdSearch(joinLines( - "schema ad {", - " document ad {", - " field campaign_ref type reference<campaign> { indexing: attribute }", - " }", - " import field campaign_ref.budget as my_budget {}", - " import field campaign_ref.budget as my_budget {}", - "}")); + void fail_duplicate_import() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + Schema schema = buildAdSearch(joinLines( + "schema ad {", + " document ad {", + " field campaign_ref type reference<campaign> { indexing: attribute }", + " }", + " import field campaign_ref.budget as my_budget {}", + " import field campaign_ref.budget as my_budget {}", + "}")); + }); + assertTrue(exception.getMessage().contains("For schema 'ad', import field as 'my_budget': Field already imported")); } private static Schema buildAdSearch(String sdContent) throws ParseException { @@ -113,52 +106,57 @@ public class ImportedFieldsTestCase { } @Test - public void check_struct_import() throws ParseException { + void check_struct_import() throws ParseException { checkStructImport(new ParentStructSdBuilder()); checkStructImport(new ParentStructSdBuilder().elem_array_weight_attr(false).elem_map_value_weight_attr(false)); checkStructImport(new ParentStructSdBuilder().elem_array_name_attr(false).elem_map_value_name_attr(false)); } @Test - public void check_nested_struct_import() throws ParseException { + void check_nested_struct_import() throws ParseException { checkNestedStructImport(new GrandParentStructSdBuilder()); checkNestedStructImport(new GrandParentStructSdBuilder().elem_array_weight_attr(false).elem_map_value_weight_attr(false)); checkNestedStructImport(new GrandParentStructSdBuilder().elem_array_name_attr(false).elem_map_value_name_attr(false)); } @Test - public void check_illegal_struct_import_missing_array_of_struct_attributes() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For schema 'child', import field 'my_elem_array': Field 'elem_array' via reference field 'parent_ref': Is not a struct containing an attribute field."); - checkStructImport(new ParentStructSdBuilder().elem_array_name_attr(false).elem_array_weight_attr(false)); + void check_illegal_struct_import_missing_array_of_struct_attributes() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + checkStructImport(new ParentStructSdBuilder().elem_array_name_attr(false).elem_array_weight_attr(false)); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_elem_array': Field 'elem_array' via reference field 'parent_ref': Is not a struct containing an attribute field.")); } @Test - public void check_illegal_struct_import_missing_map_of_struct_key_attribute() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For schema 'child', import field 'my_elem_map' (nested to 'my_elem_map.key'): Field 'elem_map.key' via reference field 'parent_ref': Is not an attribute field. Only attribute fields supported"); - checkStructImport(new ParentStructSdBuilder().elem_map_key_attr(false)); + void check_illegal_struct_import_missing_map_of_struct_key_attribute() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + checkStructImport(new ParentStructSdBuilder().elem_map_key_attr(false)); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_elem_map' (nested to 'my_elem_map.key'): Field 'elem_map.key' via reference field 'parent_ref': Is not an attribute field. Only attribute fields supported")); } @Test - public void check_illegal_struct_import_missing_map_of_struct_value_attributes() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For schema 'child', import field 'my_elem_map' (nested to 'my_elem_map.value'): Field 'elem_map.value' via reference field 'parent_ref': Is not a struct containing an attribute field."); - checkStructImport(new ParentStructSdBuilder().elem_map_value_name_attr(false).elem_map_value_weight_attr(false)); + void check_illegal_struct_import_missing_map_of_struct_value_attributes() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + checkStructImport(new ParentStructSdBuilder().elem_map_value_name_attr(false).elem_map_value_weight_attr(false)); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_elem_map' (nested to 'my_elem_map.value'): Field 'elem_map.value' via reference field 'parent_ref': Is not a struct containing an attribute field.")); } @Test - public void check_illegal_struct_import_missing_map_of_primitive_key_attribute() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For schema 'child', import field 'my_str_int_map' (nested to 'my_str_int_map.key'): Field 'str_int_map.key' via reference field 'parent_ref': Is not an attribute field. Only attribute fields supported"); - checkStructImport(new ParentStructSdBuilder().str_int_map_key_attr(false)); + void check_illegal_struct_import_missing_map_of_primitive_key_attribute() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + checkStructImport(new ParentStructSdBuilder().str_int_map_key_attr(false)); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_str_int_map' (nested to 'my_str_int_map.key'): Field 'str_int_map.key' via reference field 'parent_ref': Is not an attribute field. Only attribute fields supported")); } @Test - public void check_illegal_struct_import_missing_map_of_primitive_value_attribute() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For schema 'child', import field 'my_str_int_map' (nested to 'my_str_int_map.value'): Field 'str_int_map.value' via reference field 'parent_ref': Is not an attribute field. Only attribute fields supported"); - checkStructImport(new ParentStructSdBuilder().str_int_map_value_attr(false)); + void check_illegal_struct_import_missing_map_of_primitive_value_attribute() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + checkStructImport(new ParentStructSdBuilder().str_int_map_value_attr(false)); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_str_int_map' (nested to 'my_str_int_map.value'): Field 'str_int_map.value' via reference field 'parent_ref': Is not an attribute field. Only attribute fields supported")); } private static class NamedSdBuilder { @@ -408,20 +406,21 @@ public class ImportedFieldsTestCase { } @Test - public void check_pos_import() throws ParseException { + void check_pos_import() throws ParseException { checkPosImport(new ParentPosSdBuilder(), new ChildPosSdBuilder()); } @Test - public void check_nested_pos_import() throws ParseException { + void check_nested_pos_import() throws ParseException { checkNestedPosImport(new GrandParentPosSdBuilder(), new ChildPosSdBuilder()); } @Test - public void check_pos_import_after_pos_zcurve_import() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For schema 'child', import field 'my_pos_zcurve': Field 'pos_zcurve' via reference field 'parent_ref': Field already imported"); - checkPosImport(new ParentPosSdBuilder(), new ChildPosSdBuilder().import_pos_zcurve_before(true)); + void check_pos_import_after_pos_zcurve_import() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + checkPosImport(new ParentPosSdBuilder(), new ChildPosSdBuilder().import_pos_zcurve_before(true)); + }); + assertTrue(exception.getMessage().contains("For schema 'child', import field 'my_pos_zcurve': Field 'pos_zcurve' via reference field 'parent_ref': Field already imported")); } private static ImportedField getImportedField(String name, Schema schema) { @@ -466,7 +465,7 @@ public class ImportedFieldsTestCase { } @Test - public void field_with_struct_field_attributes_can_be_imported_from_parents_that_use_inheritance() throws ParseException { + void field_with_struct_field_attributes_can_be_imported_from_parents_that_use_inheritance() throws ParseException { var builder = buildParentsUsingInheritance(); assertParentContainsEntriesAttributes(builder.getSchema("parent_a")); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java index 71c79feedc1..893ee3b1ea4 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingInputsTestCase.java @@ -2,7 +2,7 @@ package com.yahoo.schema.processing; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -14,32 +14,32 @@ import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; public class IndexingInputsTestCase { @Test - public void requireThatExtraFieldInputExtraFieldThrows() throws IOException, ParseException { + void requireThatExtraFieldInputExtraFieldThrows() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_extra_field_input_extra_field.sd", - "For schema 'indexing_extra_field_input_extra_field', field 'bar': Indexing script refers " + - "to field 'bar' which does not exist in document type " + - "'indexing_extra_field_input_extra_field', and is not a mutable attribute."); + "For schema 'indexing_extra_field_input_extra_field', field 'bar': Indexing script refers " + + "to field 'bar' which does not exist in document type " + + "'indexing_extra_field_input_extra_field', and is not a mutable attribute."); } @Test - public void requireThatExtraFieldInputImplicitThrows() throws IOException, ParseException { + void requireThatExtraFieldInputImplicitThrows() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_extra_field_input_implicit.sd", - "For schema 'indexing_extra_field_input_implicit', field 'foo': Indexing script refers to " + - "field 'foo' which does not exist in document type 'indexing_extra_field_input_implicit', and is not a mutable attribute."); + "For schema 'indexing_extra_field_input_implicit', field 'foo': Indexing script refers to " + + "field 'foo' which does not exist in document type 'indexing_extra_field_input_implicit', and is not a mutable attribute."); } @Test - public void requireThatExtraFieldInputNullThrows() throws IOException, ParseException { + void requireThatExtraFieldInputNullThrows() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_extra_field_input_null.sd", - "For schema 'indexing_extra_field_input_null', field 'foo': Indexing script refers to field " + - "'foo' which does not exist in document type 'indexing_extra_field_input_null', and is not a mutable attribute."); + "For schema 'indexing_extra_field_input_null', field 'foo': Indexing script refers to field " + + "'foo' which does not exist in document type 'indexing_extra_field_input_null', and is not a mutable attribute."); } @Test - public void requireThatExtraFieldInputSelfThrows() throws IOException, ParseException { + void requireThatExtraFieldInputSelfThrows() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_extra_field_input_self.sd", - "For schema 'indexing_extra_field_input_self', field 'foo': Indexing script refers to field " + - "'foo' which does not exist in document type 'indexing_extra_field_input_self', and is not a mutable attribute."); + "For schema 'indexing_extra_field_input_self', field 'foo': Indexing script refers to field " + + "'foo' which does not exist in document type 'indexing_extra_field_input_self', and is not a mutable attribute."); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java index 687549f920e..e707d203381 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java @@ -2,7 +2,7 @@ package com.yahoo.schema.processing; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -15,16 +15,16 @@ import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; public class IndexingOutputsTestCase { @Test - public void requireThatOutputOtherFieldThrows() throws IOException, ParseException { + void requireThatOutputOtherFieldThrows() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_output_other_field.sd", - "For schema 'indexing_output_other_field', field 'foo': Indexing expression 'index bar' " + - "attempts to write to a field other than 'foo'."); + "For schema 'indexing_output_other_field', field 'foo': Indexing expression 'index bar' " + + "attempts to write to a field other than 'foo'."); } @Test - public void requireThatOutputConflictThrows() throws IOException, ParseException { + void requireThatOutputConflictThrows() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_output_conflict.sd", - "For schema 'indexing_output_confict', field 'bar': For expression 'index bar': Attempting " + - "to assign conflicting values to field 'bar'."); + "For schema 'indexing_output_confict', field 'bar': For expression 'index bar': Attempting " + + "to assign conflicting values to field 'bar'."); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingScriptRewriterTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingScriptRewriterTestCase.java index 76cb6a5505c..54a50d2ce93 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingScriptRewriterTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingScriptRewriterTestCase.java @@ -16,7 +16,7 @@ import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.vespa.documentmodel.SummaryTransform; import com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression; import com.yahoo.vespa.model.container.search.QueryProfiles; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.OptionalDouble; @@ -25,7 +25,7 @@ import java.util.OptionalLong; import java.util.Set; import static com.yahoo.schema.processing.AssertIndexingScript.assertIndexing; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Simon Thoresen Hult @@ -33,108 +33,108 @@ import static org.junit.Assert.assertEquals; public class IndexingScriptRewriterTestCase extends AbstractSchemaTestCase { @Test - public void testSetLanguageRewriting() { + void testSetLanguageRewriting() { assertIndexingScript("{ input test | set_language; }", - createField("test", DataType.STRING, "{ set_language }")); + createField("test", DataType.STRING, "{ set_language }")); } @Test - public void testSummaryRewriting() { + void testSummaryRewriting() { assertIndexingScript("{ input test | summary test; }", - createField("test", DataType.STRING, "{ summary }")); + createField("test", DataType.STRING, "{ summary }")); } @Test - public void testDynamicSummaryRewriting() { + void testDynamicSummaryRewriting() { SDField field = createField("test", DataType.STRING, "{ summary }"); field.addSummaryField(createDynamicSummaryField(field, "dyn")); assertIndexingScript("{ input test | tokenize normalize stem:\"BEST\" | summary dyn; }", field); } @Test - public void testSummaryRewritingWithIndexing() { + void testSummaryRewritingWithIndexing() { assertIndexingScript("{ input test | tokenize normalize stem:\"BEST\" | summary test | index test; }", - createField("test", DataType.STRING, "{ summary | index }")); + createField("test", DataType.STRING, "{ summary | index }")); } @Test - public void testDynamicAndStaticSummariesRewritingWithIndexing() { + void testDynamicAndStaticSummariesRewritingWithIndexing() { SDField field = createField("test", DataType.STRING, "{ summary | index }"); field.addSummaryField(createDynamicSummaryField(field, "dyn")); field.addSummaryField(createStaticSummaryField(field, "test")); field.addSummaryField(createStaticSummaryField(field, "other")); field.addSummaryField(createDynamicSummaryField(field, "dyn2")); assertIndexingScript("{ input test | tokenize normalize stem:\"BEST\" | summary dyn | summary dyn2 | summary other | " + - "summary test | index test; }", field); + "summary test | index test; }", field); } @Test - public void testIntSummaryRewriting() { + void testIntSummaryRewriting() { assertIndexingScript("{ input test | summary test | attribute test; }", - createField("test", DataType.INT, "{ summary | index }")); + createField("test", DataType.INT, "{ summary | index }")); } @Test - public void testStringAttributeSummaryRewriting() { + void testStringAttributeSummaryRewriting() { assertIndexingScript("{ input test | summary test | attribute test; }", - createField("test", DataType.STRING, "{ summary | attribute }")); + createField("test", DataType.STRING, "{ summary | attribute }")); } @Test - public void testMultiblockTokenize() { + void testMultiblockTokenize() { SDField field = createField("test", DataType.STRING, - "{ input test | tokenize | { summary test; }; }"); + "{ input test | tokenize | { summary test; }; }"); assertIndexingScript("{ input test | tokenize | { summary test; }; }", field); } @Test - public void requireThatOutputDefaultsToCurrentField() { + void requireThatOutputDefaultsToCurrentField() { assertIndexingScript("{ input test | attribute test; }", - createField("test", DataType.STRING, "{ attribute; }")); + createField("test", DataType.STRING, "{ attribute; }")); assertIndexingScript("{ input test | tokenize normalize stem:\"BEST\" | index test; }", - createField("test", DataType.STRING, "{ index; }")); + createField("test", DataType.STRING, "{ index; }")); assertIndexingScript("{ input test | summary test; }", - createField("test", DataType.STRING, "{ summary; }")); + createField("test", DataType.STRING, "{ summary; }")); } @Test - public void testTokenizeComparisonDisregardsConfig() { + void testTokenizeComparisonDisregardsConfig() { assertIndexingScript("{ input test | tokenize normalize stem:\"BEST\" | summary test | index test; }", - createField("test", DataType.STRING, "{ summary | tokenize | index; }")); + createField("test", DataType.STRING, "{ summary | tokenize | index; }")); } @Test - public void testDerivingFromSimple() throws Exception { + void testDerivingFromSimple() throws Exception { assertIndexing(Arrays.asList("clear_state | guard { input access | attribute access; }", - "clear_state | guard { input category | split \";\" | attribute category_arr; }", - "clear_state | guard { input category | tokenize | index category; }", - "clear_state | guard { input categories_src | lowercase | normalize | tokenize normalize stem:\"BEST\" | index categories; }", - "clear_state | guard { input categoriesagain_src | lowercase | normalize | tokenize normalize stem:\"BEST\" | index categoriesagain; }", - "clear_state | guard { input chatter | tokenize normalize stem:\"BEST\" | index chatter; }", - "clear_state | guard { input description | tokenize normalize stem:\"BEST\" | summary description | summary dyndesc | index description; }", - "clear_state | guard { input exactemento_src | lowercase | tokenize normalize stem:\"BEST\" | index exactemento | summary exactemento; }", - "clear_state | guard { input longdesc | tokenize normalize stem:\"BEST\" | summary dyndesc2 | summary dynlong | summary longdesc | summary longstat; }", - "clear_state | guard { input measurement | attribute measurement | summary measurement; }", - "clear_state | guard { input measurement | to_array | attribute measurement_arr; }", - "clear_state | guard { input popularity | attribute popularity; }", - "clear_state | guard { input popularity * input measurement | attribute popsiness; }", - "clear_state | guard { input smallattribute | attribute smallattribute; }", - "clear_state | guard { input title | tokenize normalize stem:\"BEST\" | summary title | index title; }", - "clear_state | guard { input title . \" \" . input category | tokenize | summary exact | index exact; }"), - ApplicationBuilder.buildFromFile("src/test/examples/simple.sd")); + "clear_state | guard { input category | split \";\" | attribute category_arr; }", + "clear_state | guard { input category | tokenize | index category; }", + "clear_state | guard { input categories_src | lowercase | normalize | tokenize normalize stem:\"BEST\" | index categories; }", + "clear_state | guard { input categoriesagain_src | lowercase | normalize | tokenize normalize stem:\"BEST\" | index categoriesagain; }", + "clear_state | guard { input chatter | tokenize normalize stem:\"BEST\" | index chatter; }", + "clear_state | guard { input description | tokenize normalize stem:\"BEST\" | summary description | summary dyndesc | index description; }", + "clear_state | guard { input exactemento_src | lowercase | tokenize normalize stem:\"BEST\" | index exactemento | summary exactemento; }", + "clear_state | guard { input longdesc | tokenize normalize stem:\"BEST\" | summary dyndesc2 | summary dynlong | summary longdesc | summary longstat; }", + "clear_state | guard { input measurement | attribute measurement | summary measurement; }", + "clear_state | guard { input measurement | to_array | attribute measurement_arr; }", + "clear_state | guard { input popularity | attribute popularity; }", + "clear_state | guard { input popularity * input measurement | attribute popsiness; }", + "clear_state | guard { input smallattribute | attribute smallattribute; }", + "clear_state | guard { input title | tokenize normalize stem:\"BEST\" | summary title | index title; }", + "clear_state | guard { input title . \" \" . input category | tokenize | summary exact | index exact; }"), + ApplicationBuilder.buildFromFile("src/test/examples/simple.sd")); } @Test - public void testIndexRewrite() throws Exception { + void testIndexRewrite() throws Exception { assertIndexing( Arrays.asList("clear_state | guard { input title_src | lowercase | normalize | " + - " tokenize | index title; }", - "clear_state | guard { input title_src | summary title_s; }"), + " tokenize | index title; }", + "clear_state | guard { input title_src | summary title_s; }"), ApplicationBuilder.buildFromFile("src/test/examples/indexrewrite.sd")); } @Test - public void requireThatPredicateFieldsGetOptimization() { + void requireThatPredicateFieldsGetOptimization() { assertIndexingScript("{ 10 | set_var arity | { input test | optimize_predicate | attribute test; }; }", createPredicateField( "test", DataType.PREDICATE, "{ attribute; }", 10, OptionalLong.empty(), OptionalLong.empty())); @@ -143,7 +143,7 @@ public class IndexingScriptRewriterTestCase extends AbstractSchemaTestCase { "test", DataType.PREDICATE, "{ summary | attribute ; }", 10, OptionalLong.empty(), OptionalLong.empty())); assertIndexingScript( "{ 2 | set_var arity | 0L | set_var lower_bound | 1023L | set_var upper_bound | " + - "{ input test | optimize_predicate | attribute test; }; }", + "{ input test | optimize_predicate | attribute test; }; }", createPredicateField("test", DataType.PREDICATE, "{ attribute; }", 2, OptionalLong.of(0L), OptionalLong.of(1023L))); } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java index 4da6880aa26..aa8a2922e8f 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java @@ -4,7 +4,7 @@ package com.yahoo.schema.processing; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.derived.AbstractExportingTestCase; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Arrays; @@ -18,59 +18,59 @@ import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; public class IndexingValidationTestCase extends AbstractExportingTestCase { @Test - public void testAttributeChanged() throws IOException, ParseException { + void testAttributeChanged() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_attribute_changed.sd", - "For schema 'indexing_attribute_changed', field 'foo': For expression 'attribute foo': " + - "Attempting to assign conflicting values to field 'foo'."); + "For schema 'indexing_attribute_changed', field 'foo': For expression 'attribute foo': " + + "Attempting to assign conflicting values to field 'foo'."); } @Test - public void testAttributeOther() throws IOException, ParseException { + void testAttributeOther() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_attribute_other.sd", - "For schema 'indexing_attribute_other', field 'foo': Indexing expression 'attribute bar' " + - "attempts to write to a field other than 'foo'."); + "For schema 'indexing_attribute_other', field 'foo': Indexing expression 'attribute bar' " + + "attempts to write to a field other than 'foo'."); } @Test - public void testIndexChanged() throws IOException, ParseException { + void testIndexChanged() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_index_changed.sd", - "For schema 'indexing_index_changed', field 'foo': For expression 'index foo': " + - "Attempting to assign conflicting values to field 'foo'."); + "For schema 'indexing_index_changed', field 'foo': For expression 'index foo': " + + "Attempting to assign conflicting values to field 'foo'."); } @Test - public void testIndexOther() throws IOException, ParseException { + void testIndexOther() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_index_other.sd", - "For schema 'indexing_index_other', field 'foo': Indexing expression 'index bar' " + - "attempts to write to a field other than 'foo'."); + "For schema 'indexing_index_other', field 'foo': Indexing expression 'index bar' " + + "attempts to write to a field other than 'foo'."); } @Test - public void testSummaryChanged() throws IOException, ParseException { + void testSummaryChanged() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_summary_changed.sd", - "For schema 'indexing_summary_fail', field 'foo': For expression 'summary foo': Attempting " + - "to assign conflicting values to field 'foo'."); + "For schema 'indexing_summary_fail', field 'foo': For expression 'summary foo': Attempting " + + "to assign conflicting values to field 'foo'."); } @Test - public void testSummaryOther() throws IOException, ParseException { + void testSummaryOther() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_summary_other.sd", - "For schema 'indexing_summary_other', field 'foo': Indexing expression 'summary bar' " + - "attempts to write to a field other than 'foo'."); + "For schema 'indexing_summary_other', field 'foo': Indexing expression 'summary bar' " + + "attempts to write to a field other than 'foo'."); } @Test - public void testExtraField() throws IOException, ParseException { + void testExtraField() throws IOException, ParseException { assertIndexing( Arrays.asList("clear_state | guard { input my_index | tokenize normalize stem:\"BEST\" | index my_index | summary my_index }", - "clear_state | guard { input my_input | tokenize normalize stem:\"BEST\" | index my_extra | summary my_extra }"), + "clear_state | guard { input my_input | tokenize normalize stem:\"BEST\" | index my_extra | summary my_extra }"), ApplicationBuilder.buildFromFile("src/test/examples/indexing_extra.sd")); } @Test - public void requireThatMultilineOutputConflictThrows() throws IOException, ParseException { + void requireThatMultilineOutputConflictThrows() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_multiline_output_conflict.sd", - "For schema 'indexing_multiline_output_confict', field 'cox': For expression 'index cox': " + - "Attempting to assign conflicting values to field 'cox'."); + "For schema 'indexing_multiline_output_confict', field 'cox': For expression 'index cox': " + + "Attempting to assign conflicting values to field 'cox'."); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValuesTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValuesTestCase.java index 2784fe69b28..1f723924db6 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValuesTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValuesTestCase.java @@ -2,7 +2,7 @@ package com.yahoo.schema.processing; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -15,16 +15,16 @@ import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuilds; public class IndexingValuesTestCase { @Test - public void requireThatModifyFieldNoOutputDoesNotThrow() throws IOException, ParseException { + void requireThatModifyFieldNoOutputDoesNotThrow() throws IOException, ParseException { assertBuilds("src/test/examples/indexing_modify_field_no_output.sd"); } @Test - public void requireThatInputOtherFieldThrows() throws IOException, ParseException { + void requireThatInputOtherFieldThrows() throws IOException, ParseException { assertBuildFails("src/test/examples/indexing_input_other_field.sd", - "For schema 'indexing_input_other_field', field 'bar': Indexing expression 'input foo' " + - "attempts to modify the value of the document field 'bar'. " + - "Use a field outside the document block instead."); + "For schema 'indexing_input_other_field', field 'bar': Indexing expression 'input foo' " + + "attempts to modify the value of the document field 'bar'. " + + "Use a field outside the document block instead."); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IntegerIndex2AttributeTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IntegerIndex2AttributeTestCase.java index f36effab146..d3bfe7a8f55 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/IntegerIndex2AttributeTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/IntegerIndex2AttributeTestCase.java @@ -9,13 +9,11 @@ import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.document.SDField; import com.yahoo.schema.parser.ParseException; import com.yahoo.vespa.model.container.search.QueryProfiles; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author baldersheim @@ -23,7 +21,7 @@ import static org.junit.Assert.assertTrue; public class IntegerIndex2AttributeTestCase extends AbstractSchemaTestCase { @Test - public void testIntegerIndex2Attribute() throws IOException, ParseException { + void testIntegerIndex2Attribute() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/integerindex2attribute.sd"); new IntegerIndex2Attribute(schema, new BaseDeployLogger(), new RankProfileRegistry(), new QueryProfiles()).process(true, false); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java index 530b6a95ce8..cbddea8ea6a 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java @@ -1,7 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.schema.processing; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails; @@ -12,25 +12,25 @@ public class MatchPhaseSettingsValidatorTestCase { } @Test - public void requireThatAttributeMustExists() throws Exception { + void requireThatAttributeMustExists() throws Exception { assertBuildFails("src/test/examples/matchphase/non_existing_attribute.sd", getMessagePrefix() + "does not exists"); } @Test - public void requireThatAttributeMustBeNumeric() throws Exception { + void requireThatAttributeMustBeNumeric() throws Exception { assertBuildFails("src/test/examples/matchphase/wrong_data_type_attribute.sd", getMessagePrefix() + "must be single value numeric, but it is 'string'"); } @Test - public void requireThatAttributeMustBeSingleValue() throws Exception { + void requireThatAttributeMustBeSingleValue() throws Exception { assertBuildFails("src/test/examples/matchphase/wrong_collection_type_attribute.sd", getMessagePrefix() + "must be single value numeric, but it is 'Array<int>'"); } @Test - public void requireThatAttributeMustHaveFastSearch() throws Exception { + void requireThatAttributeMustHaveFastSearch() throws Exception { assertBuildFails("src/test/examples/matchphase/non_fast_search_attribute.sd", getMessagePrefix() + "must be fast-search, but it is not"); } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/MatchedElementsOnlyResolverTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/MatchedElementsOnlyResolverTestCase.java index c401376ac3a..bd93a70d7cb 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/MatchedElementsOnlyResolverTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/MatchedElementsOnlyResolverTestCase.java @@ -7,24 +7,18 @@ import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.vespa.documentmodel.SummaryTransform; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import static com.yahoo.config.model.test.TestUtil.joinLines; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * @author geirst */ public class MatchedElementsOnlyResolverTestCase { - @SuppressWarnings("deprecation") - @Rule - public final ExpectedException exceptionRule = ExpectedException.none(); - @Test - public void complex_field_with_some_struct_field_attributes_gets_default_transform() throws ParseException { + void complex_field_with_some_struct_field_attributes_gets_default_transform() throws ParseException { assertSummaryField(joinLines("field my_field type map<string, string> {", " indexing: summary", " summary: matched-elements-only", @@ -48,7 +42,7 @@ public class MatchedElementsOnlyResolverTestCase { } @Test - public void complex_field_with_only_struct_field_attributes_gets_attribute_transform() throws ParseException { + void complex_field_with_only_struct_field_attributes_gets_attribute_transform() throws ParseException { assertSummaryField(joinLines("field my_field type map<string, string> {", " indexing: summary", " summary: matched-elements-only", @@ -76,7 +70,7 @@ public class MatchedElementsOnlyResolverTestCase { } @Test - public void explicit_complex_summary_field_can_use_filter_transform_with_reference_to_source_field() throws ParseException { + void explicit_complex_summary_field_can_use_filter_transform_with_reference_to_source_field() throws ParseException { String documentSummary = joinLines("document-summary my_summary {", " summary my_filter_field type map<string, string> {", " source: my_field", @@ -109,7 +103,7 @@ public class MatchedElementsOnlyResolverTestCase { } @Test - public void primitive_array_attribute_field_gets_attribute_transform() throws ParseException { + void primitive_array_attribute_field_gets_attribute_transform() throws ParseException { assertSummaryField(joinLines("field my_field type array<string> {", " indexing: attribute | summary", " summary: matched-elements-only", @@ -118,7 +112,7 @@ public class MatchedElementsOnlyResolverTestCase { } @Test - public void primitive_weighted_set_attribute_field_gets_attribute_transform() throws ParseException { + void primitive_weighted_set_attribute_field_gets_attribute_transform() throws ParseException { assertSummaryField(joinLines("field my_field type weightedset<string> {", " indexing: attribute | summary", " summary: matched-elements-only", @@ -127,7 +121,7 @@ public class MatchedElementsOnlyResolverTestCase { } @Test - public void explicit_summary_field_can_use_filter_transform_with_reference_to_attribute_source_field() throws ParseException { + void explicit_summary_field_can_use_filter_transform_with_reference_to_attribute_source_field() throws ParseException { String documentSummary = joinLines("document-summary my_summary {", " summary my_filter_field type array<string> {", " source: my_field", @@ -147,17 +141,18 @@ public class MatchedElementsOnlyResolverTestCase { } @Test - public void unsupported_field_type_throws() throws ParseException { - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For schema 'test', document summary 'default', summary field 'my_field': " + + void unsupported_field_type_throws() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + buildSearch(joinLines("field my_field type string {", + " indexing: summary", + " summary: matched-elements-only", + "}")); + }); + assertTrue(exception.getMessage().contains("For schema 'test', document summary 'default', summary field 'my_field': " + "'matched-elements-only' is not supported for this field type. " + "Supported field types are: array of primitive, weighted set of primitive, " + "array of simple struct, map of primitive type to simple struct, " + - "and map of primitive type to primitive type"); - buildSearch(joinLines("field my_field type string {", - " indexing: summary", - " summary: matched-elements-only", - "}")); + "and map of primitive type to primitive type")); } private void assertSummaryField(String fieldContent, String fieldName, SummaryTransform expTransform) throws ParseException { diff --git a/config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java index 912e6fcf030..c143aa43d53 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java @@ -8,15 +8,12 @@ import com.yahoo.schema.document.MatchType; import com.yahoo.schema.document.SDField; import com.yahoo.schema.document.Stemming; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author bratseth @@ -24,7 +21,7 @@ import static org.junit.Assert.fail; public class NGramTestCase extends AbstractSchemaTestCase { @Test - public void testNGram() throws IOException, ParseException { + void testNGram() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/ngram.sd"); assertNotNull(schema); @@ -36,8 +33,8 @@ public class NGramTestCase extends AbstractSchemaTestCase { assertEquals(MatchType.GRAM, gram2.getMatching().getType()); assertEquals(-1, gram2.getMatching().getGramSize()); // Not set explicitly - SDField gram3= schema.getConcreteField("gram_3"); - assertEquals(MatchType.GRAM,gram3.getMatching().getType()); + SDField gram3 = schema.getConcreteField("gram_3"); + assertEquals(MatchType.GRAM, gram3.getMatching().getType()); assertEquals(3, gram3.getMatching().getGramSize()); assertEquals("input gram_1 | ngram 1 | index gram_1 | summary gram_1", gram1.getIndexingScript().iterator().next().toString()); @@ -53,7 +50,7 @@ public class NGramTestCase extends AbstractSchemaTestCase { } @Test - public void testInvalidNGramSetting1() throws IOException, ParseException { + void testInvalidNGramSetting1() throws IOException, ParseException { try { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/invalidngram1.sd"); fail("Should cause an exception"); @@ -64,7 +61,7 @@ public class NGramTestCase extends AbstractSchemaTestCase { } @Test - public void testInvalidNGramSetting2() throws IOException, ParseException { + void testInvalidNGramSetting2() throws IOException, ParseException { try { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/invalidngram2.sd"); fail("Should cause an exception"); @@ -75,7 +72,7 @@ public class NGramTestCase extends AbstractSchemaTestCase { } @Test - public void testInvalidNGramSetting3() throws IOException, ParseException { + void testInvalidNGramSetting3() throws IOException, ParseException { try { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/invalidngram3.sd"); fail("Should cause an exception"); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/PagedAttributeValidatorTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/PagedAttributeValidatorTestCase.java index a291dda24b9..2a3a3ff93e9 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/PagedAttributeValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/PagedAttributeValidatorTestCase.java @@ -3,27 +3,24 @@ package com.yahoo.schema.processing; import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Optional; import static com.yahoo.config.model.test.TestUtil.joinLines; import static com.yahoo.schema.ApplicationBuilder.createFromString; import static com.yahoo.schema.ApplicationBuilder.createFromStrings; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class PagedAttributeValidatorTestCase { @Test - public void dense_tensor_attribute_supports_paged_setting() throws ParseException { + void dense_tensor_attribute_supports_paged_setting() throws ParseException { assertPagedSupported("tensor(x[2],y[2])"); } @Test - public void primitive_attribute_types_support_paged_setting() throws ParseException { + void primitive_attribute_types_support_paged_setting() throws ParseException { assertPagedSupported("int"); assertPagedSupported("array<int>"); assertPagedSupported("weightedset<int>"); @@ -34,7 +31,7 @@ public class PagedAttributeValidatorTestCase { } @Test - public void struct_field_attributes_support_paged_setting() throws ParseException { + void struct_field_attributes_support_paged_setting() throws ParseException { var sd = joinLines("schema test {", " document test {", " struct elem {", @@ -68,17 +65,17 @@ public class PagedAttributeValidatorTestCase { } @Test - public void non_dense_tensor_attribute_does_not_support_paged_setting() throws ParseException { + void non_dense_tensor_attribute_does_not_support_paged_setting() throws ParseException { assertPagedSettingNotSupported("tensor(x{},y[2])"); } @Test - public void predicate_attribute_does_not_support_paged_setting() throws ParseException { + void predicate_attribute_does_not_support_paged_setting() throws ParseException { assertPagedSettingNotSupported("predicate"); } @Test - public void reference_attribute_does_not_support_paged_setting() throws ParseException { + void reference_attribute_does_not_support_paged_setting() throws ParseException { assertPagedSettingNotSupported("reference<parent>", Optional.of(getSd("parent", "int"))); } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/PositionTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/PositionTestCase.java index e4f32fff41d..1b950523588 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/PositionTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/PositionTestCase.java @@ -11,12 +11,12 @@ import com.yahoo.schema.document.FieldSet; import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.vespa.documentmodel.SummaryTransform; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Iterator; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Test Position processor. @@ -26,7 +26,7 @@ import static org.junit.Assert.*; public class PositionTestCase { @Test - public void inherited_position_zcurve_field_is_not_added_to_document_fieldset() throws Exception { + void inherited_position_zcurve_field_is_not_added_to_document_fieldset() throws Exception { ApplicationBuilder sb = ApplicationBuilder.createFromFiles(Arrays.asList( "src/test/examples/position_base.sd", "src/test/examples/position_inherited.sd")); @@ -37,7 +37,7 @@ public class PositionTestCase { } @Test - public void requireThatPositionCanBeAttribute() throws Exception { + void requireThatPositionCanBeAttribute() throws Exception { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/position_attribute.sd"); assertNull(schema.getAttribute("pos")); assertNull(schema.getAttribute("pos.x")); @@ -48,18 +48,18 @@ public class PositionTestCase { } @Test - public void requireThatPositionCanNotBeIndex() throws Exception { + void requireThatPositionCanNotBeIndex() throws Exception { try { ApplicationBuilder.buildFromFile("src/test/examples/position_index.sd"); fail(); } catch (IllegalArgumentException e) { assertEquals("For schema 'position_index', field 'pos': Indexing of data type 'position' is not " + - "supported, replace 'index' statement with 'attribute'.", e.getMessage()); + "supported, replace 'index' statement with 'attribute'.", e.getMessage()); } } @Test - public void requireThatSummaryAloneDoesNotCreateZCurve() throws Exception { + void requireThatSummaryAloneDoesNotCreateZCurve() throws Exception { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/position_summary.sd"); assertNull(schema.getAttribute("pos")); assertNull(schema.getAttribute("pos.x")); @@ -78,7 +78,7 @@ public class PositionTestCase { } @Test - public void requireThatExtraFieldCanBePositionAttribute() throws Exception { + void requireThatExtraFieldCanBePositionAttribute() throws Exception { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/position_extra.sd"); assertNull(schema.getAttribute("pos_ext")); assertNull(schema.getAttribute("pos_ext.x")); @@ -89,7 +89,7 @@ public class PositionTestCase { } @Test - public void requireThatPositionArrayIsSupported() throws Exception { + void requireThatPositionArrayIsSupported() throws Exception { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/position_array.sd"); assertNull(schema.getAttribute("pos")); assertNull(schema.getAttribute("pos.x")); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankModifierTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankModifierTestCase.java index 69bf62be84b..f49b1df8cea 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankModifierTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankModifierTestCase.java @@ -5,7 +5,7 @@ import com.yahoo.schema.Schema; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -16,7 +16,7 @@ import java.io.IOException; */ public class RankModifierTestCase extends AbstractSchemaTestCase { @Test - public void testLiteral() throws IOException, ParseException { + void testLiteral() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/rankmodifier/literal.sd"); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankProfileSearchFixture.java b/config-model/src/test/java/com/yahoo/schema/processing/RankProfileSearchFixture.java index e380b1ab9af..15fe8250b71 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankProfileSearchFixture.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankProfileSearchFixture.java @@ -27,7 +27,7 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Helper class for setting up and asserting over a Search instance with a rank profile given literally diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankPropertyVariablesTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankPropertyVariablesTestCase.java index dab1d9e6e95..077017cc70e 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankPropertyVariablesTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankPropertyVariablesTestCase.java @@ -9,22 +9,22 @@ import com.yahoo.schema.Schema; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.List; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; public class RankPropertyVariablesTestCase extends AbstractSchemaTestCase { @Test - public void testRankPropVariables() throws IOException, ParseException { + void testRankPropVariables() throws IOException, ParseException { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/rankpropvars.sd", - new BaseDeployLogger(), - rankProfileRegistry, - new QueryProfileRegistry()); + new BaseDeployLogger(), + rankProfileRegistry, + new QueryProfileRegistry()); assertRankPropEquals(rankProfileRegistry.get(schema, "other").getRankProperties(), "$testvar1", "foo"); assertRankPropEquals(rankProfileRegistry.get(schema, "other").getRankProperties(), "$testvar_2", "bar"); assertRankPropEquals(rankProfileRegistry.get(schema, "other").getRankProperties(), "$testvarOne23", "baz"); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionTypeResolverTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionTypeResolverTestCase.java index f2f2a82b97c..c6d6332b4c0 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionTypeResolverTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionTypeResolverTestCase.java @@ -11,7 +11,7 @@ import com.yahoo.schema.ApplicationBuilder; import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode; import com.yahoo.tensor.TensorType; import com.yahoo.yolean.Exceptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; @@ -20,10 +20,7 @@ import java.util.logging.Level; import java.util.stream.Collectors; import static com.yahoo.config.model.test.TestUtil.joinLines; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author bratseth @@ -31,7 +28,7 @@ import static org.junit.Assert.fail; public class RankingExpressionTypeResolverTestCase { @Test - public void tensorFirstPhaseMustProduceDouble() throws Exception { + void tensorFirstPhaseMustProduceDouble() throws Exception { try { ApplicationBuilder builder = new ApplicationBuilder(); builder.addSchema(joinLines( @@ -53,13 +50,13 @@ public class RankingExpressionTypeResolverTestCase { } catch (IllegalArgumentException expected) { assertEquals("In schema 'test', rank profile 'my_rank_profile': The first-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[10],y[3])", - Exceptions.toMessageString(expected)); + Exceptions.toMessageString(expected)); } } @Test - public void tensorFirstPhaseFromConstantMustProduceDouble() throws Exception { + void tensorFirstPhaseFromConstantMustProduceDouble() throws Exception { try { ApplicationBuilder builder = new ApplicationBuilder(); builder.addSchema(joinLines( @@ -95,14 +92,13 @@ public class RankingExpressionTypeResolverTestCase { } catch (IllegalArgumentException expected) { assertEquals("In schema 'test', rank profile 'my_rank_profile': The first-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x{},y{},z{})", - Exceptions.toMessageString(expected)); + Exceptions.toMessageString(expected)); } } - @Test - public void tensorSecondPhaseMustProduceDouble() throws Exception { + void tensorSecondPhaseMustProduceDouble() throws Exception { try { ApplicationBuilder builder = new ApplicationBuilder(); builder.addSchema(joinLines( @@ -127,12 +123,12 @@ public class RankingExpressionTypeResolverTestCase { } catch (IllegalArgumentException expected) { assertEquals("In schema 'test', rank profile 'my_rank_profile': The second-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[10],y[3])", - Exceptions.toMessageString(expected)); + Exceptions.toMessageString(expected)); } } @Test - public void tensorConditionsMustHaveTypeCompatibleBranches() throws Exception { + void tensorConditionsMustHaveTypeCompatibleBranches() throws Exception { try { ApplicationBuilder schemaBuilder = new ApplicationBuilder(); schemaBuilder.addSchema(joinLines( @@ -157,14 +153,14 @@ public class RankingExpressionTypeResolverTestCase { } catch (IllegalArgumentException expected) { assertEquals("In schema 'test', rank profile 'my_rank_profile': The first-phase expression is invalid: An if expression must produce compatible types in both alternatives, but the 'true' type is tensor(x[10],y[5]) while the 'false' type is tensor(z[10])" + - "\n'true' branch: attribute(a)" + - "\n'false' branch: attribute(b)", - Exceptions.toMessageString(expected)); + "\n'true' branch: attribute(a)" + + "\n'false' branch: attribute(b)", + Exceptions.toMessageString(expected)); } } @Test - public void testFunctionInvocationTypes() throws Exception { + void testFunctionInvocationTypes() throws Exception { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); ApplicationBuilder builder = new ApplicationBuilder(rankProfileRegistry); builder.addSchema(joinLines( @@ -192,13 +188,13 @@ public class RankingExpressionTypeResolverTestCase { RankProfile profile = builder.getRankProfileRegistry().get(builder.getSchema(), "my_rank_profile"); assertEquals(TensorType.fromSpec("tensor(x[10],y[3])"), - summaryFeatures(profile).get("macro1(a)").type(profile.typeContext(builder.getQueryProfileRegistry()))); + summaryFeatures(profile).get("macro1(a)").type(profile.typeContext(builder.getQueryProfileRegistry()))); assertEquals(TensorType.fromSpec("tensor(z[10])"), - summaryFeatures(profile).get("macro1(b)").type(profile.typeContext(builder.getQueryProfileRegistry()))); + summaryFeatures(profile).get("macro1(b)").type(profile.typeContext(builder.getQueryProfileRegistry()))); } @Test - public void testTensorFunctionInvocationTypes_Nested() throws Exception { + void testTensorFunctionInvocationTypes_Nested() throws Exception { ApplicationBuilder builder = new ApplicationBuilder(); builder.addSchema(joinLines( "search test {", @@ -234,52 +230,52 @@ public class RankingExpressionTypeResolverTestCase { RankProfile profile = builder.getRankProfileRegistry().get(builder.getSchema(), "my_rank_profile"); assertEquals(TensorType.fromSpec("tensor(x[10],y[1])"), - summaryFeatures(profile).get("return_a").type(profile.typeContext(builder.getQueryProfileRegistry()))); + summaryFeatures(profile).get("return_a").type(profile.typeContext(builder.getQueryProfileRegistry()))); assertEquals(TensorType.fromSpec("tensor(z[10])"), - summaryFeatures(profile).get("return_b").type(profile.typeContext(builder.getQueryProfileRegistry()))); + summaryFeatures(profile).get("return_b").type(profile.typeContext(builder.getQueryProfileRegistry()))); } @Test - public void testAttributeInvocationViaBoundIdentifier() throws Exception { + void testAttributeInvocationViaBoundIdentifier() throws Exception { ApplicationBuilder builder = new ApplicationBuilder(); builder.addSchema(joinLines( - "search newsarticle {", - " document newsarticle {", - " field title type string {", - " indexing {", - " input title | index", - " }", - " weight: 30", - " }", - " field usstaticrank type int {", - " indexing: summary | attribute", - " }", - " field eustaticrank type int {", - " indexing: summary | attribute", - " }", - " }", - " rank-profile default {", - " macro newsboost() { ", - " expression: 200 * matches(title)", - " }", - " macro commonboost(mystaticrank) { ", - " expression: attribute(mystaticrank) + newsboost", - " }", - " macro commonfirstphase(mystaticrank) { ", - " expression: nativeFieldMatch(title) + commonboost(mystaticrank) ", - " }", - " first-phase { expression: commonfirstphase(usstaticrank) }", - " }", - " rank-profile eurank inherits default {", - " first-phase { expression: commonfirstphase(eustaticrank) }", - " }", - "}")); + "search newsarticle {", + " document newsarticle {", + " field title type string {", + " indexing {", + " input title | index", + " }", + " weight: 30", + " }", + " field usstaticrank type int {", + " indexing: summary | attribute", + " }", + " field eustaticrank type int {", + " indexing: summary | attribute", + " }", + " }", + " rank-profile default {", + " macro newsboost() { ", + " expression: 200 * matches(title)", + " }", + " macro commonboost(mystaticrank) { ", + " expression: attribute(mystaticrank) + newsboost", + " }", + " macro commonfirstphase(mystaticrank) { ", + " expression: nativeFieldMatch(title) + commonboost(mystaticrank) ", + " }", + " first-phase { expression: commonfirstphase(usstaticrank) }", + " }", + " rank-profile eurank inherits default {", + " first-phase { expression: commonfirstphase(eustaticrank) }", + " }", + "}")); builder.build(true); RankProfile profile = builder.getRankProfileRegistry().get(builder.getSchema(), "eurank"); } @Test - public void testTensorFunctionInvocationTypes_NestedSameName() throws Exception { + void testTensorFunctionInvocationTypes_NestedSameName() throws Exception { ApplicationBuilder builder = new ApplicationBuilder(); builder.addSchema(joinLines( "search test {", @@ -318,35 +314,35 @@ public class RankingExpressionTypeResolverTestCase { RankProfile profile = builder.getRankProfileRegistry().get(builder.getSchema(), "my_rank_profile"); assertEquals(TensorType.fromSpec("tensor(x[10],y[1])"), - summaryFeatures(profile).get("return_a").type(profile.typeContext(builder.getQueryProfileRegistry()))); + summaryFeatures(profile).get("return_a").type(profile.typeContext(builder.getQueryProfileRegistry()))); assertEquals(TensorType.fromSpec("tensor(z[10])"), - summaryFeatures(profile).get("return_b").type(profile.typeContext(builder.getQueryProfileRegistry()))); + summaryFeatures(profile).get("return_b").type(profile.typeContext(builder.getQueryProfileRegistry()))); } @Test - public void testTensorFunctionInvocationTypes_viaFuncWithExpr() throws Exception { + void testTensorFunctionInvocationTypes_viaFuncWithExpr() throws Exception { ApplicationBuilder builder = new ApplicationBuilder(); builder.addSchema(joinLines( - "search test {", - " document test {", - " field t1 type tensor<float>(y{}) { indexing: attribute | summary }", - " field t2 type tensor<float>(x{}) { indexing: attribute | summary }", - " }", - " rank-profile test {", - " function my_func(t) { expression: sum(t, x) + 1 }", - " function test_func_via_func_with_expr() { expression: call_func_with_expr( attribute(t1), attribute(t2) ) }", - " function call_func_with_expr(a, b) { expression: my_func( a * b ) }", - " summary-features { test_func_via_func_with_expr }", - " }", - "}")); + "search test {", + " document test {", + " field t1 type tensor<float>(y{}) { indexing: attribute | summary }", + " field t2 type tensor<float>(x{}) { indexing: attribute | summary }", + " }", + " rank-profile test {", + " function my_func(t) { expression: sum(t, x) + 1 }", + " function test_func_via_func_with_expr() { expression: call_func_with_expr( attribute(t1), attribute(t2) ) }", + " function call_func_with_expr(a, b) { expression: my_func( a * b ) }", + " summary-features { test_func_via_func_with_expr }", + " }", + "}")); builder.build(true); RankProfile profile = builder.getRankProfileRegistry().get(builder.getSchema(), "test"); assertEquals(TensorType.fromSpec("tensor<float>(y{})"), - summaryFeatures(profile).get("test_func_via_func_with_expr").type(profile.typeContext(builder.getQueryProfileRegistry()))); + summaryFeatures(profile).get("test_func_via_func_with_expr").type(profile.typeContext(builder.getQueryProfileRegistry()))); } @Test - public void importedFieldsAreAvailable() throws Exception { + void importedFieldsAreAvailable() throws Exception { ApplicationBuilder builder = new ApplicationBuilder(); builder.addSchema(joinLines( "search parent {", @@ -361,7 +357,7 @@ public class RankingExpressionTypeResolverTestCase { "search child {", " document child { ", " field ref type reference<parent> {", - "indexing: attribute | summary", + "indexing: attribute | summary", " }", " }", " import field ref.a as imported_a {}", @@ -376,14 +372,14 @@ public class RankingExpressionTypeResolverTestCase { } @Test - public void undeclaredQueryFeaturesAreAccepted() throws Exception { + void undeclaredQueryFeaturesAreAccepted() throws Exception { InspectableDeployLogger logger = new InspectableDeployLogger(); ApplicationBuilder builder = new ApplicationBuilder(logger); builder.addSchema(joinLines( "search test {", " document test { ", " field anyfield type double {" + - " indexing: attribute", + " indexing: attribute", " }", " }", " rank-profile my_rank_profile {", @@ -402,7 +398,7 @@ public class RankingExpressionTypeResolverTestCase { } @Test - public void undeclaredQueryFeaturesAreNotAcceptedWhenStrict() throws Exception { + void undeclaredQueryFeaturesAreNotAcceptedWhenStrict() throws Exception { try { InspectableDeployLogger logger = new InspectableDeployLogger(); ApplicationBuilder builder = new ApplicationBuilder(logger); @@ -410,12 +406,12 @@ public class RankingExpressionTypeResolverTestCase { "search test {", " document test { ", " field anyfield type double {" + - " indexing: attribute", + " indexing: attribute", " }", " }", " rank-profile my_rank_profile {", " strict: true" + - " first-phase {", + " first-phase {", " expression: query(foo) + f() + sum(attribute(anyfield))", " }", " function f() {", @@ -428,12 +424,12 @@ public class RankingExpressionTypeResolverTestCase { } catch (IllegalArgumentException e) { assertEquals("In schema 'test', rank profile 'my_rank_profile': rank profile 'my_rank_profile' is strict but is missing a query profile type declaration of features [query(bar), query(baz), query(foo)]", - Exceptions.toMessageString(e)); + Exceptions.toMessageString(e)); } } @Test - public void undeclaredQueryFeaturesAreAcceptedWithWarningWhenUsingTensors() throws Exception { + void undeclaredQueryFeaturesAreAcceptedWithWarningWhenUsingTensors() throws Exception { InspectableDeployLogger logger = new InspectableDeployLogger(); ApplicationBuilder builder = new ApplicationBuilder(logger); builder.addSchema(joinLines( @@ -457,24 +453,24 @@ public class RankingExpressionTypeResolverTestCase { String message = logger.findMessage("The following query features"); assertNotNull(message); assertEquals("WARNING: The following query features used in rank profile 'my_rank_profile' are not declared and " + - "will be interpreted as scalars, not tensors: [query(bar), query(baz), query(foo)]", - message); + "will be interpreted as scalars, not tensors: [query(bar), query(baz), query(foo)]", + message); } @Test - public void noWarningWhenUsingTensorsWhenQueryFeaturesAreDeclared() throws Exception { + void noWarningWhenUsingTensorsWhenQueryFeaturesAreDeclared() throws Exception { InspectableDeployLogger logger = new InspectableDeployLogger(); ApplicationBuilder builder = new ApplicationBuilder(logger); QueryProfileType myType = new QueryProfileType("mytype"); myType.addField(new FieldDescription("rank.feature.query(foo)", - new TensorFieldType(TensorType.fromSpec("tensor(d[2])"))), - builder.getQueryProfileRegistry().getTypeRegistry()); + new TensorFieldType(TensorType.fromSpec("tensor(d[2])"))), + builder.getQueryProfileRegistry().getTypeRegistry()); myType.addField(new FieldDescription("rank.feature.query(bar)", - new TensorFieldType(TensorType.fromSpec("tensor(d[2])"))), - builder.getQueryProfileRegistry().getTypeRegistry()); + new TensorFieldType(TensorType.fromSpec("tensor(d[2])"))), + builder.getQueryProfileRegistry().getTypeRegistry()); myType.addField(new FieldDescription("rank.feature.query(baz)", - new TensorFieldType(TensorType.fromSpec("tensor(d[2])"))), - builder.getQueryProfileRegistry().getTypeRegistry()); + new TensorFieldType(TensorType.fromSpec("tensor(d[2])"))), + builder.getQueryProfileRegistry().getTypeRegistry()); builder.getQueryProfileRegistry().getTypeRegistry().register(myType); builder.addSchema(joinLines( "search test {", diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithLightGBMTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithLightGBMTestCase.java index 4df0a09ec2e..50cc12e9b33 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithLightGBMTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithLightGBMTestCase.java @@ -5,8 +5,8 @@ import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.io.IOUtils; import com.yahoo.path.Path; import com.yahoo.schema.parser.ParseException; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -20,25 +20,25 @@ public class RankingExpressionWithLightGBMTestCase { private final static String lightGBMExpression = "if (!(numerical_2 >= 0.46643291586559305), 2.1594397038037663, if (categorical_2 in [\"k\", \"l\", \"m\"], 2.235297305276056, 2.1792953471546546)) + if (categorical_1 in [\"d\", \"e\"], 0.03070842919354316, if (!(numerical_1 >= 0.5102250691730842), -0.04439151147520909, 0.005117411709368601)) + if (!(numerical_2 >= 0.668665477622446), if (!(numerical_2 >= 0.008118820676863816), -0.15361238490967524, -0.01192330846157292), 0.03499044894987518) + if (!(numerical_1 >= 0.5201391072644542), -0.02141000620783247, if (categorical_1 in [\"a\", \"b\"], -0.004121485787596721, 0.04534090904886873)) + if (categorical_2 in [\"k\", \"l\", \"m\"], if (!(numerical_2 >= 0.27283279016959255), -0.01924803254356527, 0.03643772842347651), -0.02701711918923075)"; - @After + @AfterEach public void removeGeneratedModelFiles() { IOUtils.recursiveDeleteDir(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); } @Test - public void testLightGBMReference() { + void testLightGBMReference() { RankProfileSearchFixture search = fixtureWith("lightgbm('regression.json')"); search.assertFirstPhaseExpression(lightGBMExpression, "my_profile"); } @Test - public void testNestedLightGBMReference() { + void testNestedLightGBMReference() { RankProfileSearchFixture search = fixtureWith("5 + sum(lightgbm('regression.json'))"); search.assertFirstPhaseExpression("5 + reduce(" + lightGBMExpression + ", sum)", "my_profile"); } @Test - public void testImportingFromStoredExpressions() throws IOException { + void testImportingFromStoredExpressions() throws IOException { RankProfileSearchFixture search = fixtureWith("lightgbm('regression.json')"); search.assertFirstPhaseExpression(lightGBMExpression, "my_profile"); @@ -47,7 +47,7 @@ public class RankingExpressionWithLightGBMTestCase { try { storedApplicationDirectory.toFile().mkdirs(); IOUtils.copyDirectory(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile(), - storedApplicationDirectory.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); + storedApplicationDirectory.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); RankingExpressionWithOnnxTestCase.StoringApplicationPackage storedApplication = new RankingExpressionWithOnnxTestCase.StoringApplicationPackage(storedApplicationDirectory); RankProfileSearchFixture searchFromStored = fixtureWith("lightgbm('regression.json')"); searchFromStored.assertFirstPhaseExpression(lightGBMExpression, "my_profile"); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithOnnxModelTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithOnnxModelTestCase.java index 1280895bfc0..22681858fc3 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithOnnxModelTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithOnnxModelTestCase.java @@ -12,23 +12,23 @@ import com.yahoo.vespa.config.search.core.RankingConstantsConfig; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.search.DocumentDatabase; import com.yahoo.vespa.model.search.IndexedSearchCluster; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class RankingExpressionWithOnnxModelTestCase { private final Path applicationDir = Path.fromString("src/test/integration/onnx-model/"); - @After + @AfterEach public void removeGeneratedModelFiles() { IOUtils.recursiveDeleteDir(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); } @Test - public void testOnnxModelFeature() throws Exception { + void testOnnxModelFeature() throws Exception { VespaModel model = loadModel(applicationDir); assertTransformedFeature(model); assertGeneratedConfig(model); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithOnnxTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithOnnxTestCase.java index bfd0520c62a..83d19b010bb 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithOnnxTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithOnnxTestCase.java @@ -12,8 +12,8 @@ import com.yahoo.schema.FeatureNames; import com.yahoo.schema.parser.ParseException; import com.yahoo.tensor.TensorType; import com.yahoo.yolean.Exceptions; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileReader; @@ -23,10 +23,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class RankingExpressionWithOnnxTestCase { @@ -35,13 +32,13 @@ public class RankingExpressionWithOnnxTestCase { private final static String name = "mnist_softmax"; private final static String vespaExpression = "join(reduce(join(rename(Placeholder, (d0, d1), (d0, d2)), constant(mnist_softmax_layer_Variable), f(a,b)(a * b)), sum, d2) * 1.0, constant(mnist_softmax_layer_Variable_1) * 1.0, f(a,b)(a + b))"; - @After + @AfterEach public void removeGeneratedModelFiles() { IOUtils.recursiveDeleteDir(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); } @Test - public void testOnnxReferenceWithConstantFeature() { + void testOnnxReferenceWithConstantFeature() { RankProfileSearchFixture search = fixtureWith("constant(mytensor)", "onnx_vespa('mnist_softmax.onnx')", "constant mytensor { file: ignored\ntype: tensor<float>(d0[1],d1[784]) }", @@ -50,12 +47,12 @@ public class RankingExpressionWithOnnxTestCase { } @Test - public void testOnnxReferenceWithQueryFeature() { + void testOnnxReferenceWithQueryFeature() { String queryProfile = "<query-profile id='default' type='root'/>"; String queryProfileType = "<query-profile-type id='root'>" + - " <field name='query(mytensor)' type='tensor<float>(d0[1],d1[784])'/>" + - "</query-profile-type>"; + " <field name='query(mytensor)' type='tensor<float>(d0[1],d1[784])'/>" + + "</query-profile-type>"; StoringApplicationPackage application = new StoringApplicationPackage(applicationDir, queryProfile, queryProfileType); @@ -69,7 +66,7 @@ public class RankingExpressionWithOnnxTestCase { } @Test - public void testOnnxReferenceWithDocumentFeature() { + void testOnnxReferenceWithDocumentFeature() { StoringApplicationPackage application = new StoringApplicationPackage(applicationDir); RankProfileSearchFixture search = fixtureWith("attribute(mytensor)", "onnx_vespa('mnist_softmax.onnx')", @@ -82,12 +79,12 @@ public class RankingExpressionWithOnnxTestCase { @Test - public void testOnnxReferenceWithFeatureCombination() { + void testOnnxReferenceWithFeatureCombination() { String queryProfile = "<query-profile id='default' type='root'/>"; String queryProfileType = "<query-profile-type id='root'>" + - " <field name='query(mytensor)' type='tensor<float>(d0[1],d1[784],d2[10])'/>" + - "</query-profile-type>"; + " <field name='query(mytensor)' type='tensor<float>(d0[1],d1[784],d2[10])'/>" + + "</query-profile-type>"; StoringApplicationPackage application = new StoringApplicationPackage(applicationDir, queryProfile, queryProfileType); RankProfileSearchFixture search = fixtureWith("sum(query(mytensor) * attribute(mytensor) * constant(mytensor),d2)", "onnx_vespa('mnist_softmax.onnx')", @@ -100,28 +97,28 @@ public class RankingExpressionWithOnnxTestCase { @Test - public void testNestedOnnxReference() { + void testNestedOnnxReference() { RankProfileSearchFixture search = fixtureWith("tensor<float>(d0[1],d1[784])(0.0)", "5 + sum(onnx_vespa('mnist_softmax.onnx'))"); search.assertFirstPhaseExpression("5 + reduce(" + vespaExpression + ", sum)", "my_profile"); } @Test - public void testOnnxReferenceWithSpecifiedOutput() { + void testOnnxReferenceWithSpecifiedOutput() { RankProfileSearchFixture search = fixtureWith("tensor<float>(d0[1],d1[784])(0.0)", "onnx_vespa('mnist_softmax.onnx', 'layer_add')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); } @Test - public void testOnnxReferenceWithSpecifiedOutputAndSignature() { + void testOnnxReferenceWithSpecifiedOutputAndSignature() { RankProfileSearchFixture search = fixtureWith("tensor<float>(d0[1],d1[784])(0.0)", "onnx_vespa('mnist_softmax.onnx', 'default.layer_add')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); } @Test - public void testOnnxReferenceMissingFunction() throws ParseException { + void testOnnxReferenceMissingFunction() throws ParseException { try { RankProfileSearchFixture search = new RankProfileSearchFixture( new StoringApplicationPackage(applicationDir), @@ -137,15 +134,15 @@ public class RankingExpressionWithOnnxTestCase { } catch (IllegalArgumentException expected) { assertEquals("Rank profile 'my_profile' is invalid: Could not use Onnx model from " + - "onnx_vespa(\"mnist_softmax.onnx\"): " + - "Model refers input 'Placeholder' of type tensor<float>(d0[1],d1[784]) but this function is " + - "not present in rank profile 'my_profile'", + "onnx_vespa(\"mnist_softmax.onnx\"): " + + "Model refers input 'Placeholder' of type tensor<float>(d0[1],d1[784]) but this function is " + + "not present in rank profile 'my_profile'", Exceptions.toMessageString(expected)); } } @Test - public void testOnnxReferenceWithWrongFunctionType() { + void testOnnxReferenceWithWrongFunctionType() { try { RankProfileSearchFixture search = fixtureWith("tensor(d0[1],d5[10])(0.0)", "onnx_vespa('mnist_softmax.onnx')"); @@ -154,15 +151,15 @@ public class RankingExpressionWithOnnxTestCase { } catch (IllegalArgumentException expected) { assertEquals("Rank profile 'my_profile' is invalid: Could not use Onnx model from " + - "onnx_vespa(\"mnist_softmax.onnx\"): " + - "Model refers input 'Placeholder'. The required type of this is tensor<float>(d0[1],d1[784]), " + - "but this function returns tensor(d0[1],d5[10])", + "onnx_vespa(\"mnist_softmax.onnx\"): " + + "Model refers input 'Placeholder'. The required type of this is tensor<float>(d0[1],d1[784]), " + + "but this function returns tensor(d0[1],d5[10])", Exceptions.toMessageString(expected)); } } @Test - public void testOnnxReferenceSpecifyingNonExistingOutput() { + void testOnnxReferenceSpecifyingNonExistingOutput() { try { RankProfileSearchFixture search = fixtureWith("tensor<float>(d0[2],d1[784])(0.0)", "onnx_vespa('mnist_softmax.onnx', 'y')"); @@ -171,14 +168,14 @@ public class RankingExpressionWithOnnxTestCase { } catch (IllegalArgumentException expected) { assertEquals("Rank profile 'my_profile' is invalid: Could not use Onnx model from " + - "onnx_vespa(\"mnist_softmax.onnx\",\"y\"): " + - "No expressions named 'y' in model 'mnist_softmax.onnx'. Available expressions: default.layer_add", - Exceptions.toMessageString(expected)); + "onnx_vespa(\"mnist_softmax.onnx\",\"y\"): " + + "No expressions named 'y' in model 'mnist_softmax.onnx'. Available expressions: default.layer_add", + Exceptions.toMessageString(expected)); } } @Test - public void testImportingFromStoredExpressions() throws IOException { + void testImportingFromStoredExpressions() throws IOException { RankProfileSearchFixture search = fixtureWith("tensor<float>(d0[1],d1[784])(0.0)", "onnx_vespa(\"mnist_softmax.onnx\")"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); @@ -206,7 +203,7 @@ public class RankingExpressionWithOnnxTestCase { } @Test - public void testImportingFromStoredExpressionsWithFunctionOverridingConstantAndInheritance() throws IOException { + void testImportingFromStoredExpressionsWithFunctionOverridingConstantAndInheritance() throws IOException { String rankProfile = " rank-profile my_profile {\n" + " function Placeholder() {\n" + @@ -230,8 +227,8 @@ public class RankingExpressionWithOnnxTestCase { search.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile"); search.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile_child"); - assertNull("Constant overridden by function is not added", - search.search().constants().get(name + "_Variable")); + assertNull(search.search().constants().get(name + "_Variable"), + "Constant overridden by function is not added"); // At this point the expression is stored - copy application to another location which do not have a models dir Path storedApplicationDirectory = applicationDir.getParentPath().append("copy"); @@ -245,18 +242,18 @@ public class RankingExpressionWithOnnxTestCase { searchFromStored.compileRankProfile("my_profile_child", applicationDir.append("models")); searchFromStored.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile"); searchFromStored.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile_child"); - assertNull("Constant overridden by function is not added", - searchFromStored.search().constants().get(name + "_Variable")); + assertNull(searchFromStored.search().constants().get(name + "_Variable"), + "Constant overridden by function is not added"); } finally { IOUtils.recursiveDeleteDir(storedApplicationDirectory.toFile()); } } @Test - public void testFunctionGeneration() { + void testFunctionGeneration() { final String name = "small_constants_and_functions"; final String rankProfiles = - " rank-profile my_profile {\n" + + " rank-profile my_profile {\n" + " function input() {\n" + " expression: tensor<float>(d0[3])(0.0)\n" + " }\n" + @@ -275,7 +272,7 @@ public class RankingExpressionWithOnnxTestCase { } @Test - public void testImportingFromStoredExpressionsWithSmallConstantsAndInheritance() throws IOException { + void testImportingFromStoredExpressionsWithSmallConstantsAndInheritance() throws IOException { final String name = "small_constants_and_functions"; final String rankProfiles = " rank-profile my_profile {\n" + diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTensorTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTensorTestCase.java index 1f065bc7a20..c5bd0821007 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTensorTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTensorTestCase.java @@ -2,10 +2,10 @@ package com.yahoo.schema.processing; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author geirst @@ -13,16 +13,16 @@ import static org.junit.Assert.fail; public class RankingExpressionWithTensorTestCase { @Test - public void requireThatSingleLineConstantMappedTensorCanBeParsed() throws ParseException { + void requireThatSingleLineConstantMappedTensorCanBeParsed() throws ParseException { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: sum(my_tensor)\n" + - " }\n" + - " constants {\n" + - " my_tensor tensor(x{},y{}):{ {x:1,y:2}:1, {x:2,y:1}:2 }\n" + - " }\n" + - " }"); + " first-phase {\n" + + " expression: sum(my_tensor)\n" + + " }\n" + + " constants {\n" + + " my_tensor tensor(x{},y{}):{ {x:1,y:2}:1, {x:2,y:1}:2 }\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); f.assertFirstPhaseExpression("reduce(constant(my_tensor), sum)", "my_profile"); f.assertRankProperty("tensor(x{},y{}):{{x:1,y:2}:1.0, {x:2,y:1}:2.0}", "constant(my_tensor).value", "my_profile"); @@ -30,16 +30,16 @@ public class RankingExpressionWithTensorTestCase { } @Test - public void requireThatSingleLineConstantIndexedTensorCanBeParsed() throws ParseException { + void requireThatSingleLineConstantIndexedTensorCanBeParsed() throws ParseException { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: sum(my_tensor)\n" + - " }\n" + - " constants {\n" + - " my_tensor tensor(x[3]):{ {x:0}:1, {x:1}:2, {x:2}:3 }\n" + - " }\n" + - " }"); + " first-phase {\n" + + " expression: sum(my_tensor)\n" + + " }\n" + + " constants {\n" + + " my_tensor tensor(x[3]):{ {x:0}:1, {x:1}:2, {x:2}:3 }\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); f.assertFirstPhaseExpression("reduce(constant(my_tensor), sum)", "my_profile"); f.assertRankProperty("tensor(x[3]):[1.0, 2.0, 3.0]", "constant(my_tensor).value", "my_profile"); @@ -47,16 +47,16 @@ public class RankingExpressionWithTensorTestCase { } @Test - public void requireThatSingleLineConstantIndexedTensorShortFormCanBeParsed() throws ParseException { + void requireThatSingleLineConstantIndexedTensorShortFormCanBeParsed() throws ParseException { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: sum(my_tensor)\n" + - " }\n" + - " constants {\n" + - " my_tensor tensor(x[3]):[1, 2, 3]\n" + - " }\n" + - " }"); + " first-phase {\n" + + " expression: sum(my_tensor)\n" + + " }\n" + + " constants {\n" + + " my_tensor tensor(x[3]):[1, 2, 3]\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); f.assertFirstPhaseExpression("reduce(constant(my_tensor), sum)", "my_profile"); f.assertRankProperty("tensor(x[3]):[1.0, 2.0, 3.0]", "constant(my_tensor).value", "my_profile"); @@ -64,16 +64,16 @@ public class RankingExpressionWithTensorTestCase { } @Test - public void requireConstantTensorCanBeReferredViaConstantFeature() throws ParseException { + void requireConstantTensorCanBeReferredViaConstantFeature() throws ParseException { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: sum(constant(my_tensor))\n" + - " }\n" + - " constants {\n" + - " my_tensor tensor(x{},y{}):{{x:1,y:2}:1, {x:2,y:1}:2}\n" + - " }\n" + - " }"); + " first-phase {\n" + + " expression: sum(constant(my_tensor))\n" + + " }\n" + + " constants {\n" + + " my_tensor tensor(x{},y{}):{{x:1,y:2}:1, {x:2,y:1}:2}\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); f.assertFirstPhaseExpression("reduce(constant(my_tensor), sum)", "my_profile"); f.assertRankProperty("tensor(x{},y{}):{{x:1,y:2}:1.0, {x:2,y:1}:2.0}", "constant(my_tensor).value", "my_profile"); @@ -81,18 +81,18 @@ public class RankingExpressionWithTensorTestCase { } @Test - public void requireThatMultiLineConstantTensorAndTypeCanBeParsed() throws ParseException { + void requireThatMultiLineConstantTensorAndTypeCanBeParsed() throws ParseException { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: sum(my_tensor)\n" + - " }\n" + - " constants {\n" + - " my_tensor tensor(x{},y{}):\n" + - " { {x:1,y:2}:1,\n" + - " {x:2,y:1}:2 }\n" + - " }\n" + - " }"); + " first-phase {\n" + + " expression: sum(my_tensor)\n" + + " }\n" + + " constants {\n" + + " my_tensor tensor(x{},y{}):\n" + + " { {x:1,y:2}:1,\n" + + " {x:2,y:1}:2 }\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); f.assertFirstPhaseExpression("reduce(constant(my_tensor), sum)", "my_profile"); f.assertRankProperty("tensor(x{},y{}):{{x:1,y:2}:1.0, {x:2,y:1}:2.0}", "constant(my_tensor).value", "my_profile"); @@ -100,16 +100,16 @@ public class RankingExpressionWithTensorTestCase { } @Test - public void requireThatConstantTensorsCanBeUsedInSecondPhaseExpression() throws ParseException { + void requireThatConstantTensorsCanBeUsedInSecondPhaseExpression() throws ParseException { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile my_profile {\n" + - " second-phase {\n" + - " expression: sum(my_tensor)\n" + - " }\n" + - " constants {\n" + - " my_tensor tensor(x{}):{ {x:1}:1 }\n" + - " }\n" + - " }"); + " second-phase {\n" + + " expression: sum(my_tensor)\n" + + " }\n" + + " constants {\n" + + " my_tensor tensor(x{}):{ {x:1}:1 }\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); f.assertSecondPhaseExpression("reduce(constant(my_tensor), sum)", "my_profile"); f.assertRankProperty("tensor(x{}):{1:1.0}", "constant(my_tensor).value", "my_profile"); @@ -117,20 +117,20 @@ public class RankingExpressionWithTensorTestCase { } @Test - public void requireThatConstantTensorsCanBeUsedInInheritedRankProfile() throws ParseException { + void requireThatConstantTensorsCanBeUsedInInheritedRankProfile() throws ParseException { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile parent {\n" + - " constants {\n" + - " my_tensor {\n" + - " value: { {x:1}:1 }\n" + - " }\n" + - " }\n" + - " }\n" + - " rank-profile my_profile inherits parent {\n" + - " first-phase {\n" + - " expression: sum(my_tensor)\n" + - " }\n" + - " }"); + " constants {\n" + + " my_tensor {\n" + + " value: { {x:1}:1 }\n" + + " }\n" + + " }\n" + + " }\n" + + " rank-profile my_profile inherits parent {\n" + + " first-phase {\n" + + " expression: sum(my_tensor)\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); f.assertFirstPhaseExpression("reduce(constant(my_tensor), sum)", "my_profile"); f.assertRankProperty("tensor(x{}):{1:1.0}", "constant(my_tensor).value", "my_profile"); @@ -138,19 +138,19 @@ public class RankingExpressionWithTensorTestCase { } @Test - public void requireThatConstantTensorsCanBeUsedInFunction() throws ParseException { + void requireThatConstantTensorsCanBeUsedInFunction() throws ParseException { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile my_profile {\n" + - " function my_macro() {\n" + - " expression: sum(my_tensor)\n" + - " }\n" + - " first-phase {\n" + - " expression: 5.0 + my_macro\n" + - " }\n" + - " constants {\n" + - " my_tensor tensor(x{}):{ {x:1}:1 }\n" + - " }\n" + - " }"); + " function my_macro() {\n" + + " expression: sum(my_tensor)\n" + + " }\n" + + " first-phase {\n" + + " expression: 5.0 + my_macro\n" + + " }\n" + + " constants {\n" + + " my_tensor tensor(x{}):{ {x:1}:1 }\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); f.assertFirstPhaseExpression("5.0 + my_macro", "my_profile"); f.assertFunction("reduce(constant(my_tensor), sum)", "my_macro", "my_profile"); @@ -159,18 +159,18 @@ public class RankingExpressionWithTensorTestCase { } @Test - public void requireThatCombinationOfConstantTensorsAndConstantValuesCanBeUsed() throws ParseException { + void requireThatCombinationOfConstantTensorsAndConstantValuesCanBeUsed() throws ParseException { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: my_number_1 + sum(my_tensor) + my_number_2\n" + - " }\n" + - " constants {\n" + - " my_number_1 double: 3.0\n" + - " my_tensor tensor(x{}):{ {x:1}:1 }\n" + - " my_number_2 double: 5.0\n" + - " }\n" + - " }"); + " first-phase {\n" + + " expression: my_number_1 + sum(my_tensor) + my_number_2\n" + + " }\n" + + " constants {\n" + + " my_number_1 double: 3.0\n" + + " my_tensor tensor(x{}):{ {x:1}:1 }\n" + + " my_number_2 double: 5.0\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); f.assertFirstPhaseExpression("3.0 + reduce(constant(my_tensor), sum) + 5.0", "my_profile"); f.assertRankProperty("tensor(x{}):{1:1.0}", "constant(my_tensor).value", "my_profile"); @@ -178,20 +178,20 @@ public class RankingExpressionWithTensorTestCase { } @Test - public void requireThatInvalidTensorTypeSpecThrowsException() throws ParseException { + void requireThatInvalidTensorTypeSpecThrowsException() throws ParseException { try { RankProfileSearchFixture f = new RankProfileSearchFixture( " rank-profile my_profile {\n" + - " constants {\n" + - " my_tensor tensor(x):{ {x:1}:1 }\n" + - " }\n" + - " }"); + " constants {\n" + + " my_tensor tensor(x):{ {x:1}:1 }\n" + + " }\n" + + " }"); f.compileRankProfile("my_profile"); fail("Expected exception"); } catch (IllegalArgumentException e) { assertStartsWith("Type of constant(my_tensor): Illegal tensor type spec: A tensor type spec must be on the form", - e.getMessage()); + e.getMessage()); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTransformerTokensTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTransformerTokensTestCase.java index f8086fb3bc6..5c82be0745e 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTransformerTokensTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithTransformerTokensTestCase.java @@ -17,16 +17,16 @@ import com.yahoo.searchlib.rankingexpression.RankingExpression; import com.yahoo.searchlib.rankingexpression.evaluation.MapContext; import com.yahoo.searchlib.rankingexpression.evaluation.TensorValue; import com.yahoo.tensor.Tensor; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class RankingExpressionWithTransformerTokensTestCase { @Test - public void testTokenInputIds() throws Exception { + void testTokenInputIds() throws Exception { String expected = "tensor(d0[1],d1[12]):[101,1,2,102,3,4,5,102,6,7,102,0]"; String a = "tensor(d0[2]):[1,2]"; String b = "tensor(d0[3]):[3,4,5]"; @@ -37,7 +37,7 @@ public class RankingExpressionWithTransformerTokensTestCase { } @Test - public void testTokenTypeIds() throws Exception { + void testTokenTypeIds() throws Exception { String expected = "tensor(d0[1],d1[10]):[0,0,0,0,1,1,1,1,0,0]"; String a = "tensor(d0[2]):[1,2]"; String b = "tensor(d0[3]):[3,4,5]"; @@ -47,7 +47,7 @@ public class RankingExpressionWithTransformerTokensTestCase { } @Test - public void testAttentionMask() throws Exception { + void testAttentionMask() throws Exception { String expected = "tensor(d0[1],d1[10]):[1,1,1,1,1,1,1,1,0,0]"; String a = "tensor(d0[2]):[1,2]"; String b = "tensor(d0[3]):[3,4,5]"; diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithXGBoostTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithXGBoostTestCase.java index e1b1473a59a..d01bb1be377 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithXGBoostTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionWithXGBoostTestCase.java @@ -5,8 +5,8 @@ import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.io.IOUtils; import com.yahoo.path.Path; import com.yahoo.schema.parser.ParseException; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -22,25 +22,25 @@ public class RankingExpressionWithXGBoostTestCase { "if (f29 < -0.1234567, if (!(f56 >= -0.242398), 1.71218, -1.70044), if (f109 < 0.8723473, -1.94071, 1.85965)) + " + "if (!(f60 >= -0.482947), if (f29 < -4.2387498, 0.784718, -0.96853), -6.23624)"; - @After + @AfterEach public void removeGeneratedModelFiles() { IOUtils.recursiveDeleteDir(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); } @Test - public void testXGBoostReference() { + void testXGBoostReference() { RankProfileSearchFixture search = fixtureWith("xgboost('xgboost.2.2.json')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); } @Test - public void testNestedXGBoostReference() { + void testNestedXGBoostReference() { RankProfileSearchFixture search = fixtureWith("5 + sum(xgboost('xgboost.2.2.json'))"); search.assertFirstPhaseExpression("5 + reduce(" + vespaExpression + ", sum)", "my_profile"); } @Test - public void testImportingFromStoredExpressions() throws IOException { + void testImportingFromStoredExpressions() throws IOException { RankProfileSearchFixture search = fixtureWith("xgboost('xgboost.2.2.json')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); @@ -49,7 +49,7 @@ public class RankingExpressionWithXGBoostTestCase { try { storedApplicationDirectory.toFile().mkdirs(); IOUtils.copyDirectory(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile(), - storedApplicationDirectory.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); + storedApplicationDirectory.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); RankingExpressionWithOnnxTestCase.StoringApplicationPackage storedApplication = new RankingExpressionWithOnnxTestCase.StoringApplicationPackage(storedApplicationDirectory); RankProfileSearchFixture searchFromStored = fixtureWith("xgboost('xgboost.2.2.json')"); searchFromStored.assertFirstPhaseExpression(vespaExpression, "my_profile"); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionsTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionsTestCase.java index c985d427a5a..526576c9e0b 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/RankingExpressionsTestCase.java @@ -18,15 +18,14 @@ import com.yahoo.schema.derived.RawRankProfile; import com.yahoo.schema.derived.TestableDeployLogger; import com.yahoo.schema.parser.ParseException; import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class RankingExpressionsTestCase extends AbstractSchemaTestCase { @@ -35,7 +34,7 @@ public class RankingExpressionsTestCase extends AbstractSchemaTestCase { } @Test - public void testFunctions() throws IOException, ParseException { + void testFunctions() throws IOException, ParseException { ModelContext.Properties deployProperties = new TestProperties(); RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); Schema schema = createSearch("src/test/examples/rankingexpressionfunction", deployProperties, rankProfileRegistry); @@ -46,13 +45,13 @@ public class RankingExpressionsTestCase extends AbstractSchemaTestCase { assertEquals("var2", functions.get("titlematch").function().arguments().get(1)); assertEquals("var1 * var2 + 890", functions.get("titlematch").function().getBody().getRoot().toString()); assertEquals("0.8 + 0.2 * titlematch(4,5) + 0.8 * titlematch(7,8) * closeness(distance)", - functionsRankProfile.getFirstPhaseRanking().getRoot().toString()); + functionsRankProfile.getFirstPhaseRanking().getRoot().toString()); assertEquals("78 + closeness(distance)", - functions.get("artistmatch").function().getBody().getRoot().toString()); + functions.get("artistmatch").function().getBody().getRoot().toString()); assertEquals(0, functions.get("artistmatch").function().arguments().size()); RawRankProfile rawRankProfile = new RawRankProfile(functionsRankProfile, new LargeRankExpressions(new MockFileRegistry()), new QueryProfileRegistry(), - new ImportedMlModels(), new AttributeFields(schema), deployProperties); + new ImportedMlModels(), new AttributeFields(schema), deployProperties); List<Pair<String, String>> rankProperties = rawRankProfile.configProperties(); assertEquals(6, rankProperties.size()); @@ -72,11 +71,13 @@ public class RankingExpressionsTestCase extends AbstractSchemaTestCase { assertEquals("4 * 5 + 890", rankProperties.get(0).getSecond()); } - @Test(expected = IllegalArgumentException.class) - public void testThatIncludingFileInSubdirFails() throws IOException, ParseException { - RankProfileRegistry registry = new RankProfileRegistry(); - Schema schema = createSearch("src/test/examples/rankingexpressioninfile", new TestProperties(), registry); - new DerivedConfiguration(schema, registry); // rank profile parsing happens during deriving + @Test + void testThatIncludingFileInSubdirFails() throws IOException, ParseException { + assertThrows(IllegalArgumentException.class, () -> { + RankProfileRegistry registry = new RankProfileRegistry(); + Schema schema = createSearch("src/test/examples/rankingexpressioninfile", new TestProperties(), registry); + new DerivedConfiguration(schema, registry); // rank profile parsing happens during deriving + }); // rank profile parsing happens during deriving } private void verifyProfile(RankProfile profile, List<String> expectedFunctions, List<Pair<String, String>> rankProperties, @@ -114,7 +115,7 @@ public class RankingExpressionsTestCase extends AbstractSchemaTestCase { } @Test - public void testLargeInheritedFunctions() throws IOException, ParseException { + void testLargeInheritedFunctions() throws IOException, ParseException { ModelContext.Properties properties = new TestProperties(); RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); LargeRankExpressions largeExpressions = new LargeRankExpressions(new MockFileRegistry(), 50); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ReferenceFieldTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/ReferenceFieldTestCase.java index 57b4d928a52..5f26e7b2964 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ReferenceFieldTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ReferenceFieldTestCase.java @@ -9,43 +9,35 @@ import com.yahoo.schema.Schema; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.document.SDDocumentType; import com.yahoo.schema.parser.ParseException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author bjorncs */ public class ReferenceFieldTestCase { - @SuppressWarnings("deprecation") - @Rule - public final ExpectedException exceptionRule = ExpectedException.none(); - @Test - public void reference_fields_are_parsed_from_search_definition() throws ParseException { + void reference_fields_are_parsed_from_search_definition() throws ParseException { ApplicationBuilder builder = new ApplicationBuilder(); String campaignSdContent = "schema campaign {\n" + - " document campaign {\n" + - " }\n" + - "}"; + " document campaign {\n" + + " }\n" + + "}"; String salespersonSdContent = "schema salesperson {\n" + - " document salesperson {\n" + - " }\n" + - "}"; + " document salesperson {\n" + + " }\n" + + "}"; String adSdContent = "schema ad {\n" + - " document ad {\n" + - " field campaign_ref type reference<campaign> { indexing: attribute }\n" + - " field salesperson_ref type reference<salesperson> { indexing: attribute }\n" + - " }\n" + - "}"; + " document ad {\n" + + " field campaign_ref type reference<campaign> { indexing: attribute }\n" + + " field salesperson_ref type reference<salesperson> { indexing: attribute }\n" + + " }\n" + + "}"; builder.addSchema(campaignSdContent); builder.addSchema(salespersonSdContent); builder.addSchema(adSdContent); @@ -56,37 +48,38 @@ public class ReferenceFieldTestCase { } @Test - public void cyclic_document_dependencies_are_detected() throws ParseException { - var builder = new ApplicationBuilder(new TestProperties()); - String campaignSdContent = - "schema campaign {\n" + - " document campaign {\n" + - " field ad_ref type reference<ad> { indexing: attribute }\n" + - " }\n" + - "}"; - String adSdContent = - "schema ad {\n" + - " document ad {\n" + - " field campaign_ref type reference<campaign> { indexing: attribute }\n" + - " }\n" + - "}"; - builder.addSchema(campaignSdContent); - builder.addSchema(adSdContent); - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("reference cycle for documents"); - builder.build(true); + void cyclic_document_dependencies_are_detected() throws ParseException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + var builder = new ApplicationBuilder(new TestProperties()); + String campaignSdContent = + "schema campaign {\n" + + " document campaign {\n" + + " field ad_ref type reference<ad> { indexing: attribute }\n" + + " }\n" + + "}"; + String adSdContent = + "schema ad {\n" + + " document ad {\n" + + " field campaign_ref type reference<campaign> { indexing: attribute }\n" + + " }\n" + + "}"; + builder.addSchema(campaignSdContent); + builder.addSchema(adSdContent); + builder.build(true); + }); + assertTrue(exception.getMessage().contains("reference cycle for documents")); } private static void assertSearchContainsReferenceField(String expectedFieldname, String referencedDocType, SDDocumentType documentType) { Field field = documentType.getDocumentType().getField(expectedFieldname); - assertNotNull("Field does not exist in document type: " + expectedFieldname, field); + assertNotNull(field, "Field does not exist in document type: " + expectedFieldname); DataType dataType = field.getDataType(); assertTrue(dataType instanceof NewDocumentReferenceDataType); NewDocumentReferenceDataType refField = (NewDocumentReferenceDataType) dataType; assertEquals(referencedDocType, refField.getTargetTypeName()); - assertTrue(! refField.isTemporary()); + assertFalse(refField.isTemporary()); } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ReservedDocumentNamesTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/ReservedDocumentNamesTestCase.java index 974d8c261ca..404b8f648cf 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ReservedDocumentNamesTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ReservedDocumentNamesTestCase.java @@ -3,12 +3,12 @@ package com.yahoo.schema.processing; import com.yahoo.schema.derived.AbstractExportingTestCase; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Simon Thoresen Hult @@ -16,7 +16,7 @@ import static org.junit.Assert.fail; public class ReservedDocumentNamesTestCase extends AbstractExportingTestCase { @Test - public void requireThatPositionIsAReservedDocumentName() throws IOException, ParseException { + void requireThatPositionIsAReservedDocumentName() throws IOException, ParseException { try { assertCorrectDeriving("reserved_position"); fail(); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ReservedRankingExpressionFunctionNamesTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/ReservedRankingExpressionFunctionNamesTestCase.java index e405a105f3c..f657efffde7 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ReservedRankingExpressionFunctionNamesTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ReservedRankingExpressionFunctionNamesTestCase.java @@ -5,12 +5,12 @@ import com.yahoo.config.application.api.DeployLogger; import com.yahoo.schema.RankProfileRegistry; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.logging.Level; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author lesters @@ -18,7 +18,7 @@ import static org.junit.Assert.assertTrue; public class ReservedRankingExpressionFunctionNamesTestCase { @Test - public void requireThatFunctionsWithReservedNamesIssueAWarning() throws ParseException { + void requireThatFunctionsWithReservedNamesIssueAWarning() throws ParseException { TestDeployLogger deployLogger = new TestDeployLogger(); RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); ApplicationBuilder builder = new ApplicationBuilder(deployLogger, rankProfileRegistry); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/SchemaMustHaveDocumentTest.java b/config-model/src/test/java/com/yahoo/schema/processing/SchemaMustHaveDocumentTest.java index 03f9d7c5960..6e5e17398d9 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/SchemaMustHaveDocumentTest.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/SchemaMustHaveDocumentTest.java @@ -3,11 +3,11 @@ package com.yahoo.schema.processing; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * @author hmusum @@ -15,13 +15,13 @@ import static org.junit.Assert.fail; public class SchemaMustHaveDocumentTest { @Test - public void requireErrorWhenMissingDocument() throws IOException, ParseException { + void requireErrorWhenMissingDocument() throws IOException, ParseException { try { ApplicationBuilder.buildFromFile("src/test/examples/invalid_sd_missing_document.sd"); fail("SD without document"); } catch (IllegalArgumentException e) { if (!e.getMessage() - .contains("For schema 'imageconfig': A search specification must have an equally named document inside of it.")) { + .contains("For schema 'imageconfig': A search specification must have an equally named document inside of it.")) { throw e; } } diff --git a/config-model/src/test/java/com/yahoo/schema/processing/SummaryConsistencyTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/SummaryConsistencyTestCase.java index 76132a4d09f..c5f0fb49946 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/SummaryConsistencyTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/SummaryConsistencyTestCase.java @@ -5,15 +5,15 @@ import com.yahoo.schema.Schema; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.parser.ParseException; import com.yahoo.vespa.documentmodel.SummaryTransform; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.config.model.test.TestUtil.joinLines; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SummaryConsistencyTestCase { @Test - public void attribute_combiner_transform_is_set_when_source_is_array_of_struct_with_only_struct_field_attributes() throws ParseException { + void attribute_combiner_transform_is_set_when_source_is_array_of_struct_with_only_struct_field_attributes() throws ParseException { String sd = joinLines( "search structmemorysummary {", " document structmemorysummary {", diff --git a/config-model/src/test/java/com/yahoo/schema/processing/SummaryFieldsMustHaveValidSourceTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/SummaryFieldsMustHaveValidSourceTestCase.java index d94815015d7..22151063eb7 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/SummaryFieldsMustHaveValidSourceTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/SummaryFieldsMustHaveValidSourceTestCase.java @@ -9,17 +9,17 @@ import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.parser.ParseException; import com.yahoo.vespa.model.container.search.QueryProfiles; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class SummaryFieldsMustHaveValidSourceTestCase extends AbstractSchemaTestCase { @Test - public void requireThatInvalidSourceIsCaught() throws IOException, ParseException { + void requireThatInvalidSourceIsCaught() throws IOException, ParseException { try { ApplicationBuilder.buildFromFile("src/test/examples/invalidsummarysource.sd"); fail("This should throw and never get here"); @@ -29,7 +29,7 @@ public class SummaryFieldsMustHaveValidSourceTestCase extends AbstractSchemaTest } @Test - public void requireThatInvalidImplicitSourceIsCaught() throws IOException, ParseException { + void requireThatInvalidImplicitSourceIsCaught() throws IOException, ParseException { try { ApplicationBuilder.buildFromFile("src/test/examples/invalidimplicitsummarysource.sd"); fail("This should throw and never get here"); @@ -39,7 +39,7 @@ public class SummaryFieldsMustHaveValidSourceTestCase extends AbstractSchemaTest } @Test - public void requireThatInvalidSelfReferingSingleSource() throws IOException, ParseException { + void requireThatInvalidSelfReferingSingleSource() throws IOException, ParseException { try { ApplicationBuilder.buildFromFile("src/test/examples/invalidselfreferringsummary.sd"); fail("This should throw and never get here"); @@ -49,7 +49,7 @@ public class SummaryFieldsMustHaveValidSourceTestCase extends AbstractSchemaTest } @Test - public void requireThatDocumentIdIsAllowedToPass() throws IOException, ParseException { + void requireThatDocumentIdIsAllowedToPass() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/documentidinsummary.sd"); BaseDeployLogger deployLogger = new BaseDeployLogger(); RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/TensorFieldTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/TensorFieldTestCase.java index 9164f361a92..60e1e35fb2e 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/TensorFieldTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/TensorFieldTestCase.java @@ -3,15 +3,12 @@ package com.yahoo.schema.processing; import com.yahoo.schema.document.Attribute; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.schema.ApplicationBuilder.createFromString; import static com.yahoo.config.model.test.TestUtil.joinLines; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author geirst @@ -19,32 +16,32 @@ import static org.junit.Assert.fail; public class TensorFieldTestCase { @Test - public void requireThatTensorFieldCannotBeOfCollectionType() throws ParseException { + void requireThatTensorFieldCannotBeOfCollectionType() throws ParseException { try { createFromString(getSd("field f1 type array<tensor(x{})> {}")); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals("For schema 'test', field 'f1': A field with collection type of tensor is not supported. Use simple type 'tensor' instead.", - e.getMessage()); + e.getMessage()); } } @Test - public void requireThatTensorFieldCannotBeIndexField() throws ParseException { + void requireThatTensorFieldCannotBeIndexField() throws ParseException { try { createFromString(getSd("field f1 type tensor(x{}) { indexing: index }")); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals("For schema 'test', field 'f1': A tensor of type 'tensor(x{})' does not support having an 'index'. " + - "Currently, only tensors with 1 indexed dimension supports that.", - e.getMessage()); + "Currently, only tensors with 1 indexed dimension supports that.", + e.getMessage()); } } @Test - public void requireThatIndexedTensorAttributeCannotBeFastSearch() throws ParseException { + void requireThatIndexedTensorAttributeCannotBeFastSearch() throws ParseException { try { createFromString(getSd("field f1 type tensor(x[3]) { indexing: attribute \n attribute: fast-search }")); fail("Expected exception"); @@ -55,7 +52,7 @@ public class TensorFieldTestCase { } @Test - public void requireThatIndexedTensorAttributeCannotBeFastRank() throws ParseException { + void requireThatIndexedTensorAttributeCannotBeFastRank() throws ParseException { try { createFromString(getSd("field f1 type tensor(x[3]) { indexing: attribute \n attribute: fast-rank }")); fail("Expected exception"); @@ -66,7 +63,7 @@ public class TensorFieldTestCase { } @Test - public void requireThatIllegalTensorTypeSpecThrowsException() throws ParseException { + void requireThatIllegalTensorTypeSpecThrowsException() throws ParseException { try { createFromString(getSd("field f1 type tensor(invalid) { indexing: attribute }")); fail("Expected exception"); @@ -77,19 +74,19 @@ public class TensorFieldTestCase { } @Test - public void hnsw_index_is_default_turned_off() throws ParseException { + void hnsw_index_is_default_turned_off() throws ParseException { var attr = getAttributeFromSd("field t1 type tensor(x[64]) { indexing: attribute }", "t1"); assertFalse(attr.hnswIndexParams().isPresent()); } @Test - public void hnsw_index_gets_default_parameters_if_not_specified() throws ParseException { + void hnsw_index_gets_default_parameters_if_not_specified() throws ParseException { assertHnswIndexParams("", 16, 200); assertHnswIndexParams("index: hnsw", 16, 200); } @Test - public void hnsw_index_parameters_can_be_specified() throws ParseException { + void hnsw_index_parameters_can_be_specified() throws ParseException { assertHnswIndexParams("index { hnsw { max-links-per-node: 32 } }", 32, 200); assertHnswIndexParams("index { hnsw { neighbors-to-explore-at-insert: 300 } }", 16, 300); assertHnswIndexParams(joinLines("index {", @@ -102,7 +99,7 @@ public class TensorFieldTestCase { } @Test - public void tensor_with_hnsw_index_must_be_an_attribute() throws ParseException { + void tensor_with_hnsw_index_must_be_an_attribute() throws ParseException { try { createFromString(getSd("field t1 type tensor(x[64]) { indexing: index }")); fail("Expected exception"); @@ -113,7 +110,7 @@ public class TensorFieldTestCase { } @Test - public void tensor_with_hnsw_index_parameters_must_be_an_index() throws ParseException { + void tensor_with_hnsw_index_parameters_must_be_an_index() throws ParseException { try { createFromString(getSd(joinLines( "field t1 type tensor(x[64]) {", @@ -132,7 +129,7 @@ public class TensorFieldTestCase { } @Test - public void tensors_with_at_least_one_mapped_dimension_can_be_direct() throws ParseException { + void tensors_with_at_least_one_mapped_dimension_can_be_direct() throws ParseException { assertTrue(getAttributeFromSd( "field t1 type tensor(x{}) { indexing: attribute \n attribute: fast-search }", "t1").isFastSearch()); assertTrue(getAttributeFromSd( @@ -140,7 +137,7 @@ public class TensorFieldTestCase { } @Test - public void tensors_with_at_least_one_mapped_dimension_can_be_fast_rank() throws ParseException { + void tensors_with_at_least_one_mapped_dimension_can_be_fast_rank() throws ParseException { assertTrue(getAttributeFromSd( "field t1 type tensor(x{}) { indexing: attribute \n attribute: fast-rank }", "t1").isFastRank()); assertTrue(getAttributeFromSd( diff --git a/config-model/src/test/java/com/yahoo/schema/processing/TensorTransformTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/TensorTransformTestCase.java index aaf5f381c62..028ad5dea86 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/TensorTransformTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/TensorTransformTestCase.java @@ -20,109 +20,109 @@ import com.yahoo.schema.derived.AttributeFields; import com.yahoo.schema.derived.RawRankProfile; import com.yahoo.schema.parser.ParseException; import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class TensorTransformTestCase extends AbstractSchemaTestCase { @Test - public void requireThatNormalMaxAndMinAreNotReplaced() throws ParseException { + void requireThatNormalMaxAndMinAreNotReplaced() throws ParseException { assertTransformedExpression("max(1.0,2.0)", - "max(1.0,2.0)"); + "max(1.0,2.0)"); assertTransformedExpression("min(attribute(double_field),x)", - "min(attribute(double_field),x)"); + "min(attribute(double_field),x)"); assertTransformedExpression("max(attribute(double_field),attribute(double_array_field))", - "max(attribute(double_field),attribute(double_array_field))"); + "max(attribute(double_field),attribute(double_array_field))"); assertTransformedExpression("min(attribute(tensor_field_1),attribute(double_field))", - "min(attribute(tensor_field_1),attribute(double_field))"); + "min(attribute(tensor_field_1),attribute(double_field))"); assertTransformedExpression("reduce(max(attribute(tensor_field_1),attribute(tensor_field_2)),sum)", - "reduce(max(attribute(tensor_field_1),attribute(tensor_field_2)),sum)"); + "reduce(max(attribute(tensor_field_1),attribute(tensor_field_2)),sum)"); assertTransformedExpression("min(constant(test_constant_tensor),1.0)", - "min(test_constant_tensor,1.0)"); + "min(test_constant_tensor,1.0)"); assertTransformedExpression("max(constant(base_constant_tensor),1.0)", - "max(base_constant_tensor,1.0)"); + "max(base_constant_tensor,1.0)"); assertTransformedExpression("min(constant(file_constant_tensor),1.0)", - "min(constant(file_constant_tensor),1.0)"); + "min(constant(file_constant_tensor),1.0)"); assertTransformedExpression("max(query(q),1.0)", - "max(query(q),1.0)"); + "max(query(q),1.0)"); assertTransformedExpression("max(query(n),1.0)", - "max(query(n),1.0)"); + "max(query(n),1.0)"); } @Test - public void requireThatMaxAndMinWithTensorAttributesAreReplaced() throws ParseException { + void requireThatMaxAndMinWithTensorAttributesAreReplaced() throws ParseException { assertTransformedExpression("reduce(attribute(tensor_field_1),max,x)", - "max(attribute(tensor_field_1),x)"); + "max(attribute(tensor_field_1),x)"); assertTransformedExpression("1+reduce(attribute(tensor_field_1),max,x)", - "1 + max(attribute(tensor_field_1),x)"); + "1 + max(attribute(tensor_field_1),x)"); assertTransformedExpression("if(attribute(double_field),1+reduce(attribute(tensor_field_1),max,x),reduce(attribute(tensor_field_1),sum,x))", - "if(attribute(double_field),1 + max(attribute(tensor_field_1),x),reduce(attribute(tensor_field_1), sum, x))"); + "if(attribute(double_field),1 + max(attribute(tensor_field_1),x),reduce(attribute(tensor_field_1), sum, x))"); assertTransformedExpression("reduce(max(attribute(tensor_field_1),attribute(tensor_field_2)),max,x)", - "max(max(attribute(tensor_field_1),attribute(tensor_field_2)),x)"); + "max(max(attribute(tensor_field_1),attribute(tensor_field_2)),x)"); assertTransformedExpression("reduce(if(attribute(double_field),attribute(tensor_field_2),attribute(tensor_field_2)),max,x)", - "max(if(attribute(double_field),attribute(tensor_field_2),attribute(tensor_field_2)),x)"); + "max(if(attribute(double_field),attribute(tensor_field_2),attribute(tensor_field_2)),x)"); assertTransformedExpression("max(reduce(attribute(tensor_field_1),max,x),x)", - "max(max(attribute(tensor_field_1),x),x)"); // will result in deploy error. + "max(max(attribute(tensor_field_1),x),x)"); // will result in deploy error. assertTransformedExpression("reduce(reduce(attribute(tensor_field_2),max,x),max,y)", - "max(max(attribute(tensor_field_2),x),y)"); + "max(max(attribute(tensor_field_2),x),y)"); } @Test - public void requireThatMaxAndMinWithConstantTensorsAreReplaced() throws ParseException { + void requireThatMaxAndMinWithConstantTensorsAreReplaced() throws ParseException { assertTransformedExpression("reduce(constant(test_constant_tensor),max,x)", - "max(test_constant_tensor,x)"); + "max(test_constant_tensor,x)"); assertTransformedExpression("reduce(constant(base_constant_tensor),max,x)", - "max(base_constant_tensor,x)"); + "max(base_constant_tensor,x)"); assertTransformedExpression("reduce(constant(file_constant_tensor),min,x)", - "min(constant(file_constant_tensor),x)"); + "min(constant(file_constant_tensor),x)"); } @Test - public void requireThatMaxAndMinWithTensorExpressionsAreReplaced() throws ParseException { + void requireThatMaxAndMinWithTensorExpressionsAreReplaced() throws ParseException { assertTransformedExpression("reduce(attribute(double_field)+attribute(tensor_field_1),min,x)", - "min(attribute(double_field) + attribute(tensor_field_1),x)"); + "min(attribute(double_field) + attribute(tensor_field_1),x)"); assertTransformedExpression("reduce(attribute(tensor_field_1)*attribute(tensor_field_2),min,x)", - "min(attribute(tensor_field_1) * attribute(tensor_field_2),x)"); + "min(attribute(tensor_field_1) * attribute(tensor_field_2),x)"); assertTransformedExpression("reduce(join(attribute(tensor_field_1),attribute(tensor_field_2),f(x,y)(x*y)),min,x)", - "min(join(attribute(tensor_field_1),attribute(tensor_field_2),f(x,y)(x*y)),x)"); + "min(join(attribute(tensor_field_1),attribute(tensor_field_2),f(x,y)(x*y)),x)"); assertTransformedExpression("min(join(tensor_field_1,tensor_field_2,f(x,y)(x*y)),x)", - "min(join(tensor_field_1,tensor_field_2,f(x,y)(x*y)),x)"); // because tensor fields are not in attribute(...) + "min(join(tensor_field_1,tensor_field_2,f(x,y)(x*y)),x)"); // because tensor fields are not in attribute(...) assertTransformedExpression("reduce(join(attribute(tensor_field_1),backend_rank_feature,f(x,y)(x*y)),min,x)", - "min(join(attribute(tensor_field_1),backend_rank_feature,f(x,y)(x*y)),x)"); + "min(join(attribute(tensor_field_1),backend_rank_feature,f(x,y)(x*y)),x)"); } @Test - public void requireThatMaxAndMinWithTensorFromIsReplaced() throws ParseException { + void requireThatMaxAndMinWithTensorFromIsReplaced() throws ParseException { assertTransformedExpression("reduce(tensorFromLabels(attribute(double_array_field)),max,double_array_field)", - "max(tensorFromLabels(attribute(double_array_field)),double_array_field)"); + "max(tensorFromLabels(attribute(double_array_field)),double_array_field)"); assertTransformedExpression("reduce(tensorFromLabels(attribute(double_array_field),x),max,x)", - "max(tensorFromLabels(attribute(double_array_field),x),x)"); + "max(tensorFromLabels(attribute(double_array_field),x),x)"); assertTransformedExpression("reduce(tensorFromWeightedSet(attribute(weightedset_field)),max,weightedset_field)", - "max(tensorFromWeightedSet(attribute(weightedset_field)),weightedset_field)"); + "max(tensorFromWeightedSet(attribute(weightedset_field)),weightedset_field)"); assertTransformedExpression("reduce(tensorFromWeightedSet(attribute(weightedset_field),x),max,x)", - "max(tensorFromWeightedSet(attribute(weightedset_field),x),x)"); + "max(tensorFromWeightedSet(attribute(weightedset_field),x),x)"); } @Test - public void requireThatMaxAndMinWithTensorInQueryIsReplaced() throws ParseException { + void requireThatMaxAndMinWithTensorInQueryIsReplaced() throws ParseException { assertTransformedExpression("reduce(query(q),max,x)", "max(query(q),x)"); assertTransformedExpression("max(query(n),x)", "max(query(n),x)"); } @Test - public void requireThatMaxAndMinWithTensorsReturnedFromFunctionsAreReplaced() throws ParseException { + void requireThatMaxAndMinWithTensorsReturnedFromFunctionsAreReplaced() throws ParseException { assertTransformedExpression("reduce(rankingExpression(returns_tensor),max,x)", - "max(returns_tensor,x)"); + "max(returns_tensor,x)"); assertTransformedExpression("reduce(rankingExpression(wraps_returns_tensor),max,x)", - "max(wraps_returns_tensor,x)"); + "max(wraps_returns_tensor,x)"); assertTransformedExpression("reduce(rankingExpression(tensor_inheriting),max,x)", - "max(tensor_inheriting,x)"); + "max(tensor_inheriting,x)"); assertTransformedExpression("reduce(rankingExpression(returns_tensor_with_arg@),max,x)", - "max(returns_tensor_with_arg(attribute(tensor_field_1)),x)"); + "max(returns_tensor_with_arg(attribute(tensor_field_1)),x)"); } private void assertTransformedExpression(String expected, String original) throws ParseException { diff --git a/config-model/src/test/java/com/yahoo/schema/processing/ValidateFieldTypesTest.java b/config-model/src/test/java/com/yahoo/schema/processing/ValidateFieldTypesTest.java index 87bb2e96042..5f0940f0d2d 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/ValidateFieldTypesTest.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/ValidateFieldTypesTest.java @@ -16,12 +16,13 @@ import com.yahoo.schema.document.SDDocumentType; import com.yahoo.schema.document.SDField; import com.yahoo.vespa.documentmodel.DocumentSummary; import com.yahoo.vespa.documentmodel.SummaryField; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.util.Collections; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author bjorncs */ @@ -30,22 +31,18 @@ public class ValidateFieldTypesTest { private static final String IMPORTED_FIELD_NAME = "imported_myfield"; private static final String DOCUMENT_NAME = "my_doc"; - @SuppressWarnings("deprecation") - @Rule - public final ExpectedException exceptionRule = ExpectedException.none(); - @Test - public void throws_exception_if_type_of_document_field_does_not_match_summary_field() { - Schema schema = createSearchWithDocument(DOCUMENT_NAME); - schema.setImportedFields(createSingleImportedField(IMPORTED_FIELD_NAME, DataType.INT)); - schema.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME, DataType.STRING, schema)); + void throws_exception_if_type_of_document_field_does_not_match_summary_field() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + Schema schema = createSearchWithDocument(DOCUMENT_NAME); + schema.setImportedFields(createSingleImportedField(IMPORTED_FIELD_NAME, DataType.INT)); + schema.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME, DataType.STRING, schema)); - ValidateFieldTypes validator = new ValidateFieldTypes(schema, null, null, null); - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage( - "For schema '" + DOCUMENT_NAME + "', field '" + IMPORTED_FIELD_NAME + "': Incompatible types. " + - "Expected int for summary field '" + IMPORTED_FIELD_NAME + "', got string."); - validator.process(true, false); + ValidateFieldTypes validator = new ValidateFieldTypes(schema, null, null, null); + validator.process(true, false); + }); + assertTrue(exception.getMessage().contains("For schema '" + DOCUMENT_NAME + "', field '" + IMPORTED_FIELD_NAME + "': Incompatible types. " + + "Expected int for summary field '" + IMPORTED_FIELD_NAME + "', got string.")); } private static Schema createSearch(String documentType) { diff --git a/config-model/src/test/java/com/yahoo/schema/processing/VespaMlModelTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/VespaMlModelTestCase.java index 016e30e80af..dc72df9fc78 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/VespaMlModelTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/VespaMlModelTestCase.java @@ -7,13 +7,13 @@ import com.yahoo.path.Path; import com.yahoo.schema.derived.RawRankProfile; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.ml.ImportedModelTester; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Optional; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests adding Vespa ranking expression based models in the models/ dir @@ -37,13 +37,13 @@ public class VespaMlModelTestCase { /** The model name */ private final String name = "example"; - @After + @AfterEach public void removeGeneratedModelFiles() { IOUtils.recursiveDeleteDir(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); } @Test - public void testGlobalVespaModel() throws IOException { + void testGlobalVespaModel() throws IOException { ImportedModelTester tester = new ImportedModelTester(name, applicationDir); VespaModel model = tester.createVespaModel(); tester.assertLargeConstant("constant1asLarge", model, Optional.of(3L)); @@ -55,7 +55,7 @@ public class VespaMlModelTestCase { storedAppDir.toFile().mkdirs(); IOUtils.copy(applicationDir.append("services.xml").toString(), storedAppDir.append("services.xml").toString()); IOUtils.copyDirectory(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile(), - storedAppDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); + storedAppDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); ImportedModelTester storedTester = new ImportedModelTester(name, storedAppDir); VespaModel storedModel = storedTester.createVespaModel(); storedTester.assertLargeConstant("constant1asLarge", model, Optional.of(3L)); diff --git a/config-model/src/test/java/com/yahoo/schema/processing/WeightedSetSummaryToTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/WeightedSetSummaryToTestCase.java index 2f62228cc3f..95d01946969 100644 --- a/config-model/src/test/java/com/yahoo/schema/processing/WeightedSetSummaryToTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/processing/WeightedSetSummaryToTestCase.java @@ -5,17 +5,17 @@ import com.yahoo.schema.Schema; import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.AbstractSchemaTestCase; import com.yahoo.schema.parser.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** @author bratseth */ public class WeightedSetSummaryToTestCase extends AbstractSchemaTestCase { @Test - public void testRequireThatImplicitFieldsAreCreated() throws IOException, ParseException { + void testRequireThatImplicitFieldsAreCreated() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/weightedset-summaryto.sd"); assertNotNull(schema); } |