From 2cf4cc1f2a4ad1adace9b0e5877d9fbed6983323 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 19 Jan 2023 23:08:25 +0100 Subject: Prep testing for implementing fallback --- docprocs/src/test/cfg/documentmanager.cfg | 12 +++++ docprocs/src/test/cfg/ilscripts.cfg | 5 +- .../indexing/IndexingProcessorTestCase.java | 56 +++++++++++++++++++++- 3 files changed, 71 insertions(+), 2 deletions(-) (limited to 'docprocs/src') diff --git a/docprocs/src/test/cfg/documentmanager.cfg b/docprocs/src/test/cfg/documentmanager.cfg index 017c7bdffe1..cf3101581d9 100644 --- a/docprocs/src/test/cfg/documentmanager.cfg +++ b/docprocs/src/test/cfg/documentmanager.cfg @@ -115,6 +115,12 @@ doctype[1].structtype[0].field[17].type 10017 doctype[1].structtype[0].field[18].name "titles" doctype[1].structtype[0].field[18].internalid 1831803314 doctype[1].structtype[0].field[18].type 10016 +doctype[1].structtype[0].field[19].name "combined" +doctype[1].structtype[0].field[19].internalid 12345 +doctype[1].structtype[0].field[19].type 10016 +doctype[2].structtype[0].field[20].name "combinedWithFallback" +doctype[2].structtype[0].field[20].internalid 67890 +doctype[2].structtype[0].field[20].type 10004 doctype[2].name "music" doctype[2].idx 10018 doctype[2].inherits[0].idx 10000 @@ -249,6 +255,12 @@ doctype[2].structtype[0].field[37].type 10004 doctype[2].structtype[0].field[38].name "multiposition2d" doctype[2].structtype[0].field[38].internalid 807198992 doctype[2].structtype[0].field[38].type 10016 +doctype[2].structtype[0].field[39].name "combined" +doctype[2].structtype[0].field[39].internalid 12345 +doctype[2].structtype[0].field[39].type 10004 +doctype[2].structtype[0].field[40].name "combinedWithFallback" +doctype[2].structtype[0].field[40].internalid 67890 +doctype[2].structtype[0].field[40].type 10004 doctype[3].name "music_summary" doctype[3].idx 10023 doctype[3].inherits[0].idx 10000 diff --git a/docprocs/src/test/cfg/ilscripts.cfg b/docprocs/src/test/cfg/ilscripts.cfg index 550cbed2c26..f54aebb1685 100644 --- a/docprocs/src/test/cfg/ilscripts.cfg +++ b/docprocs/src/test/cfg/ilscripts.cfg @@ -5,8 +5,11 @@ ilscript[0].docfield[0] "artist" ilscript[0].docfield[1] "title" ilscript[0].docfield[2] "isbn" ilscript[0].docfield[3] "song" -ilscript[0].content[4] +ilscript[0].content[5] ilscript[0].content[0] "input artist | attribute title" ilscript[0].content[1] "input title | attribute artist" ilscript[0].content[2] "input isbn | passthrough isbn" ilscript[0].content[3] "input isbn | attribute song" +ilscript[0].content[4] "input artist . " ". input title | index combined" +ilscript[0].content[5] "input artist . " ". input title | index combinedWithFallback" + diff --git a/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java b/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java index 1f7cd008fb0..f4049777d77 100644 --- a/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java +++ b/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java @@ -23,6 +23,7 @@ import org.junit.Test; import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -99,6 +100,49 @@ public class IndexingProcessorTestCase { } + @Test + public void testFieldDependingOnTwoInputs() { + // 'artist' is assigned to 'title' and vice versa + // 'combined' gets the value of both + // 'combinedWithFallback' falls back to an empty string if an input is missing + + { // Both inputs are set + DocumentType inputType = indexer.getDocumentTypeManager().getDocumentType("music"); + DocumentUpdate input = new DocumentUpdate(inputType, "id:ns:music::"); + input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("artist"), new StringFieldValue("artist1"))); + input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("title"), new StringFieldValue("title1"))); + + DocumentUpdate output = (DocumentUpdate)process(input); + assertEquals(4, output.fieldUpdates().size()); + assertAssignment("artist", "title1", output); + assertAssignment("title", "artist1", output); + assertAssignment("combined", "artist1 title1", output); + assertAssignment("combinedWithFallback", "artist1 title1", output); + } + + { // Just artist is set + DocumentType inputType = indexer.getDocumentTypeManager().getDocumentType("music"); + DocumentUpdate input = new DocumentUpdate(inputType, "id:ns:music::"); + input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("artist"), new StringFieldValue("artist1"))); + // no title + + DocumentUpdate output = (DocumentUpdate)process(input); + assertEquals(1, output.fieldUpdates().size()); + assertAssignment("title", "artist1", output); + } + + { // Just title is set + DocumentType inputType = indexer.getDocumentTypeManager().getDocumentType("music"); + DocumentUpdate input = new DocumentUpdate(inputType, "id:ns:music::"); + input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("title"), new StringFieldValue("title1"))); + // no title + + DocumentUpdate output = (DocumentUpdate)process(input); + assertEquals(1, output.fieldUpdates().size()); + assertAssignment("artist", "title1", output); + } + } + @Test public void requireThatEmptyDocumentUpdateOutputDoesNotThrow() { DocumentType inputType = indexer.getDocumentTypeManager().getDocumentType("music"); @@ -116,6 +160,16 @@ public class IndexingProcessorTestCase { assertSame(input, output); } + private void assertAssignment(String fieldName, String value, DocumentUpdate output) { + FieldUpdate update = output.getFieldUpdate(fieldName); + assertNotNull("Update of '" + fieldName + "' exists", update); + assertEquals(fieldName, update.getField().getName()); + assertEquals(1, update.getValueUpdates().size()); + ValueUpdate combinedAssignment = update.getValueUpdate(0); + assertTrue(combinedAssignment instanceof AssignValueUpdate); + assertEquals(new StringFieldValue(value), combinedAssignment.getValue()); + } + private DocumentOperation process(DocumentOperation input) { Processing proc = new Processing(); proc.getDocumentOperations().add(input); @@ -131,6 +185,6 @@ public class IndexingProcessorTestCase { return new IndexingProcessor(new DocumentTypeManager(ConfigGetter.getConfig(DocumentmanagerConfig.class, configId)), ConfigGetter.getConfig(IlscriptsConfig.class, configId), new SimpleLinguistics(), - new ComponentRegistry()); + new ComponentRegistry<>()); } } -- cgit v1.2.3