Search in sources :

Example 51 with DocumentPut

use of com.yahoo.document.DocumentPut 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 52 with DocumentPut

use of com.yahoo.document.DocumentPut 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)

Example 53 with DocumentPut

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

the class JsonReaderTestCase method idAsAliasForPutTest.

@Test
public final void idAsAliasForPutTest() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"id\": \"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 54 with DocumentPut

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

the class JsonReaderTestCase method testArray.

@Test
public final void testArray() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testarray::whee\"," + " \"fields\": { \"actualarray\": [" + " \"nalle\"," + " \"tralle\"]}}"));
    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("actualarray"));
    assertSame(Array.class, f.getClass());
    Array<?> a = (Array<?>) f;
    assertEquals(2, a.size());
    assertEquals(new StringFieldValue("nalle"), a.get(0));
    assertEquals(new StringFieldValue("tralle"), a.get(1));
}
Also used : Array(com.yahoo.document.datatypes.Array) ByteArrayInputStream(java.io.ByteArrayInputStream) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) 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) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Test(org.junit.Test)

Example 55 with DocumentPut

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

the class JsonReaderTestCase method misspelledFieldTest.

@Test
public final void misspelledFieldTest() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"smething\": \"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));
    exception.expect(NullPointerException.class);
    exception.expectMessage("Could not get field \"smething\" in the structure of type \"smoke\".");
    new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
}
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)

Aggregations

DocumentPut (com.yahoo.document.DocumentPut)67 Document (com.yahoo.document.Document)40 DocumentType (com.yahoo.document.DocumentType)35 Test (org.junit.Test)30 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)23 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 DocumentOperation (com.yahoo.document.DocumentOperation)13 DocumentId (com.yahoo.document.DocumentId)12 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)11 FieldValue (com.yahoo.document.datatypes.FieldValue)10 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)10 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)10 DocumentRemove (com.yahoo.document.DocumentRemove)8 DocumentUpdate (com.yahoo.document.DocumentUpdate)7 Array (com.yahoo.document.datatypes.Array)7 DocumentProcessor (com.yahoo.docproc.DocumentProcessor)6 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)5