summaryrefslogtreecommitdiffstats
path: root/config-model/src/test
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-10-19 18:11:27 +0200
committerJon Bratseth <bratseth@gmail.com>2021-10-19 18:11:27 +0200
commit8d337646d3f06b6ad987e4b3a8d7fda230726d00 (patch)
tree1d357475fc4eae4d618ae75928ba66e363db065b /config-model/src/test
parent8ae224deaa6c98c3cd5a212a526241e99689d4e2 (diff)
Test adding to inherited collections
Diffstat (limited to 'config-model/src/test')
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java111
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java3
2 files changed, 112 insertions, 2 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java
index 1813ee1f636..0f9951b707b 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java
@@ -109,6 +109,116 @@ public class SchemaTestCase {
" indexing: summary" +
" }" +
" }" +
+ " fieldset child_set {" +
+ " fields: cf1, pf1" +
+ " }" +
+ " stemming: shortest" +
+ " index child_index {" +
+ " stemming: shortest" +
+ " }" +
+ " field child_field type string {" +
+ " indexing: input pf1 | lowercase | index | attribute | summary" +
+ " }" +
+ " rank-profile child_profile inherits parent_profile {" +
+ " }" +
+ " constant child_constant {" +
+ " file: constants/my_constant_tensor_file.json" +
+ " type: tensor<float>(x{},y{})" +
+ " }" +
+ " onnx-model child_model {" +
+ " file: models/my_model.onnx" +
+ " }" +
+ " document-summary child_summary inherits parent_summary {" +
+ " summary cf1 type string {}" +
+ " }" +
+ " import field parentschema_ref.name as child_imported {}" +
+ "}");
+
+ SearchBuilder builder = new SearchBuilder(new DeployLoggerStub());
+ builder.processorsToSkip().add(OnnxModelTypeResolver.class); // Avoid discovering the Onnx model referenced does not exist
+ builder.processorsToSkip().add(ImportedFieldsResolver.class); // Avoid discovering the document reference leads nowhere
+ builder.importString(parentLines);
+ builder.importString(childLines);
+ builder.build(true);
+ var application = builder.application();
+
+ var child = application.schemas().get("child");
+ assertEquals("pf1", child.fieldSets().userFieldSets().get("parent_set").getFieldNames().stream().findFirst().get());
+ assertEquals("[cf1, pf1]", child.fieldSets().userFieldSets().get("child_set").getFieldNames().toString());
+ assertEquals(Stemming.SHORTEST, child.getStemming());
+ assertEquals(Stemming.BEST, child.getIndex("parent_index").getStemming());
+ assertEquals(Stemming.SHORTEST, child.getIndex("child_index").getStemming());
+ assertNotNull(child.getField("parent_field"));
+ assertNotNull(child.getField("child_field"));
+ assertNotNull(child.getExtraField("parent_field"));
+ assertNotNull(child.getExtraField("child_field"));
+ assertNotNull(application.rankProfileRegistry().get(child, "parent_profile"));
+ assertNotNull(application.rankProfileRegistry().get(child, "child_profile"));
+ assertEquals("parent_profile", application.rankProfileRegistry().get(child, "child_profile").getInheritedName());
+ assertNotNull(child.rankingConstants().get("parent_constant"));
+ assertNotNull(child.rankingConstants().get("child_constant"));
+ assertTrue(child.rankingConstants().asMap().containsKey("parent_constant"));
+ assertTrue(child.rankingConstants().asMap().containsKey("child_constant"));
+ assertNotNull(child.onnxModels().get("parent_model"));
+ assertNotNull(child.onnxModels().get("child_model"));
+ assertTrue(child.onnxModels().asMap().containsKey("parent_model"));
+ assertTrue(child.onnxModels().asMap().containsKey("child_model"));
+ assertNotNull(child.getSummary("parent_summary"));
+ assertNotNull(child.getSummary("child_summary"));
+ assertEquals("parent_summary", child.getSummary("child_summary").getInherited().getName());
+ assertTrue(child.getSummaries().containsKey("parent_summary"));
+ assertTrue(child.getSummaries().containsKey("child_summary"));
+ assertNotNull(child.getSummaryField("pf1"));
+ assertNotNull(child.getSummaryField("cf1"));
+ assertNotNull(child.getExplicitSummaryField("pf1"));
+ assertNotNull(child.getExplicitSummaryField("cf1"));
+ assertNotNull(child.getUniqueNamedSummaryFields().get("pf1"));
+ assertNotNull(child.getUniqueNamedSummaryFields().get("cf1"));
+ assertNotNull(child.temporaryImportedFields().get().fields().get("parent_imported"));
+ assertNotNull(child.temporaryImportedFields().get().fields().get("child_imported"));
+ }
+
+ @Test
+ public void testSchemaInheritanceEmptyChildren() throws ParseException {
+ String parentLines = joinLines(
+ "schema parent {" +
+ " document parent {" +
+ " field pf1 type string {" +
+ " indexing: summary" +
+ " }" +
+ " }" +
+ " fieldset parent_set {" +
+ " fields: pf1" +
+ " }" +
+ " stemming: none" +
+ " index parent_index {" +
+ " stemming: best" +
+ " }" +
+ " field parent_field type string {" +
+ " indexing: input pf1 | lowercase | index | attribute | summary" +
+ " }" +
+ " rank-profile parent_profile {" +
+ " }" +
+ " constant parent_constant {" +
+ " file: constants/my_constant_tensor_file.json" +
+ " type: tensor<float>(x{},y{})" +
+ " }" +
+ " onnx-model parent_model {" +
+ " file: models/my_model.onnx" +
+ " }" +
+ " document-summary parent_summary {" +
+ " summary pf1 type string {}" +
+ " }" +
+ " import field parentschema_ref.name as parent_imported {}" +
+ " raw-as-base64-in-summary" +
+ "}");
+ String childLines = joinLines(
+ "schema child inherits parent {" +
+ " document child inherits parent {" +
+ " field cf1 type string {" +
+ " indexing: summary" +
+ " }" +
+ " }" +
"}");
String grandchildLines = joinLines(
"schema grandchild inherits child {" +
@@ -148,7 +258,6 @@ public class SchemaTestCase {
assertNotNull(schema.getSummaryField("pf1"));
assertNotNull(schema.getExplicitSummaryField("pf1"));
assertNotNull(schema.getUniqueNamedSummaryFields().get("pf1"));
- assertTrue(schema.temporaryImportedFields().isPresent());
assertNotNull(schema.temporaryImportedFields().get().fields().get("parent_imported"));
assertTrue(schema.isRawAsBase64());
}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java
index be47f448e40..0e96420f03c 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/DocumentTypeChangeValidatorTest.java
@@ -17,6 +17,7 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newRefeedAction;
import static org.junit.Assert.assertEquals;
@@ -208,7 +209,7 @@ public class DocumentTypeChangeValidatorTest {
return new NewDocumentType(
new NewDocumentType.Name("mydoc"),
headerfields,
- new FieldSets(),
+ new FieldSets(Optional.empty()),
Collections.emptySet(),
Collections.emptySet());
}