diff options
Diffstat (limited to 'config-model/src/test/java/com/yahoo')
8 files changed, 50 insertions, 23 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java index e0a4d0f24ca..4fae4d92cb0 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/DocumentGraphValidatorTest.java @@ -17,6 +17,8 @@ import java.util.List; import java.util.Map; import static java.util.stream.Collectors.toList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author bjorncs @@ -118,16 +120,21 @@ public class DocumentGraphValidatorTest { validator.validateDocumentGraph(documentListOf(adSearch)); } + /** + * Self inheritance is checked early because it is possible, and because it otherwise + * produces a stack overflow before getting to graph validation. + */ @Test public void self_inheritance_forbidden() { - Search adSearch = createSearchWithName("ad"); - SDDocumentType document = adSearch.getDocument(); - document.inherit(document); - - DocumentGraphValidator validator = new DocumentGraphValidator(); - exceptionRule.expect(DocumentGraphValidator.DocumentGraphException.class); - exceptionRule.expectMessage("Document dependency cycle detected: ad->ad."); - validator.validateDocumentGraph(documentListOf(adSearch)); + try { + Search adSearch = createSearchWithName("ad"); + SDDocumentType document = adSearch.getDocument(); + document.inherit(document); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("Document type 'ad' cannot inherit itself", e.getMessage()); + } } private static List<SDDocumentType> documentListOf(Search... searches) { diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java index 6b39d046600..fff5c2023b9 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java @@ -40,7 +40,7 @@ public class RankingExpressionLoopDetectionTestCase { fail("Excepted exception"); } catch (IllegalArgumentException e) { - assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: foo is invalid: Invocation loop: foo -> foo", + assertEquals("In schema 'test', rank profile 'test': The function 'foo' is invalid: foo is invalid: Invocation loop: foo -> foo", Exceptions.toMessageString(e)); } } @@ -75,7 +75,7 @@ public class RankingExpressionLoopDetectionTestCase { fail("Excepted exception"); } catch (IllegalArgumentException e) { - assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: arg(5) is invalid: foo is invalid: arg(5) is invalid: Invocation loop: arg(5) -> foo -> arg(5)", + assertEquals("In schema 'test', rank profile 'test': The function 'foo' is invalid: arg(5) is invalid: foo is invalid: arg(5) is invalid: Invocation loop: arg(5) -> foo -> arg(5)", Exceptions.toMessageString(e)); } } @@ -110,7 +110,7 @@ public class RankingExpressionLoopDetectionTestCase { fail("Excepted exception"); } catch (IllegalArgumentException e) { - assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: arg(foo) is invalid: a1 is invalid: foo is invalid: arg(foo) is invalid: Invocation loop: arg(foo) -> foo -> arg(foo)", + assertEquals("In schema 'test', rank profile 'test': The function 'foo' is invalid: arg(foo) is invalid: a1 is invalid: foo is invalid: arg(foo) is invalid: Invocation loop: arg(foo) -> foo -> arg(foo)", Exceptions.toMessageString(e)); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java index f8d03d3574b..d871a863dcd 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java @@ -216,6 +216,26 @@ public class SummaryTestCase { } } + @Test + public void testValidationOfInheritedSummary() throws ParseException { + try { + String schema = joinLines( + "schema test {" + + " document test {" + + " }" + + " document-summary test_summary inherits nonesuch {" + + " }" + + "}"); + DeployLoggerStub logger = new DeployLoggerStub(); + SearchBuilder.createFromStrings(logger, schema); + fail("Expected failure"); + } + catch (IllegalArgumentException e) { + assertEquals("document summary 'test_summary' inherits nonesuch but this is not present in schema 'test'", + e.getMessage()); + } + } + private static class TestValue { private final DocumentSummary summary; diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/UrlFieldValidationTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/UrlFieldValidationTestCase.java index be2b048f211..8873fc36303 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/UrlFieldValidationTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/UrlFieldValidationTestCase.java @@ -26,7 +26,7 @@ public class UrlFieldValidationTestCase { fail("Should have caused an exception"); // success } catch (IllegalArgumentException e) { - assertEquals("Error in field 'a' in search definition 'test': uri type fields cannot be attributes", + assertEquals("Error in field 'a' in schema 'test': uri type fields cannot be attributes", Exceptions.toMessageString(e)); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java index c82d39e084f..f0fab8e4810 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AddAttributeTransformToSummaryOfImportedFieldsTest.java @@ -36,7 +36,7 @@ public class AddAttributeTransformToSummaryOfImportedFieldsTest { public void attribute_summary_transform_applied_to_summary_field_of_imported_field() { Search search = createSearchWithDocument(DOCUMENT_NAME); search.setImportedFields(createSingleImportedField(IMPORTED_FIELD_NAME)); - search.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME)); + search.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME, search)); AddAttributeTransformToSummaryOfImportedFields processor = new AddAttributeTransformToSummaryOfImportedFields( search,null,null,null); @@ -65,8 +65,8 @@ public class AddAttributeTransformToSummaryOfImportedFieldsTest { return new ImportedFields(Collections.singletonMap(fieldName, importedField)); } - private static DocumentSummary createDocumentSummary(String fieldName) { - DocumentSummary summary = new DocumentSummary("mysummary"); + private static DocumentSummary createDocumentSummary(String fieldName, Search search) { + DocumentSummary summary = new DocumentSummary("mysummary", search); summary.add(new SummaryField(fieldName, DataType.INT)); return summary; } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java index 47e74185902..f9796432de8 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/AdjustPositionSummaryFieldsTestCase.java @@ -200,7 +200,7 @@ public class AdjustPositionSummaryFieldsTestCase { public void addSummaryField(String summaryName, String fieldName, DataType dataType, SummaryTransform transform, String source) { DocumentSummary summary = childSearch.getSummary(summaryName); if (summary == null) { - summary = new DocumentSummary(summaryName); + summary = new DocumentSummary(summaryName, childSearch); childSearch.addSummary(summary); } SummaryField summaryField = new SummaryField(fieldName, dataType); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java index 8fa4c9952ff..3bdcca52236 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java @@ -52,7 +52,7 @@ public class RankingExpressionTypeResolverTestCase { fail("Expected exception"); } catch (IllegalArgumentException expected) { - assertEquals("In search definition '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])", + 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)); } } @@ -100,7 +100,7 @@ public class RankingExpressionTypeResolverTestCase { fail("Expected exception"); } catch (IllegalArgumentException expected) { - assertEquals("In search definition '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{})", + 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)); } } @@ -132,7 +132,7 @@ public class RankingExpressionTypeResolverTestCase { fail("Expected exception"); } catch (IllegalArgumentException expected) { - assertEquals("In search definition '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])", + 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)); } } @@ -162,7 +162,7 @@ public class RankingExpressionTypeResolverTestCase { fail("Expected exception"); } catch (IllegalArgumentException expected) { - assertEquals("In search definition '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])" + + 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)); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ValidateFieldTypesTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ValidateFieldTypesTest.java index adc146a2047..c7b9ce16338 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ValidateFieldTypesTest.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ValidateFieldTypesTest.java @@ -37,7 +37,7 @@ public class ValidateFieldTypesTest { public void throws_exception_if_type_of_document_field_does_not_match_summary_field() { Search search = createSearchWithDocument(DOCUMENT_NAME); search.setImportedFields(createSingleImportedField(IMPORTED_FIELD_NAME, DataType.INT)); - search.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME, DataType.STRING)); + search.addSummary(createDocumentSummary(IMPORTED_FIELD_NAME, DataType.STRING, search)); ValidateFieldTypes validator = new ValidateFieldTypes(search, null, null, null); exceptionRule.expect(IllegalArgumentException.class); @@ -66,8 +66,8 @@ public class ValidateFieldTypesTest { return new ImportedFields(Collections.singletonMap(fieldName, importedField)); } - private static DocumentSummary createDocumentSummary(String fieldName, DataType dataType) { - DocumentSummary summary = new DocumentSummary("mysummary"); + private static DocumentSummary createDocumentSummary(String fieldName, DataType dataType, Search search) { + DocumentSummary summary = new DocumentSummary("mysummary", search); summary.add(new SummaryField(fieldName, dataType)); return summary; } |