Search in sources :

Example 36 with DocumentPut

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

the class SchemaMappingAndAccessesTest method testProxyAndSecureSecureFailing.

public void testProxyAndSecureSecureFailing() {
    DocumentProcessor procInsecure = new TestDPInsecure();
    Map<Pair<String, String>, String> fieldMap = new HashMap<>();
    fieldMap.put(new Pair<>("album", "titleMapped"), "title");
    procInsecure.setFieldMap(fieldMap);
    DocumentPut put = new DocumentPut(getDoc());
    Document doc = new Call(procInsecure).configDoc(procInsecure, put).getDocument();
    try {
        procInsecure.process(Processing.of(new DocumentPut(doc)));
        fail("Insecure docproc went through");
    } catch (Exception e) {
        assertTrue(e.getMessage().matches(".*allowed.*"));
    }
// assertEquals(doc.get("title"), "MyTitle");
}
Also used : Call(com.yahoo.docproc.Call) DocumentProcessor(com.yahoo.docproc.DocumentProcessor) HashMap(java.util.HashMap) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document) Pair(com.yahoo.collections.Pair)

Example 37 with DocumentPut

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

Example 38 with DocumentPut

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

the class SimpleDocumentProcessorTestCase method requireThatProcessingMultipleOperationsWork.

@Test
public void requireThatProcessingMultipleOperationsWork() {
    DocumentType type = new DocumentType("foobar");
    type.addField("title", DataType.STRING);
    Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"), new DocumentUpdate(type, "doc:this:is:an:update"), new DocumentRemove(new DocumentId("doc:this:is:a:remove")));
    DocprocService service = setupDocprocService(new VerySimpleDocumentProcessor());
    service.getExecutor().process(p);
    assertThat(p.getDocumentOperations().size(), is(3));
    assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
    assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
    assertThat(p.getDocumentOperations().get(1) instanceof DocumentUpdate, is(true));
    assertThat(p.getDocumentOperations().get(2) instanceof DocumentRemove, is(true));
    assertThat(p.getDocumentOperations().get(2).getId().toString(), is("userdoc:foobar:1234:something"));
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

Example 39 with DocumentPut

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

the class SimpleDocumentProcessorTestCase method requireThatProcessingSingleOperationWorks.

@Test
public void requireThatProcessingSingleOperationWorks() {
    DocumentType type = new DocumentType("foobar");
    type.addField("title", DataType.STRING);
    Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"));
    DocprocService service = setupDocprocService(new VerySimpleDocumentProcessor());
    service.getExecutor().process(p);
    assertThat(p.getDocumentOperations().size(), is(1));
    assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
    assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Test(org.junit.Test)

Example 40 with DocumentPut

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

the class SimpleDocumentProcessorTestCase method requireThatThrowingTerminatesIteration.

@Test
public void requireThatThrowingTerminatesIteration() {
    DocumentType type = new DocumentType("foobar");
    type.addField("title", DataType.STRING);
    Processing p = getProcessing(new DocumentPut(type, "doc:this:is:a:document"), new DocumentRemove(new DocumentId("doc:this:is:a:remove")), new DocumentPut(type, "doc:this:is:a:document2"));
    DocprocService service = setupDocprocService(new SimpleDocumentProcessorThrowingOnRemovesAndUpdates());
    try {
        service.getExecutor().process(p);
    } catch (RuntimeException re) {
    // ok
    }
    assertThat(p.getDocumentOperations().size(), is(3));
    assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true));
    assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), is("processed"));
    assertThat(p.getDocumentOperations().get(1) instanceof DocumentRemove, is(true));
    assertThat(p.getDocumentOperations().get(1).getId().toString(), is("doc:this:is:a:remove"));
    assertThat(p.getDocumentOperations().get(2) instanceof DocumentPut, is(true));
    assertThat(((DocumentPut) p.getDocumentOperations().get(2)).getDocument().getFieldValue("title"), nullValue());
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) 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