diff options
author | Arne H Juul <arnej@yahooinc.com> | 2022-03-16 08:49:18 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2022-03-16 09:29:52 +0000 |
commit | 3d7c813384a59e45d937c4eae609c4157f9d179d (patch) | |
tree | bd17583da85dd52485682903c2cf2e49bbb73aa0 /config-model/src/test/java/com | |
parent | f5b958de6c8473dc7e09a6675af4c63d504827d8 (diff) |
validate no annotation references in document
* similar to check in SearchDataTypeValidator
* fails with experimental parsing for now
Diffstat (limited to 'config-model/src/test/java/com')
-rw-r--r-- | config-model/src/test/java/com/yahoo/searchdefinition/AnnotationReferenceTestCase.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/AnnotationReferenceTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/AnnotationReferenceTestCase.java new file mode 100644 index 00000000000..ea89e805ed2 --- /dev/null +++ b/config-model/src/test/java/com/yahoo/searchdefinition/AnnotationReferenceTestCase.java @@ -0,0 +1,62 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition; + +import com.yahoo.document.DataType; +import com.yahoo.document.Field; +import com.yahoo.document.annotation.AnnotationReferenceDataType; +import com.yahoo.searchdefinition.Schema; +import com.yahoo.searchdefinition.document.SDDocumentType; +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.config.model.deploy.TestProperties; +import org.junit.Test; + +import static com.yahoo.config.model.test.TestUtil.joinLines; +import static org.junit.Assert.assertFalse; + +/** + * @author arnej + */ +public class AnnotationReferenceTestCase { + + static final String sd = + joinLines("search test {", + " document test { ", + " struct mystruct {", + " field x type int {}", + " }", + " field a type string {}", + " field b type mystruct {}", + " annotation marker {}", + " annotation person {", + " field name type string {}", + " field age type int {}", + " }", + " annotation complex {", + " field title type string {}", + " field tag type annotationreference<marker> {}", + " field owner type annotationreference<person> {}", + " }", + " }", + "}"); + + @Test + public void noAnnotationReferenceInDocument() throws Exception { + var builder = new ApplicationBuilder(new TestProperties().setExperimentalSdParsing(true)); + builder.addSchema(sd); + builder.build(true); + checkForAnnRef(builder.getSchema().getDocument()); + } + + void checkForAnnRef(SDDocumentType doc) { + for (var child : doc.getTypes()) { + System.err.println("Check child ["+child+"] of parent "+doc); + checkForAnnRef(child); + } + for (Field field : doc.fieldSet()) { + DataType fieldType = field.getDataType(); + System.err.println("datatype "+fieldType+" in field "+field+" in doc "+doc); + assertFalse(fieldType instanceof AnnotationReferenceDataType); + } + } + +} |