Search in sources :

Example 11 with DocumentOperation

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

the class JsonReaderTestCase method testCompleteFeedWithCreateAndCondition.

@Test
public final void testCompleteFeedWithCreateAndCondition() {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}}" + ", " + "{" + "\"condition\":\"bla\"," + "\"update\": \"id:unittest:testarray::whee\"," + " \"create\":true," + " \"fields\": { " + "\"actualarray\": {" + " \"add\": [" + " \"person\"," + " \"another person\"]}}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentOperation d = r.next();
    Document doc = ((DocumentPut) d).getDocument();
    smokeTestDoc(doc);
    d = r.next();
    DocumentUpdate update = (DocumentUpdate) d;
    checkSimpleArrayAdd(update);
    assertThat(update.getCreateIfNonExistent(), is(true));
    assertThat(update.getCondition().getSelection(), is("bla"));
    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) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 12 with DocumentOperation

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

the class JsonReaderTestCase method testCompleteFeedWithEmptyDoc.

@Test
public final void testCompleteFeedWithEmptyDoc() {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": {}}" + ", " + "{\"update\": \"id:unittest:testarray::whee\"," + " \"fields\": {}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentOperation d = r.next();
    Document doc = ((DocumentPut) d).getDocument();
    assertEquals("smoke", doc.getId().getDocType());
    d = r.next();
    DocumentUpdate update = (DocumentUpdate) d;
    assertEquals("testarray", update.getId().getDocType());
    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) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 13 with DocumentOperation

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

the class JsonReaderTestCase method testFeedWithTestAndSetCondition.

private void testFeedWithTestAndSetCondition(String jsonDoc) {
    final ByteArrayInputStream parseInfoDoc = new ByteArrayInputStream(Utf8.toBytes(jsonDoc));
    final JsonReader reader = new JsonReader(types, parseInfoDoc, parserFactory);
    final int NUM_OPERATIONS_IN_FEED = 3;
    for (int i = 0; i < NUM_OPERATIONS_IN_FEED; i++) {
        DocumentOperation operation = reader.next();
        assertTrue("A test and set condition should be present", operation.getCondition().isPresent());
        assertEquals("DocumentOperation's test and set condition should be equal to the one in the JSON feed", "smoke.something == \"smoketest\"", operation.getCondition().getSelection());
    }
    assertNull(reader.next());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 14 with DocumentOperation

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

the class JsonWriterTestCase method removeTest.

@Test
public void removeTest() {
    final DocumentId documentId = new DocumentId("id:unittest:smoke::whee");
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[" + Utf8.toString(JsonWriter.documentRemove(documentId)) + "]"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentOperation actualRemoveAsBaseType = r.next();
    assertSame(DocumentRemove.class, actualRemoveAsBaseType.getClass());
    assertEquals(actualRemoveAsBaseType.getId(), documentId);
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentId(com.yahoo.document.DocumentId) Test(org.junit.Test)

Example 15 with DocumentOperation

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

the class IndexingProcessorTestCase method requireThatIndexerProcessesDocuments.

@Test
public void requireThatIndexerProcessesDocuments() {
    Document input = new Document(indexer.getDocumentTypeManager().getDocumentType("music"), "doc:scheme:");
    input.setFieldValue("artist", new StringFieldValue("69"));
    DocumentOperation op = process(new DocumentPut(input));
    assertTrue(op instanceof DocumentPut);
    Document output = ((DocumentPut) op).getDocument();
    assertEquals(new StringFieldValue("69"), output.getFieldValue("title"));
    assertEquals("music", output.getDataType().getName());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document) Test(org.junit.Test)

Aggregations

DocumentOperation (com.yahoo.document.DocumentOperation)23 DocumentPut (com.yahoo.document.DocumentPut)13 Document (com.yahoo.document.Document)10 DocumentUpdate (com.yahoo.document.DocumentUpdate)8 Test (org.junit.Test)7 DocumentRemove (com.yahoo.document.DocumentRemove)5 DocumentType (com.yahoo.document.DocumentType)5 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DocumentId (com.yahoo.document.DocumentId)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Processing (com.yahoo.docproc.Processing)2 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)2 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)2 FieldUpdate (com.yahoo.document.update.FieldUpdate)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 SplitterDocumentProcessor.doProcessOuterDocument (com.yahoo.docproc.util.SplitterDocumentProcessor.doProcessOuterDocument)1 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)1 Field (com.yahoo.document.Field)1