Search in sources :

Example 66 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonReaderTestCase method controlBasicFeed.

protected void controlBasicFeed(JsonReader r) {
    DocumentOperation d = r.next();
    Document doc = ((DocumentPut) d).getDocument();
    smokeTestDoc(doc);
    d = r.next();
    DocumentUpdate update = (DocumentUpdate) d;
    checkSimpleArrayAdd(update);
    d = r.next();
    DocumentRemove remove = (DocumentRemove) d;
    assertEquals("smoke", remove.getId().getDocType());
    assertNull(r.next());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document)

Example 67 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonReaderTestCase method smokeTest.

@Test
public final void smokeTest() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}}"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentParseInfo parseInfo = r.parseDocument().get();
    DocumentType docType = r.readDocumentType(parseInfo.documentId);
    DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
    new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
    smokeTestDoc(put.getDocument());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Test(org.junit.Test)

Example 68 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonReaderTestCase method docIdLookaheadTest.

@Test
public final void docIdLookaheadTest() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{" + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}," + "\"put\": \"id:unittest:smoke::whee\"" + "}"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentParseInfo parseInfo = r.parseDocument().get();
    DocumentType docType = r.readDocumentType(parseInfo.documentId);
    DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
    new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
    smokeTestDoc(put.getDocument());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Test(org.junit.Test)

Example 69 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonReaderTestCase method testWeightedSet.

@Test
public final void testWeightedSet() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testset::whee\"," + " \"fields\": { \"actualset\": {" + " \"nalle\": 2," + " \"tralle\": 7 }}}"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentParseInfo parseInfo = r.parseDocument().get();
    DocumentType docType = r.readDocumentType(parseInfo.documentId);
    DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
    new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
    Document doc = put.getDocument();
    FieldValue f = doc.getFieldValue(doc.getField("actualset"));
    assertSame(WeightedSet.class, f.getClass());
    WeightedSet<?> w = (WeightedSet<?>) f;
    assertEquals(2, w.size());
    assertEquals(new Integer(2), w.get(new StringFieldValue("nalle")));
    assertEquals(new Integer(7), w.get(new StringFieldValue("tralle")));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) ByteArrayInputStream(java.io.ByteArrayInputStream) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet) Test(org.junit.Test)

Example 70 with Document

use of com.yahoo.document.Document in project vespa by vespa-engine.

the class JsonReaderTestCase method testRaw.

@Test
public final void testRaw() throws IOException {
    String stuff = new String(new JsonStringEncoder().quoteAsString(new Base64().encodeToString(Utf8.toBytes("smoketest"))));
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testraw::whee\"," + " \"fields\": { \"actualraw\": \"" + stuff + "\"" + " }}"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentParseInfo parseInfo = r.parseDocument().get();
    DocumentType docType = r.readDocumentType(parseInfo.documentId);
    DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
    new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
    Document doc = put.getDocument();
    FieldValue f = doc.getFieldValue(doc.getField("actualraw"));
    assertSame(Raw.class, f.getClass());
    Raw s = (Raw) f;
    ByteBuffer b = s.getByteBuffer();
    assertEquals("smoketest", Utf8.toString(b));
}
Also used : Base64(org.apache.commons.codec.binary.Base64) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Raw(com.yahoo.document.datatypes.Raw) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) ByteBuffer(java.nio.ByteBuffer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) JsonStringEncoder(com.fasterxml.jackson.core.io.JsonStringEncoder) ByteArrayInputStream(java.io.ByteArrayInputStream) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Test(org.junit.Test)

Aggregations

Document (com.yahoo.document.Document)109 Test (org.junit.Test)63 DocumentType (com.yahoo.document.DocumentType)41 DocumentPut (com.yahoo.document.DocumentPut)40 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)33 ByteArrayInputStream (java.io.ByteArrayInputStream)23 InputStream (java.io.InputStream)18 DocumentId (com.yahoo.document.DocumentId)16 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)13 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)13 HashMap (java.util.HashMap)13 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)12 FieldValue (com.yahoo.document.datatypes.FieldValue)12 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)12 DocumentOperation (com.yahoo.document.DocumentOperation)10 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)10 DocumentUpdate (com.yahoo.document.DocumentUpdate)8 Array (com.yahoo.document.datatypes.Array)8