diff options
Diffstat (limited to 'config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java')
-rw-r--r-- | config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java index 3aeba7cd265..522d4dc2b15 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java @@ -3,7 +3,7 @@ package com.yahoo.searchdefinition.processing; import com.yahoo.document.DataType; import com.yahoo.document.TensorDataType; -import com.yahoo.searchdefinition.Search; +import com.yahoo.searchdefinition.Schema; import com.yahoo.searchdefinition.document.ImmutableImportedSDField; import com.yahoo.searchdefinition.document.ImmutableSDField; import com.yahoo.searchdefinition.document.ImportedField; @@ -36,9 +36,9 @@ public class ImportedFieldsResolverTestCase { ImportedField myField = model.importedFields.fields().get(fieldName); assertNotNull(myField); assertEquals(fieldName, myField.fieldName()); - assertSame(model.childSearch.getConcreteField("ref"), myField.reference().referenceField()); - assertSame(model.parentSearch, myField.reference().targetSearch()); - ImmutableSDField targetField = model.parentSearch.getField(targetFieldName); + assertSame(model.childSchema.getConcreteField("ref"), myField.reference().referenceField()); + assertSame(model.parentSchema, myField.reference().targetSearch()); + ImmutableSDField targetField = model.parentSchema.getField(targetFieldName); if (targetField instanceof SDField) { assertSame(targetField, myField.targetField()); } else { @@ -60,7 +60,7 @@ public class ImportedFieldsResolverTestCase { @Test public void resolver_fails_if_document_reference_is_not_found() { exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For search 'child', import field 'my_attribute_field': " + 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(); } @@ -68,7 +68,7 @@ public class ImportedFieldsResolverTestCase { @Test public void resolver_fails_if_referenced_field_is_not_found() { exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For search 'child', import field 'my_attribute_field': " + 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(); } @@ -76,7 +76,7 @@ public class ImportedFieldsResolverTestCase { @Test public void resolver_fails_if_imported_field_is_not_an_attribute() { exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("For search 'child', import field 'my_not_attribute': " + 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(); } @@ -85,7 +85,7 @@ public class ImportedFieldsResolverTestCase { public void resolver_fails_if_imported_field_is_indexing() { exceptionRule.expect(IllegalArgumentException.class); exceptionRule.expectMessage( - "For search 'child', import field 'my_attribute_and_index': " + + "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") @@ -96,55 +96,54 @@ public class ImportedFieldsResolverTestCase { public void resolver_fails_if_imported_field_is_of_type_predicate() { exceptionRule.expect(IllegalArgumentException.class); exceptionRule.expectMessage( - "For search 'child', import field 'my_predicate_field': " + + "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(); } static class SearchModel extends ParentChildSearchModel { - public final Search grandParentSearch; + public final Schema grandParentSchema; public ImportedFields importedFields; public SearchModel() { super(); - grandParentSearch = createSearch("grandparent"); - grandParentSearch.getDocument().addField(createField("ancient_field", DataType.INT, "{ attribute }")); - - parentSearch.getDocument().addField(createField("attribute_field", DataType.INT, "{ attribute }")); - parentSearch.getDocument().addField(createField("attribute_and_index", DataType.INT, "{ attribute | index }")); - parentSearch.getDocument().addField(new TemporarySDField("not_attribute", DataType.INT)); - parentSearch.getDocument().addField(createField("tensor_field", new TensorDataType(TensorType.fromSpec("tensor(x[5])")), "{ attribute }")); - parentSearch.getDocument().addField(createField("predicate_field", DataType.PREDICATE, "{ attribute }")); - addRefField(parentSearch, grandParentSearch, "ref"); - addImportedField(parentSearch, "ancient_field", "ref", "ancient_field"); - - addRefField(childSearch, parentSearch, "ref"); + grandParentSchema = createSearch("grandparent"); + grandParentSchema.getDocument().addField(createField("ancient_field", DataType.INT, "{ attribute }")); + + parentSchema.getDocument().addField(createField("attribute_field", DataType.INT, "{ attribute }")); + parentSchema.getDocument().addField(createField("attribute_and_index", DataType.INT, "{ attribute | index }")); + parentSchema.getDocument().addField(new TemporarySDField("not_attribute", DataType.INT)); + parentSchema.getDocument().addField(createField("tensor_field", new TensorDataType(TensorType.fromSpec("tensor(x[5])")), "{ attribute }")); + parentSchema.getDocument().addField(createField("predicate_field", DataType.PREDICATE, "{ attribute }")); + addRefField(parentSchema, grandParentSchema, "ref"); + addImportedField(parentSchema, "ancient_field", "ref", "ancient_field"); + + addRefField(childSchema, parentSchema, "ref"); } protected SearchModel addImportedField(String fieldName, String referenceFieldName, String targetFieldName) { - return addImportedField(childSearch, fieldName, referenceFieldName, targetFieldName); + return addImportedField(childSchema, fieldName, referenceFieldName, targetFieldName); } - protected SearchModel addImportedField(Search search, String fieldName, String referenceFieldName, String targetFieldName) { - super.addImportedField(search, fieldName, referenceFieldName, targetFieldName); + protected SearchModel addImportedField(Schema schema, String fieldName, String referenceFieldName, String targetFieldName) { + super.addImportedField(schema, fieldName, referenceFieldName, targetFieldName); return this; } public void resolve() { - resolve(grandParentSearch); - resolve(parentSearch); - importedFields = resolve(childSearch); + resolve(grandParentSchema); + resolve(parentSchema); + importedFields = resolve(childSchema); } - private static ImportedFields resolve(Search search) { - assertNotNull(search.temporaryImportedFields().get()); - assertFalse(search.importedFields().isPresent()); - new ImportedFieldsResolver(search, null, null, null).process(true, false); - assertFalse(search.temporaryImportedFields().isPresent()); - assertNotNull(search.importedFields().get()); - return search.importedFields().get(); + private static ImportedFields resolve(Schema schema) { + assertNotNull(schema.temporaryImportedFields().get()); + assertFalse(schema.importedFields().isPresent()); + new ImportedFieldsResolver(schema, null, null, null).process(true, false); + assertNotNull(schema.importedFields().get()); + return schema.importedFields().get(); } } |