Skip to content

Commit

Permalink
Verify exception messages in RelevanceQueryBuildTest
Browse files Browse the repository at this point in the history
Signed-off-by: MaxKsyunz <[email protected]>
  • Loading branch information
MaxKsyunz committed May 25, 2022
1 parent 15775e8 commit ee4e319
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -82,7 +87,9 @@ void calls_action_when_correct_argument_name() {
@ParameterizedTest
@MethodSource("insufficientArguments")
public void throws_SyntaxCheckException_when_no_required_arguments(List<Expression> 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<List<Expression>> insufficientArguments() {
Expand Down

0 comments on commit ee4e319

Please sign in to comment.