summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahoo-inc.com>2017-02-09 12:52:06 +0100
committerGitHub <noreply@github.com>2017-02-09 12:52:06 +0100
commit5f661457a9fbd82ec9a704a388d6424de073f5b3 (patch)
treeb45a0daf4eeae27f001b6d21cc9af71c775ba356 /document
parent6f12f0033c795ffdc821787e38cde2563326c2a1 (diff)
parentbdeb242fffe9d8e43772f110b512d7b58c933481 (diff)
Merge pull request #1723 from yahoo/vekterli/add-reference-field-support-to-concrete-document-types
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..1e4079dd3fe 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 DocumentId 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());
+ }
+
}