From ee4e31969f47a6e05a0f831b35d4c00168a032a0 Mon Sep 17 00:00:00 2001 From: MaxKsyunz Date: Wed, 25 May 2022 14:10:21 -0700 Subject: [PATCH] Verify exception messages in RelevanceQueryBuildTest Signed-off-by: MaxKsyunz --- .../lucene/relevance/RelevanceQueryBuildTest.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/RelevanceQueryBuildTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/RelevanceQueryBuildTest.java index cfa876dafe..1186031f5f 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/RelevanceQueryBuildTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/RelevanceQueryBuildTest.java @@ -5,6 +5,7 @@ package org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance; +import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -29,6 +30,7 @@ import org.opensearch.sql.data.model.ExprStringValue; import org.opensearch.sql.data.model.ExprValue; import org.opensearch.sql.data.type.ExprType; +import org.opensearch.sql.exception.ExpressionEvaluationException; import org.opensearch.sql.exception.SemanticCheckException; import org.opensearch.sql.expression.Expression; import org.opensearch.sql.expression.FunctionExpression; @@ -54,6 +56,7 @@ public void setUp() { queryBuilder = mock(QueryBuilder.class); when(query.createQueryBuilder(any(), any())).thenReturn(queryBuilder); when(queryBuilder.queryName()).thenReturn("mocked_query"); + when(queryBuilder.getWriteableName()).thenReturn("mock_query"); } @Test @@ -67,7 +70,9 @@ void throws_SemanticCheckException_when_wrong_argument_name() { FunctionExpression expr = createCall(List.of(FIELD_ARG, QUERY_ARG, namedArgument("wrongArg", "value"))); - assertThrows(SemanticCheckException.class, () -> query.build(expr)); + SemanticCheckException exception = + assertThrows(SemanticCheckException.class, () -> query.build(expr)); + assertEquals("Parameter wrongArg is invalid for mock_query function.", exception.getMessage()); } @Test @@ -82,7 +87,9 @@ void calls_action_when_correct_argument_name() { @ParameterizedTest @MethodSource("insufficientArguments") public void throws_SyntaxCheckException_when_no_required_arguments(List arguments) { - assertThrows(SyntaxCheckException.class, () -> query.build(createCall(arguments))); + SyntaxCheckException exception = assertThrows(SyntaxCheckException.class, + () -> query.build(createCall(arguments))); + assertEquals("mock_query requires at least two parameters", exception.getMessage()); } public static Stream> insufficientArguments() {