summaryrefslogtreecommitdiffstats
path: root/document/src/test/java/com/yahoo
diff options
context:
space:
mode:
Diffstat (limited to 'document/src/test/java/com/yahoo')
-rw-r--r--document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java54
-rw-r--r--document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java8
-rw-r--r--document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java4
-rwxr-xr-xdocument/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java44
4 files changed, 57 insertions, 53 deletions
diff --git a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java
index 15319985591..243102c17df 100644
--- a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java
+++ b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java
@@ -1,10 +1,19 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;
-import com.yahoo.document.datatypes.*;
+import com.yahoo.document.datatypes.Array;
+import com.yahoo.document.datatypes.FloatFieldValue;
+import com.yahoo.document.datatypes.IntegerFieldValue;
+import com.yahoo.document.datatypes.StringFieldValue;
+import com.yahoo.document.datatypes.TensorFieldValue;
+import com.yahoo.document.datatypes.WeightedSet;
import com.yahoo.document.fieldpathupdate.FieldPathUpdate;
-import com.yahoo.document.select.parser.ParseException;
-import com.yahoo.document.serialization.*;
+import com.yahoo.document.serialization.DocumentDeserializer;
+import com.yahoo.document.serialization.DocumentDeserializerFactory;
+import com.yahoo.document.serialization.DocumentSerializer;
+import com.yahoo.document.serialization.DocumentSerializerFactory;
+import com.yahoo.document.serialization.DocumentUpdateFlags;
+import com.yahoo.document.serialization.DocumentUpdateWriter;
import com.yahoo.document.update.AssignValueUpdate;
import com.yahoo.document.update.FieldUpdate;
import com.yahoo.document.update.ValueUpdate;
@@ -259,8 +268,8 @@ public class DocumentUpdateTestCase {
update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(1)));
update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(2)));
- assertEquals(1, update.getFieldUpdates().size());
- FieldUpdate fieldUpdate = update.getFieldUpdate(0);
+ assertEquals(1, update.fieldUpdates().size());
+ FieldUpdate fieldUpdate = update.getFieldUpdate(field);
assertNotNull(fieldUpdate);
assertEquals(field, fieldUpdate.getField());
assertEquals(2, fieldUpdate.getValueUpdates().size());
@@ -342,13 +351,16 @@ public class DocumentUpdateTestCase {
assertEquals(new DocumentId("doc:update:test"), upd.getId());
assertEquals(type, upd.getType());
- FieldUpdate serAssignFU = upd.getFieldUpdate(0);
+ FieldUpdate serAssignFU = upd.getFieldUpdate(type.getField("intfield"));
assertEquals(type.getField("intfield"), serAssignFU.getField());
ValueUpdate serAssign = serAssignFU.getValueUpdate(0);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, serAssign.getValueUpdateClassID());
assertEquals(new IntegerFieldValue(4), serAssign.getValue());
- FieldUpdate serAddFU = upd.getFieldUpdate(2);
+ ValueUpdate serArith = serAssignFU.getValueUpdate(1);
+ assertEquals(ValueUpdate.ValueUpdateClassID.ARITHMETIC, serArith.getValueUpdateClassID());
+
+ FieldUpdate serAddFU = upd.getFieldUpdate(type.getField("arrayoffloatfield"));
assertEquals(type.getField("arrayoffloatfield"), serAddFU.getField());
ValueUpdate serAdd1 = serAddFU.getValueUpdate(0);
assertEquals(ValueUpdate.ValueUpdateClassID.ADD, serAdd1.getValueUpdateClassID());
@@ -363,12 +375,7 @@ public class DocumentUpdateTestCase {
FloatFieldValue addparam3 = (FloatFieldValue)serAdd3.getValue();
assertEquals(new FloatFieldValue(-1.00f), addparam3);
- FieldUpdate arithFU = upd.getFieldUpdate(3);
- assertEquals(type.getField("intfield"), serAssignFU.getField());
- ValueUpdate serArith = arithFU.getValueUpdate(0);
- assertEquals(ValueUpdate.ValueUpdateClassID.ARITHMETIC, serArith.getValueUpdateClassID());
-
- FieldUpdate wsetFU = upd.getFieldUpdate(4);
+ FieldUpdate wsetFU = upd.getFieldUpdate(type.getField("wsfield"));
assertEquals(type.getField("wsfield"), wsetFU.getField());
assertEquals(2, wsetFU.size());
ValueUpdate mapUpd = wsetFU.getValueUpdate(0);
@@ -420,8 +427,8 @@ public class DocumentUpdateTestCase {
barUpdate.addFieldUpdate(barField);
fooUpdate.addAll(barUpdate);
- assertEquals(1, fooUpdate.getFieldUpdates().size());
- FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(0);
+ assertEquals(1, fooUpdate.fieldUpdates().size());
+ FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(field);
assertNotNull(fieldUpdate);
assertEquals(field, fieldUpdate.getField());
assertEquals(2, fieldUpdate.getValueUpdates().size());
@@ -465,6 +472,7 @@ public class DocumentUpdateTestCase {
}
@Test
+ @SuppressWarnings("deprecation")
public void testFieldUpdatesInDocUp() {
DocumentType t1 = new DocumentType("doo");
Field f1 = new Field("field1", DataType.STRING);
@@ -493,14 +501,6 @@ public class DocumentUpdateTestCase {
assertSame(fu1, documentUpdate.getFieldUpdate(f1));
- assertSame(fu1, documentUpdate.getFieldUpdate(0));
- assertSame(fu2, documentUpdate.getFieldUpdate(1));
-
- documentUpdate.setFieldUpdate(0, fu2);
- documentUpdate.setFieldUpdate(1, fu1);
- assertEquals(2, documentUpdate.size());
- assertSame(fu1, documentUpdate.getFieldUpdate(1));
- assertSame(fu2, documentUpdate.getFieldUpdate(0));
try {
documentUpdate.setFieldUpdates(null);
@@ -515,12 +515,12 @@ public class DocumentUpdateTestCase {
documentUpdate.setFieldUpdates(fus);
assertEquals(2, documentUpdate.size());
- assertSame(fu1, documentUpdate.getFieldUpdate(0));
- assertSame(fu2, documentUpdate.getFieldUpdate(1));
+ assertSame(fu1, documentUpdate.getFieldUpdate(fu1.getField()));
+ assertSame(fu2, documentUpdate.getFieldUpdate(fu2.getField()));
- documentUpdate.removeFieldUpdate(1);
+ documentUpdate.removeFieldUpdate(fu2.getField());
assertEquals(1, documentUpdate.size());
- assertSame(fu1, documentUpdate.getFieldUpdate(0));
+ assertSame(fu1, documentUpdate.getFieldUpdate(fu1.getField()));
documentUpdate.toString();
diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
index 1fd45cb07c4..32f63e6c0b3 100644
--- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
@@ -292,8 +292,8 @@ public class JsonReaderTestCase {
+ "\"skuggsjaa\": {"
+ "\"assign\": { \"sandra\": \"person\","
+ " \"cloud\": \"another person\"}}}}");
- assertEquals(1, put.getFieldUpdates().size());
- FieldUpdate fu = put.getFieldUpdate(0);
+ assertEquals(1, put.fieldUpdates().size());
+ FieldUpdate fu = put.fieldUpdates().iterator().next();
assertEquals(1, fu.getValueUpdates().size());
ValueUpdate vu = fu.getValueUpdate(0);
assertTrue(vu instanceof AssignValueUpdate);
@@ -315,8 +315,8 @@ public class JsonReaderTestCase {
+ " \"fields\": { "
+ "\"skuggsjaa\": {"
+ "\"assign\": { }}}}");
- assertEquals(1, put.getFieldUpdates().size());
- FieldUpdate fu = put.getFieldUpdate(0);
+ assertEquals(1, put.fieldUpdates().size());
+ FieldUpdate fu = put.fieldUpdates().iterator().next();
assertEquals(1, fu.getValueUpdates().size());
ValueUpdate vu = fu.getValueUpdate(0);
assertTrue(vu instanceof AssignValueUpdate);
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
index ea954f0da40..dcdea0975ad 100644
--- a/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
@@ -46,8 +46,8 @@ public class UriParserTestCase {
DocumentUpdate upd = nextUpdate(it);
assertNotNull(upd);
- assertEquals(1, upd.getFieldUpdates().size());
- FieldUpdate fieldUpd = upd.getFieldUpdate(0);
+ assertEquals(1, upd.fieldUpdates().size());
+ FieldUpdate fieldUpd = upd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_arr"), fieldUpd.getField());
assertEquals(1, fieldUpd.getValueUpdates().size());
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
index 4c64f7c35cb..1aad59f4c56 100755
--- a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
@@ -5,6 +5,7 @@ import com.yahoo.document.*;
import com.yahoo.document.datatypes.*;
import com.yahoo.document.fieldpathupdate.AddFieldPathUpdate;
import com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate;
+import com.yahoo.document.fieldpathupdate.FieldPathUpdate;
import com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate;
import com.yahoo.document.serialization.DeserializationException;
import com.yahoo.document.update.AddValueUpdate;
@@ -16,6 +17,7 @@ import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayInputStream;
+import java.util.Iterator;
import java.util.List;
import static org.junit.Assert.*;
@@ -687,103 +689,105 @@ public class VespaXMLReaderTestCase {
DocumentUpdate docUpdate = op.getDocumentUpdate();
- assertEquals(20, docUpdate.getFieldPathUpdates().size());
+ assertEquals(20, docUpdate.fieldPathUpdates().size());
+ Iterator<FieldPathUpdate> updates = docUpdate.fieldPathUpdates().iterator();
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(0);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("url", ass.getOriginalFieldPath());
assertEquals(new StringFieldValue("assignUrl"), ass.getNewValue());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(1);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("title", ass.getOriginalFieldPath());
assertEquals(new StringFieldValue("assignTitle"), ass.getNewValue());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(2);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("last_downloaded", ass.getOriginalFieldPath());
assertEquals("1", ass.getExpression());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(3);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("value_long", ass.getOriginalFieldPath());
assertEquals("2", ass.getExpression());
}
+ updates.next(); // Skip number 5
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(5);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("stringarr", ass.getOriginalFieldPath());
assertEquals("[assignString1, assignString2]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(6);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("intarr", ass.getOriginalFieldPath());
assertEquals("[3, 4]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(7);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("longarr", ass.getOriginalFieldPath());
assertEquals("[5, 6]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(8);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("bytearr", ass.getOriginalFieldPath());
assertEquals("[7, 8]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(9);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("floatarr", ass.getOriginalFieldPath());
assertEquals("[9.0, 10.0]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(10);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetint", ass.getOriginalFieldPath());
WeightedSet set = (WeightedSet)ass.getNewValue();
assertEquals(Integer.valueOf(11), set.get(new IntegerFieldValue(11)));
assertEquals(Integer.valueOf(12), set.get(new IntegerFieldValue(12)));
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(11);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetstring", ass.getOriginalFieldPath());
WeightedSet set = (WeightedSet)ass.getNewValue();
assertEquals(Integer.valueOf(13), set.get(new StringFieldValue("assign13")));
assertEquals(Integer.valueOf(14), set.get(new StringFieldValue("assign14")));
}
{
- AddFieldPathUpdate ass = (AddFieldPathUpdate)docUpdate.getFieldPathUpdates().get(12);
+ AddFieldPathUpdate ass = (AddFieldPathUpdate)updates.next();
assertEquals("stringarr", ass.getOriginalFieldPath());
assertEquals("[addString1, addString2]", ass.getNewValues().toString());
}
{
- AddFieldPathUpdate ass = (AddFieldPathUpdate)docUpdate.getFieldPathUpdates().get(13);
+ AddFieldPathUpdate ass = (AddFieldPathUpdate)updates.next();
assertEquals("longarr", ass.getOriginalFieldPath());
assertEquals("[5]", ass.getNewValues().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(14);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetint{13}", ass.getOriginalFieldPath());
assertEquals("13", ass.getExpression());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(15);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetint{14}", ass.getOriginalFieldPath());
assertEquals("14", ass.getExpression());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(16);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetstring{add13}", ass.getOriginalFieldPath());
assertEquals("1", ass.getExpression());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(17);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetstring{assign13}", ass.getOriginalFieldPath());
assertEquals("130", ass.getExpression());
}
{
- RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)docUpdate.getFieldPathUpdates().get(18);
+ RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)updates.next();
assertEquals("weightedsetstring{assign14}", ass.getOriginalFieldPath());
}
{
- RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)docUpdate.getFieldPathUpdates().get(19);
+ RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)updates.next();
assertEquals("bytearr", ass.getOriginalFieldPath());
}
Document doc = new Document(manager.getDocumentType("news"), new DocumentId("doc:test:test:test"));