summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahoo-inc.com>2017-02-08 16:49:42 +0100
committerTor Brede Vekterli <vekterli@yahoo-inc.com>2017-02-08 17:02:28 +0100
commitfa231dadff889cccd3b1b2f1a1883d5c20f2dc59 (patch)
tree6530590b7a669c44ea051bf04b472ba985677164 /document
parent27ddf647d881ab58ae69dd629599b52ee7c9d320 (diff)
Support references in concrete document types
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java11
-rw-r--r--document/src/test/java/com/yahoo/document/datatypes/ReferenceFieldValueTestCase.java13
2 files changed, 24 insertions, 0 deletions
diff --git a/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java
index 5d65b25499c..459681d52ae 100644
--- a/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java
+++ b/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java
@@ -151,4 +151,15 @@ public class ReferenceFieldValue extends FieldValue {
public void deserialize(Field field, FieldReader reader) {
reader.read(field, this);
}
+
+ /**
+ * Expose target document ID as this value's wrapped value. Primarily implemented to
+ * allow for transparent interoperability when used in concrete document types.
+ *
+ * @return reference DocumentId, or null if none has been set
+ */
+ @Override
+ public Object getWrappedValue() {
+ return documentId.orElse(null);
+ }
}
diff --git a/document/src/test/java/com/yahoo/document/datatypes/ReferenceFieldValueTestCase.java b/document/src/test/java/com/yahoo/document/datatypes/ReferenceFieldValueTestCase.java
index daa65d6e95e..a1d69238463 100644
--- a/document/src/test/java/com/yahoo/document/datatypes/ReferenceFieldValueTestCase.java
+++ b/document/src/test/java/com/yahoo/document/datatypes/ReferenceFieldValueTestCase.java
@@ -13,6 +13,7 @@ import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
@@ -189,4 +190,16 @@ public class ReferenceFieldValueTestCase {
value.assign(newId);
}
+ @Test
+ public void exposed_wrapped_value_is_null_for_empty_reference() {
+ ReferenceFieldValue nullRef = new ReferenceFieldValue(referenceTypeFoo());
+ assertNull(nullRef.getWrappedValue());
+ }
+
+ @Test
+ public void expose_wrapped_value_is_doc_id_for_non_empty_reference() {
+ ReferenceFieldValue idRef = new ReferenceFieldValue(referenceTypeFoo(), docId("id:ns:foo::toad"));
+ assertEquals(docId("id:ns:foo::toad"), idRef.getWrappedValue());
+ }
+
}