From d65048481a3b6ace8dcc62fea787c2a6b35f36ee Mon Sep 17 00:00:00 2001 From: "Gopala-Krishna.Char" Date: Thu, 4 Jan 2024 11:45:12 +0100 Subject: [PATCH] add test for nested list Signed-off-by: Gopala-Krishna.Char --- .../TextEmbeddingProcessorTests.java | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/opensearch/neuralsearch/processor/TextEmbeddingProcessorTests.java b/src/test/java/org/opensearch/neuralsearch/processor/TextEmbeddingProcessorTests.java index f1936d812..a67cfbde0 100644 --- a/src/test/java/org/opensearch/neuralsearch/processor/TextEmbeddingProcessorTests.java +++ b/src/test/java/org/opensearch/neuralsearch/processor/TextEmbeddingProcessorTests.java @@ -9,11 +9,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.BiConsumer; import java.util.function.Supplier; @@ -398,6 +394,20 @@ public void testBuildVectorOutput_withNestedMap_successful() { assertNotNull(actionGamesKnn); } + public void testBuildVectorOutput_withNestedList_successful() { + Map config = createNestedListConfiguration(); + IngestDocument ingestDocument = createNestedListIngestDocument(); + TextEmbeddingProcessor textEmbeddingProcessor = createInstanceWithNestedMapConfiguration(config); + Map knnMap = textEmbeddingProcessor.buildMapWithProcessorKeyAndOriginalValue(ingestDocument); + List> modelTensorList = createMockVectorResult(); + textEmbeddingProcessor.buildNLPResult(knnMap, modelTensorList, ingestDocument.getSourceAndMetadata()); + List> nestedObj = (List>) ingestDocument.getSourceAndMetadata().get("nestedField"); + assertTrue(nestedObj.get(0).containsKey("vectorField")); + assertTrue(nestedObj.get(1).containsKey("vectorField")); + assertNotNull(nestedObj.get(0).get("vectorField")); + assertNotNull(nestedObj.get(1).get("vectorField")); + } + public void test_updateDocument_appendVectorFieldsToDocument_successful() { Map config = createPlainStringConfiguration(); IngestDocument ingestDocument = createPlainIngestDocument(); @@ -514,4 +524,22 @@ private IngestDocument createNestedMapIngestDocument() { result.put("favorites", favorite); return new IngestDocument(result, new HashMap<>()); } + + private Map createNestedListConfiguration(){ + Map nestedConfig = new HashMap<>(); + nestedConfig.put("textField", "vectorField"); + Map result = new HashMap<>(); + result.put("nestedField", nestedConfig); + return result; + } + + private IngestDocument createNestedListIngestDocument(){ + HashMap nestedObj1 = new HashMap<>(); + nestedObj1.put("textField", "This is a text field"); + HashMap nestedObj2 = new HashMap<>(); + nestedObj2.put("textField", "This is another text field"); + HashMap nestedList = new HashMap<>(); + nestedList.put("nestedField", Arrays.asList(nestedObj1, nestedObj2)); + return new IngestDocument(nestedList, new HashMap<>()); + } }