use of com.yahoo.document.fieldpathupdate.FieldPathUpdate in project vespa by vespa-engine.
the class DocumentToPathUpdateTestCase method requireThatStructAssignIsConverted.
@Test
public void requireThatStructAssignIsConverted() {
DocumentType docType = new DocumentType("my_type");
StructDataType structType = new StructDataType("my_struct");
structType.addField(new Field("b", DataType.INT));
docType.addField(new Field("a", structType));
Struct struct = structType.createFieldValue();
struct.setFieldValue("b", new IntegerFieldValue(69));
FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "a", "", struct);
Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
assertNotNull(doc);
FieldValue obj = doc.getFieldValue("a");
assertTrue(obj instanceof Struct);
struct = (Struct) obj;
struct.setFieldValue("b", new IntegerFieldValue(96));
DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
assertNotNull(docUpd);
assertEquals(1, docUpd.getFieldPathUpdates().size());
assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
assertTrue(upd instanceof AssignFieldPathUpdate);
assertEquals("a", upd.getOriginalFieldPath());
assertEquals(struct, ((AssignFieldPathUpdate) upd).getNewValue());
}
use of com.yahoo.document.fieldpathupdate.FieldPathUpdate in project vespa by vespa-engine.
the class DocumentToPathUpdateTestCase method requireThatIntegerAssignIsConverted.
@Test
public void requireThatIntegerAssignIsConverted() {
DocumentType docType = new DocumentType("my_type");
docType.addField(new Field("my_int", DataType.INT));
FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "my_int", "", new IntegerFieldValue(69));
Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
assertNotNull(doc);
doc.setFieldValue("my_int", new IntegerFieldValue(96));
DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
assertNotNull(docUpd);
assertEquals(1, docUpd.getFieldPathUpdates().size());
assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
assertTrue(upd instanceof AssignFieldPathUpdate);
assertEquals("my_int", upd.getOriginalFieldPath());
assertEquals(new IntegerFieldValue(96), ((AssignFieldPathUpdate) upd).getNewValue());
}
use of com.yahoo.document.fieldpathupdate.FieldPathUpdate in project vespa by vespa-engine.
the class DocumentToPathUpdateTestCase method requireThatStringAssignIsConverted.
@Test
public void requireThatStringAssignIsConverted() {
DocumentType docType = new DocumentType("my_type");
docType.addField(new Field("my_str", DataType.STRING));
FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "my_str", "", new StringFieldValue("69"));
Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
assertNotNull(doc);
doc.setFieldValue("my_str", new StringFieldValue("96"));
DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
assertNotNull(docUpd);
assertEquals(1, docUpd.getFieldPathUpdates().size());
assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
assertTrue(upd instanceof AssignFieldPathUpdate);
assertEquals("my_str", upd.getOriginalFieldPath());
assertEquals(new StringFieldValue("96"), ((AssignFieldPathUpdate) upd).getNewValue());
}
use of com.yahoo.document.fieldpathupdate.FieldPathUpdate in project vespa by vespa-engine.
the class DocumentToPathUpdateTestCase method requireThatStructElementAssignIsConverted.
@Test
public void requireThatStructElementAssignIsConverted() {
DocumentType docType = new DocumentType("my_type");
StructDataType structType = new StructDataType("my_struct");
structType.addField(new Field("b", DataType.INT));
docType.addField(new Field("a", structType));
FieldPathUpdate upd = new AssignFieldPathUpdate(docType, "a.b", "", new IntegerFieldValue(69));
Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
assertNotNull(doc);
FieldValue obj = doc.getFieldValue("a");
assertTrue(obj instanceof Struct);
Struct struct = (Struct) obj;
struct.setFieldValue("b", new IntegerFieldValue(96));
DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
assertNotNull(docUpd);
assertEquals(1, docUpd.getFieldPathUpdates().size());
assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
assertTrue(upd instanceof AssignFieldPathUpdate);
assertEquals("a.b", upd.getOriginalFieldPath());
obj = ((AssignFieldPathUpdate) upd).getNewValue();
assertTrue(obj instanceof IntegerFieldValue);
assertEquals(96, ((IntegerFieldValue) obj).getInteger());
}
use of com.yahoo.document.fieldpathupdate.FieldPathUpdate in project vespa by vespa-engine.
the class PathUpdateToDocumentTestCase method requireThatAddIsConverted.
@SuppressWarnings({ "unchecked" })
@Test
public void requireThatAddIsConverted() {
DocumentType docType = new DocumentType("my_type");
ArrayDataType arrType = DataType.getArray(DataType.INT);
docType.addField(new Field("my_arr", arrType));
Array<IntegerFieldValue> arrVal = arrType.createFieldValue();
arrVal.add(new IntegerFieldValue(6));
arrVal.add(new IntegerFieldValue(9));
FieldPathUpdate upd = new AddFieldPathUpdate(docType, "my_arr", "", arrVal);
Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
assertNotNull(doc);
FieldValue obj = doc.getFieldValue("my_arr");
assertTrue(obj instanceof Array);
Array arr = (Array) obj;
assertEquals(2, arr.size());
assertEquals(new IntegerFieldValue(6), arr.get(0));
assertEquals(new IntegerFieldValue(9), arr.get(1));
}
Aggregations