From 73ff44b8334e0660cc379b01af8a0daaa7ee79e7 Mon Sep 17 00:00:00 2001 From: xinyual Date: Tue, 27 Feb 2024 11:48:15 +0800 Subject: [PATCH] add more UTs Signed-off-by: xinyual --- .../processor/chunker/DelimiterChunker.java | 6 ++++-- .../processor/DocumentChunkingProcessorTests.java | 9 +++++++-- .../processor/chunker/DelimiterChunkerTests.java | 13 +++++++++++-- .../processor/DelimiterChunkerProcessor.json | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/opensearch/neuralsearch/processor/chunker/DelimiterChunker.java b/src/main/java/org/opensearch/neuralsearch/processor/chunker/DelimiterChunker.java index 625562a36..31577604f 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/chunker/DelimiterChunker.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/chunker/DelimiterChunker.java @@ -19,10 +19,12 @@ public void validateParameters(Map parameters) { if (parameters.containsKey(DELIMITER_FIELD)) { Object delimiter = parameters.get(DELIMITER_FIELD); if (!(delimiter instanceof String)) { - throw new IllegalArgumentException("delimiter parameters: " + delimiter + " must be string"); + throw new IllegalArgumentException("delimiter parameters: " + delimiter + " must be string."); + } else if (((String) delimiter).length() == 0) { + throw new IllegalArgumentException("delimiter parameters should not be empty."); } } else { - throw new IllegalArgumentException("You must contain field:" + DELIMITER_FIELD + " in your parameter"); + throw new IllegalArgumentException("You must contain field:" + DELIMITER_FIELD + " in your parameter."); } } diff --git a/src/test/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessorTests.java b/src/test/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessorTests.java index 3da358f41..639a85898 100644 --- a/src/test/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessorTests.java +++ b/src/test/java/org/opensearch/neuralsearch/processor/DocumentChunkingProcessorTests.java @@ -1,2 +1,7 @@ -package org.opensearch.neuralsearch.processor;public class DocumentChunkingProcessorTests { -} +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.opensearch.neuralsearch.processor; + +public class DocumentChunkingProcessorTests {} diff --git a/src/test/java/org/opensearch/neuralsearch/processor/chunker/DelimiterChunkerTests.java b/src/test/java/org/opensearch/neuralsearch/processor/chunker/DelimiterChunkerTests.java index 8e16ffee2..8838310f4 100644 --- a/src/test/java/org/opensearch/neuralsearch/processor/chunker/DelimiterChunkerTests.java +++ b/src/test/java/org/opensearch/neuralsearch/processor/chunker/DelimiterChunkerTests.java @@ -22,7 +22,7 @@ public void testChunkerWithNoDelimiterField() { String content = "a\nb\nc\nd"; Map inputParameters = Map.of("", ""); Exception exception = assertThrows(IllegalArgumentException.class, () -> chunker.validateParameters(inputParameters)); - Assert.assertEquals("You must contain field:" + DELIMITER_FIELD + " in your parameter", exception.getMessage()); + Assert.assertEquals("You must contain field:" + DELIMITER_FIELD + " in your parameter.", exception.getMessage()); } @Test @@ -31,7 +31,16 @@ public void testChunkerWithDelimiterFieldNotString() { String content = "a\nb\nc\nd"; Map inputParameters = Map.of(DELIMITER_FIELD, List.of("")); Exception exception = assertThrows(IllegalArgumentException.class, () -> chunker.validateParameters(inputParameters)); - Assert.assertEquals("delimiter parameters: " + List.of("") + " must be string", exception.getMessage()); + Assert.assertEquals("delimiter parameters: " + List.of("") + " must be string.", exception.getMessage()); + } + + @Test + public void testChunkerWithDelimiterFieldNoString() { + DelimiterChunker chunker = new DelimiterChunker(); + String content = "a\nb\nc\nd"; + Map inputParameters = Map.of(DELIMITER_FIELD, ""); + Exception exception = assertThrows(IllegalArgumentException.class, () -> chunker.validateParameters(inputParameters)); + Assert.assertEquals("delimiter parameters should not be empty.", exception.getMessage()); } @Test diff --git a/src/test/resources/processor/DelimiterChunkerProcessor.json b/src/test/resources/processor/DelimiterChunkerProcessor.json index c94f3e249..08077bc54 100644 --- a/src/test/resources/processor/DelimiterChunkerProcessor.json +++ b/src/test/resources/processor/DelimiterChunkerProcessor.json @@ -14,4 +14,4 @@ } } ] -} \ No newline at end of file +}