Search in sources :

Example 6 with DocumentProcessor

use of com.yahoo.docproc.DocumentProcessor in project vespa by vespa-engine.

the class DocumentGenPluginTest method testConcreteProxyDoc.

@Test
public void testConcreteProxyDoc() {
    Book book = getBook();
    Map<String, String> fieldMap = new HashMap<>();
    fieldMap.put("t", "title");
    fieldMap.put("a", "author");
    fieldMap.put("i", "isbn");
    fieldMap.put("y", "year");
    DocumentProcessor dp = new BookProcessor();
    ProxyDocument proxiedBook = new ProxyDocument(dp, book, fieldMap);
    dp.process(Processing.of(new DocumentPut(proxiedBook)));
    assertEquals(proxiedBook.getFieldValue("title").getWrappedValue(), "The T");
    assertEquals(book.getFieldValue("title").getWrappedValue(), "The T");
    assertEquals(book.getTitle(), "The T");
    assertNull(book.getAuthor());
    assertNull(book.getFieldValue("author"));
    assertEquals(book.getYear(), (Integer) 2011);
    assertEquals(book.getFieldValue("year").getWrappedValue(), 2011);
    assertEquals(book.getIsbn(), "ISBN YEP");
    assertEquals(book.getFieldValue("isbn"), new StringFieldValue("ISBN YEP"));
}
Also used : DocumentProcessor(com.yahoo.docproc.DocumentProcessor) ProxyDocument(com.yahoo.docproc.proxy.ProxyDocument) Test(org.junit.Test)

Example 7 with DocumentProcessor

use of com.yahoo.docproc.DocumentProcessor in project vespa by vespa-engine.

the class JDiscContainerDocprocTest method requireThatBasicDocumentProcessingWorks.

@Test
public void requireThatBasicDocumentProcessingWorks() throws Exception {
    try (Application app = new ApplicationBuilder().servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())).documentType("music", DOCUMENT).build()) {
        JDisc container = app.getJDisc("container");
        DocumentProcessing docProc = container.documentProcessing();
        DocumentType type = docProc.getDocumentTypes().get("music");
        ChainRegistry<DocumentProcessor> chains = docProc.getChains();
        assertTrue(chains.allComponentsById().containsKey(new ComponentId(CHAIN_NAME)));
        Document doc = new Document(type, "doc:this:is:a:great:album");
        doc.setFieldValue("title", "Great Album!");
        com.yahoo.docproc.Processing processing;
        DocumentProcessor.Progress progress;
        DocumentPut put = new DocumentPut(doc);
        processing = com.yahoo.docproc.Processing.of(put);
        progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
        processing = com.yahoo.docproc.Processing.of(put);
        progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
    }
}
Also used : Rot13DocumentProcessor(com.yahoo.application.container.docprocs.Rot13DocumentProcessor) DocumentProcessor(com.yahoo.docproc.DocumentProcessor) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) ApplicationBuilder(com.yahoo.application.ApplicationBuilder) Application(com.yahoo.application.Application) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 8 with DocumentProcessor

use of com.yahoo.docproc.DocumentProcessor in project vespa by vespa-engine.

the class SchemaMappingAndAccessesTest method testSchemaMap.

public void testSchemaMap() {
    SchemaMap map = new SchemaMap();
    map.addMapping("mychain", "com.yahoo.MyDocProc", "mydoctype", "inDoc1", "inProc1");
    map.addMapping("mychain", "com.yahoo.MyDocProc", "mydoctype", "inDoc2", "inProc2");
    Map<Pair<String, String>, String> cMap = map.chainMap("mychain", "com.yahoo.MyDocProc");
    assertEquals("inDoc1", cMap.get(new Pair<>("mydoctype", "inProc1")));
    assertEquals("inDoc2", cMap.get(new Pair<>("mydoctype", "inProc2")));
    assertNull(cMap.get(new Pair<>("invalidtype", "inProc2")));
    Map<Pair<String, String>, String> noMap = map.chainMap("invalidchain", "com.yahoo.MyDocProc");
    Map<Pair<String, String>, String> noMap2 = map.chainMap("mychain", "com.yahoo.MyInvalidDocProc");
    assertTrue(noMap.isEmpty());
    assertTrue(noMap2.isEmpty());
    DocumentProcessor proc = new TestDocumentProcessor1();
    proc.setFieldMap(cMap);
    Map<String, String> dMap = proc.getDocMap("mydoctype");
    assertEquals("inDoc1", dMap.get("inProc1"));
    assertEquals("inDoc2", dMap.get("inProc2"));
}
Also used : DocumentProcessor(com.yahoo.docproc.DocumentProcessor) TestDocumentProcessor1(com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1) Pair(com.yahoo.collections.Pair)

Example 9 with DocumentProcessor

use of com.yahoo.docproc.DocumentProcessor 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 10 with DocumentProcessor

use of com.yahoo.docproc.DocumentProcessor in project vespa by vespa-engine.

the class SchemaMappingAndAccessesTest method testSchemaMapNoDocType.

public void testSchemaMapNoDocType() {
    SchemaMap map = new SchemaMap(null);
    map.addMapping("mychain", "com.yahoo.MyDocProc", null, "inDoc1", "inProc1");
    map.addMapping("mychain", "com.yahoo.MyDocProc", null, "inDoc2", "inProc2");
    Map<Pair<String, String>, String> cMap = map.chainMap("mychain", "com.yahoo.MyDocProc");
    DocumentProcessor proc = new TestDocumentProcessor1();
    proc.setFieldMap(cMap);
    Map<String, String> dMap = proc.getDocMap("mydoctype");
    assertEquals("inDoc1", dMap.get("inProc1"));
    assertEquals("inDoc2", dMap.get("inProc2"));
}
Also used : DocumentProcessor(com.yahoo.docproc.DocumentProcessor) TestDocumentProcessor1(com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1) Pair(com.yahoo.collections.Pair)

Aggregations

DocumentProcessor (com.yahoo.docproc.DocumentProcessor)10 Document (com.yahoo.document.Document)6 DocumentPut (com.yahoo.document.DocumentPut)6 Pair (com.yahoo.collections.Pair)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)3 Application (com.yahoo.application.Application)2 ApplicationBuilder (com.yahoo.application.ApplicationBuilder)2 Rot13DocumentProcessor (com.yahoo.application.container.docprocs.Rot13DocumentProcessor)2 ComponentId (com.yahoo.component.ComponentId)2 Call (com.yahoo.docproc.Call)2 TestDocumentProcessor1 (com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1)2 Processing (com.yahoo.docproc.Processing)2 DocumentType (com.yahoo.document.DocumentType)2 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)2 CallStack (com.yahoo.docproc.CallStack)1 ProxyDocument (com.yahoo.docproc.proxy.ProxyDocument)1 Array (com.yahoo.document.datatypes.Array)1 Struct (com.yahoo.document.datatypes.Struct)1