use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.
the class FeedTesterV3 method createDoctypeManager.
DocumentTypeManager createDoctypeManager() {
DocumentTypeManager docTypeManager = new DocumentTypeManager();
DocumentType documentType = new DocumentType("testdocument");
documentType.addField("title", DataType.STRING);
documentType.addField("body", DataType.STRING);
docTypeManager.registerDocumentType(documentType);
return docTypeManager;
}
use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.
the class ScriptManagerTestCase method requireThatScriptsAreAppliedToSubType.
@Test
public void requireThatScriptsAreAppliedToSubType() throws ParseException {
DocumentTypeManager typeMgr = new DocumentTypeManager();
typeMgr.configure("file:src/test/cfg/documentmanager_inherit.cfg");
DocumentType docType = typeMgr.getDocumentType("newssummary");
assertNotNull(docType);
IlscriptsConfig.Builder config = new IlscriptsConfig.Builder();
config.ilscript(new IlscriptsConfig.Ilscript.Builder().doctype("newssummary").content("index"));
ScriptManager scriptMgr = new ScriptManager(typeMgr, new IlscriptsConfig(config), null);
assertNotNull(scriptMgr.getScript(typeMgr.getDocumentType("newsarticle")));
assertNull(scriptMgr.getScript(new DocumentType("unknown")));
}
use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.
the class ScriptManagerTestCase method requireThatEmptyConfigurationDoesNotThrow.
@Test
public void requireThatEmptyConfigurationDoesNotThrow() {
DocumentTypeManager typeMgr = new DocumentTypeManager();
typeMgr.configure("file:src/test/cfg/documentmanager_inherit.cfg");
ScriptManager scriptMgr = new ScriptManager(typeMgr, new IlscriptsConfig(new IlscriptsConfig.Builder()), null);
assertNull(scriptMgr.getScript(new DocumentType("unknown")));
}
use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.
the class SplitterJoinerTestCase method testSplitJoin.
@Test
public void testSplitJoin() {
ConfigGetter<SplitterJoinerDocumentProcessorConfig> getter = new ConfigGetter<>(SplitterJoinerDocumentProcessorConfig.class);
ConfigGetter<DocumentmanagerConfig> docManGetter = new ConfigGetter<>(DocumentmanagerConfig.class);
SplitterJoinerDocumentProcessorConfig cfg = getter.getConfig("file:src/test/java/com/yahoo/docproc/util/splitter-joiner-document-processor.cfg");
DocumentmanagerConfig docManCfg = docManGetter.getConfig("file:src/test/java/com/yahoo/docproc/util/documentmanager.docindoc.cfg");
SplitterDocumentProcessor splitter = new SplitterDocumentProcessor(cfg, docManCfg);
DocumentTypeManager manager = splitter.manager;
/**
** Create documents: ***
*/
Document inner1 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:one");
inner1.setFieldValue("name", new StringFieldValue("Donald Duck"));
inner1.setFieldValue("content", new StringFieldValue("Lives in Duckburg"));
Document inner2 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:two");
inner2.setFieldValue("name", new StringFieldValue("Uncle Scrooge"));
inner2.setFieldValue("content", new StringFieldValue("Lives in Duckburg, too."));
Array<Document> innerArray = (Array<Document>) manager.getDocumentType("outerdoc").getField("innerdocuments").getDataType().createFieldValue();
innerArray.add(inner1);
innerArray.add(inner2);
Document outer = new Document(manager.getDocumentType("outerdoc"), "doc:outer:the:only:one");
outer.setFieldValue("innerdocuments", innerArray);
/**
** End create documents ***
*/
Processing p = Processing.of(new DocumentPut(outer));
splitter.process(p);
assertEquals(2, p.getDocumentOperations().size());
assertThat(((DocumentPut) (p.getDocumentOperations().get(0))).getDocument(), sameInstance(inner1));
assertThat(((DocumentPut) (p.getDocumentOperations().get(1))).getDocument(), sameInstance(inner2));
assertThat(((DocumentPut) (p.getVariable(cfg.contextFieldName()))).getDocument(), sameInstance(outer));
assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray));
assertTrue(innerArray.isEmpty());
JoinerDocumentProcessor joiner = new JoinerDocumentProcessor(cfg, docManCfg);
joiner.process(p);
assertThat(p.getDocumentOperations().size(), equalTo(1));
assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument(), sameInstance(outer));
assertThat(p.getVariable(cfg.contextFieldName()), nullValue());
assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray));
assertThat(innerArray.size(), equalTo(2));
assertThat(innerArray.get(0), sameInstance(inner1));
assertThat(innerArray.get(1), sameInstance(inner2));
}
use of com.yahoo.document.DocumentTypeManager in project vespa by vespa-engine.
the class ProcessingUpdateTestCase method testProcessingUpdates.
public void testProcessingUpdates() {
DocumentType articleType = new DocumentType("article");
articleType.addField(new Field("body", DataType.STRING, true));
articleType.addField(new Field("title", DataType.STRING, true));
dtm = new DocumentTypeManager();
dtm.registerDocumentType(articleType);
put = new DocumentPut(articleType, "doc:banana:apple");
put.getDocument().setFieldValue("body", "this is the body of the article, blah blah blah");
FieldUpdate upd = FieldUpdate.createAssign(articleType.getField("body"), new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"));
update = new DocumentUpdate(articleType, new DocumentId("doc:grape:orange"));
update.addFieldUpdate(upd);
DocprocService service = new DocprocService("update");
DocumentProcessor firstP = new TitleDocumentProcessor();
service.setCallStack(new CallStack().addLast(firstP));
service.setInService(true);
Processing p = new Processing();
p.addDocumentOperation(put);
p.addDocumentOperation(update);
service.process(p);
while (service.doWork()) {
}
List<DocumentOperation> operations = p.getDocumentOperations();
Document first = ((DocumentPut) operations.get(0)).getDocument();
assertEquals(new StringFieldValue("this is the body of the article, blah blah blah"), first.getFieldValue("body"));
assertEquals(new StringFieldValue("body blah blah blah "), first.getFieldValue("title"));
DocumentUpdate second = (DocumentUpdate) operations.get(1);
FieldUpdate firstUpd = second.getFieldUpdate(0);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, firstUpd.getValueUpdate(0).getValueUpdateClassID());
assertEquals(new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"), firstUpd.getValueUpdate(0).getValue());
FieldUpdate secondUpd = second.getFieldUpdate(1);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, secondUpd.getValueUpdate(0).getValueUpdateClassID());
assertEquals(new StringFieldValue("body blahdi blahdi blahdi "), secondUpd.getValueUpdate(0).getValue());
}
Aggregations