summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/AnnotationReferenceTestCase.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-19 12:03:06 +0200
committerJon Bratseth <bratseth@gmail.com>2022-05-19 12:03:06 +0200
commit5c24dc5c9642a8d9ed70aee4c950fd0678a1ebec (patch)
treebd9b74bf00c832456f0b83c1b2cd7010be387d68 /config-model/src/test/java/com/yahoo/schema/AnnotationReferenceTestCase.java
parentf17c4fe7de4c55f5c4ee61897eab8c2f588d8405 (diff)
Rename the 'searchdefinition' package to 'schema'
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/AnnotationReferenceTestCase.java')
-rw-r--r--config-model/src/test/java/com/yahoo/schema/AnnotationReferenceTestCase.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/AnnotationReferenceTestCase.java b/config-model/src/test/java/com/yahoo/schema/AnnotationReferenceTestCase.java
new file mode 100644
index 00000000000..dbe827ed67f
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/schema/AnnotationReferenceTestCase.java
@@ -0,0 +1,67 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema;
+
+import com.yahoo.document.DataType;
+import com.yahoo.document.StructDataType;
+import com.yahoo.document.Field;
+import com.yahoo.document.annotation.AnnotationReferenceDataType;
+import com.yahoo.schema.document.SDDocumentType;
+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;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @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());
+ builder.addSchema(sd);
+ builder.build(true);
+ var doc = builder.getSchema().getDocument();
+ checkForAnnRef(doc);
+ var complex = doc.findAnnotation("complex");
+ var dt = complex.getDataType();
+ assertTrue(dt instanceof StructDataType);
+ var struct = (StructDataType)dt;
+ var field = struct.getField("owner");
+ assertTrue(field.getDataType() instanceof AnnotationReferenceDataType);
+ }
+
+ void checkForAnnRef(SDDocumentType doc) {
+ for (var child : doc.getTypes()) {
+ checkForAnnRef(child);
+ }
+ for (Field field : doc.fieldSet()) {
+ DataType fieldType = field.getDataType();
+ assertFalse(fieldType instanceof AnnotationReferenceDataType);
+ }
+ }
+
+}