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"));
}
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!"));
}
}
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"));
}
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");
}
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"));
}
Aggregations