aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/test
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2018-08-15 14:17:07 +0000
committerTor Egge <Tor.Egge@oath.com>2018-08-15 14:17:07 +0000
commit35996c0c1f9c19d144ae4ddffbeb6a965f2be200 (patch)
treea76dec1166e85b4f6fa9322fcaf5827472d33047 /document/src/test
parentce18b860f1a7802fde6230e615a259fccbc34c3d (diff)
Iterate over result list in reverse order to avoid stale
array indexes when removing array elements.
Diffstat (limited to 'document/src/test')
-rwxr-xr-xdocument/src/test/java/com/yahoo/document/DocumentPathUpdateTestCase.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/document/src/test/java/com/yahoo/document/DocumentPathUpdateTestCase.java b/document/src/test/java/com/yahoo/document/DocumentPathUpdateTestCase.java
index a0c891a3f30..ce55a5a501c 100755
--- a/document/src/test/java/com/yahoo/document/DocumentPathUpdateTestCase.java
+++ b/document/src/test/java/com/yahoo/document/DocumentPathUpdateTestCase.java
@@ -103,6 +103,24 @@ public class DocumentPathUpdateTestCase {
}
@Test
+ public void testApplyRemoveMultiList2() {
+ Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
+ assertNull(doc.getFieldValue("strarray"));
+ Array<StringFieldValue> strArray = new Array<>(doc.getField("strarray").getDataType());
+ strArray.add(new StringFieldValue("remove val 0 and 1"));
+ strArray.add(new StringFieldValue("remove val 0 and 1"));
+ strArray.add(new StringFieldValue("hello hello"));
+ doc.setFieldValue("strarray", strArray);
+ assertNotNull(doc.getFieldValue("strarray"));
+ DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
+ docUp.addFieldPathUpdate(new RemoveFieldPathUpdate(doc.getDataType(), "strarray[$x]", "foobar.strarray[$x] == \"remove val 0 and 1\""));
+ docUp.applyTo(doc);
+ assertEquals(1, ((List) doc.getFieldValue("strarray")).size());
+ List docList = (List) doc.getFieldValue("strarray");
+ assertEquals(new StringFieldValue("hello hello"), docList.get(0));
+ }
+
+ @Test
public void testApplyRemoveEntireListField() {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
assertNull(doc.getFieldValue("strarray"));