use of com.yahoo.document.datatypes.Raw in project vespa by vespa-engine.
the class DocumentTestCase method validateCppDocNotMap.
@SuppressWarnings("unchecked")
public void validateCppDocNotMap(Document doc) throws IOException {
// in practice to validate v6 serialization
assertEquals("doc:serializetest:http://test.doc.id/", doc.getId().toString());
assertEquals(new IntegerFieldValue(5), doc.getFieldValue("intfield"));
assertEquals(new FloatFieldValue((float) -9.23), doc.getFieldValue("floatfield"));
assertEquals(new StringFieldValue("This is a string."), doc.getFieldValue("stringfield"));
assertEquals(new LongFieldValue(398420092938472983L), doc.getFieldValue("longfield"));
assertEquals(new DoubleFieldValue(98374532.398820d), doc.getFieldValue("doublefield"));
assertEquals(new StringFieldValue("http://this.is.a.test/"), doc.getFieldValue("urifield"));
// NOTE: The value really is unsigned 254, which becomes signed -2:
assertEquals(new ByteFieldValue(-2), doc.getFieldValue("bytefield"));
ByteBuffer raw = ByteBuffer.wrap("RAW DATA".getBytes());
assertEquals(new Raw(raw), doc.getFieldValue("rawfield"));
Document docindoc = (Document) doc.getFieldValue("docfield");
assertEquals(docMan.getDocumentType("docindoc"), docindoc.getDataType());
assertEquals(new DocumentId("doc:docindoc:http://embedded"), docindoc.getId());
Array<FloatFieldValue> array = (Array<FloatFieldValue>) doc.getFieldValue("arrayoffloatfield");
assertEquals(new FloatFieldValue(1.0f), array.get(0));
assertEquals(new FloatFieldValue(2.0f), array.get(1));
WeightedSet<StringFieldValue> wset = (WeightedSet<StringFieldValue>) doc.getFieldValue("wsfield");
assertEquals(new Integer(50), wset.get(new StringFieldValue("Weighted 0")));
assertEquals(new Integer(199), wset.get(new StringFieldValue("Weighted 1")));
}
use of com.yahoo.document.datatypes.Raw in project vespa by vespa-engine.
the class DocumentTestCase method getSertestDocument.
private Document getSertestDocument() {
Document doc = new Document(docMan.getDocumentType("sertest"), new DocumentId("doc:sertest:foobar"));
doc.setFieldValue("mailid", "emailfromalicetobob");
// 03/13/06 11:00:00
doc.setFieldValue("date", -2013512400);
doc.setFieldValue("attachmentcount", 2);
byte[] rawBytes = new byte[100];
for (int i = 0; i < rawBytes.length; i++) {
rawBytes[i] = (byte) i;
}
doc.setFieldValue("rawfield", new Raw(ByteBuffer.wrap(rawBytes)));
Document docInDoc = new Document(docMan.getDocumentType("docindoc"), new DocumentId("doc:sertest:inserted"));
docInDoc.setFieldValue("tull", "ball");
doc.setFieldValue("docindoc", docInDoc);
WeightedSet<StringFieldValue> wset = new WeightedSet<>(DataType.getWeightedSet(DataType.STRING));
wset.put(new StringFieldValue("this is a test"), 5);
wset.put(new StringFieldValue("this is another test, blah blah"), 10);
doc.setFieldValue("weightedfield", wset);
MapFieldValue<StringFieldValue, StringFieldValue> map = new MapFieldValue<>(new MapDataType(DataType.STRING, DataType.STRING));
map.put(new StringFieldValue("foo1"), new StringFieldValue("bar1"));
map.put(new StringFieldValue("foo2"), new StringFieldValue("bar2"));
doc.setFieldValue("mapfield", map);
return doc;
}
use of com.yahoo.document.datatypes.Raw in project vespa by vespa-engine.
the class DocumentTestCaseBase method getTestDocument.
public Document getTestDocument() {
Document doc = new Document(docMan.getDocumentType("testdoc"), new DocumentId("doc:testdoc:http://www.ntnu.no/"));
doc.setFieldValue(byteField.getName(), (byte) 30);
doc.setFieldValue(byteField.getName(), (byte) 30);
doc.setFieldValue(intField.getName(), 50);
ByteBuffer buf = ByteBuffer.allocate(7).put("hei der".getBytes());
buf.flip();
doc.setFieldValue(rawField, new Raw(buf));
doc.setFieldValue(floatField, new FloatFieldValue((float) 3.56));
doc.setFieldValue("stringattr", "tjohei");
assertNotNull(doc.getId());
assertNotNull(doc.getDataType());
return doc;
}
Aggregations