Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: YANGDB <[email protected]>
  • Loading branch information
YANG-DB committed Dec 11, 2024
1 parent f76ee37 commit fe8d600
Showing 1 changed file with 0 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@
import org.junit.Test;
import scala.collection.mutable.WrappedArray;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.apache.derby.vti.XmlVTI.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.opensearch.sql.expression.function.SerializableUdf.jsonAppendFunction;
import static org.opensearch.sql.expression.function.SerializableUdf.jsonDeleteFunction;
import static org.opensearch.sql.expression.function.SerializableUdf.jsonExtendFunction;

public class SerializableJsonUdfTest {

Expand Down Expand Up @@ -158,94 +150,4 @@ public void testJsonAppendFunctionInvalidJson() {
String result = jsonAppendFunction.apply(invalidJson, WrappedArray.make(new String[]{"key1", "newValue"}));
assertNull(result);
}

@Test
public void testJsonExtendFunctionWithExistingPath() {
String jsonStr = "{\"path1\": [\"value1\", \"value2\"]}";
List<Map.Entry<String, List<String>>> pathValuePairs = new ArrayList<>();
pathValuePairs.add(Map.entry("path1", asList("value3", "value4")));

String result = jsonExtendFunction.apply(jsonStr, pathValuePairs);
String expectedJson = "{\"path1\":[\"value1\",\"value2\",\"value3\",\"value4\"]}";

assertEquals(expectedJson, result);
}

@Test
public void testJsonExtendFunctionWithNewPath() {
String jsonStr = "{\"path1\": [\"value1\"]}";
List<Map.Entry<String, List<String>>> pathValuePairs = new ArrayList<>();
pathValuePairs.add(Map.entry("path2", asList("newValue1", "newValue2")));

String result = jsonExtendFunction.apply(jsonStr, pathValuePairs);
String expectedJson = "{\"path1\":[\"value1\"],\"path2\":[\"newValue1\",\"newValue2\"]}";

assertEquals(expectedJson, result);
}

@Test
public void testJsonExtendFunctionWithNullInput() {
String result = jsonExtendFunction.apply(null, Collections.emptyList());
assertNull(result);
}

@Test
public void testJsonExtendFunctionWithInvalidJson() {
String result = jsonExtendFunction.apply("invalid json", Collections.emptyList());
assertNull(result);
}

@Test
public void testJsonExtendFunctionWithNonArrayPath() {
String jsonStr = "{\"path1\":\"value1\"}";
List<Map.Entry<String, List<String>>> pathValuePairs = new ArrayList<>();
pathValuePairs.add(Map.entry("path1", asList("value2")));

String result = jsonExtendFunction.apply(jsonStr, pathValuePairs);
String expectedJson = "{\"path1\":[\"value2\"]}";

assertEquals(expectedJson, result);
}

@Test
public void testJsonExtendFunctionAddValuesToExistingArray() {
String jsonStr = "{\"key1\":\"value1\",\"key2\":[\"value2\"]}";
List<Map.Entry<String, List<String>>> pathValuePairs = new ArrayList<>();
pathValuePairs.add( Map.entry("key2", Arrays.asList("value3", "value4")));

String expectedJson = "{\"key1\":\"value1\",\"key2\":[\"value2\",\"value3\",\"value4\"]}";
String result = jsonExtendFunction.apply(jsonStr, pathValuePairs);

assertEquals(expectedJson, result);
}

@Test
public void testJsonExtendFunctionAddNewArray() {
String jsonStr = "{\"key1\":\"value1\"}";
List<Map.Entry<String, List<String>>> pathValuePairs = new ArrayList<>();
pathValuePairs.add( Map.entry("key2", Arrays.asList("value2", "value3")));

String expectedJson = "{\"key1\":\"value1\",\"key2\":[\"value2\",\"value3\"]}";
String result = jsonExtendFunction.apply(jsonStr, pathValuePairs);

assertEquals(expectedJson, result);
}

@Test
public void testJsonExtendFunctionHandleEmptyValues() {
String jsonStr = "{\"key1\":\"value1\",\"key2\":[\"value2\"]}";
List<Map.Entry<String, List<String>>> pathValuePairs = new ArrayList<>();
pathValuePairs.add( Map.entry("key2", Collections.emptyList()));

String expectedJson = "{\"key1\":\"value1\",\"key2\":[\"value2\"]}";
String result = jsonExtendFunction.apply(jsonStr, pathValuePairs);

assertEquals(expectedJson, result);
}

@Test
public void testJsonExtendFunctionHandleNullInput() {
String result = jsonExtendFunction.apply(null, Collections.singletonList( Map.entry("key2", List.of("value2"))));
assertEquals(null, result);
}
}

0 comments on commit fe8d600

Please sign in to comment.