From 7417e739480eea577de1b1832710587f9f15a977 Mon Sep 17 00:00:00 2001 From: yuye-aws Date: Wed, 24 Apr 2024 17:51:02 +0800 Subject: [PATCH] remove search index tool integration tests Signed-off-by: yuye-aws --- .../integTest/SearchIndexToolIT.java | 136 ------------------ 1 file changed, 136 deletions(-) delete mode 100644 src/test/java/org/opensearch/integTest/SearchIndexToolIT.java diff --git a/src/test/java/org/opensearch/integTest/SearchIndexToolIT.java b/src/test/java/org/opensearch/integTest/SearchIndexToolIT.java deleted file mode 100644 index f989ebef..00000000 --- a/src/test/java/org/opensearch/integTest/SearchIndexToolIT.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.integTest; - -import static org.hamcrest.Matchers.containsString; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; - -import org.hamcrest.MatcherAssert; -import org.junit.After; -import org.junit.Before; -import org.opensearch.client.ResponseException; - -import lombok.SneakyThrows; - -public class SearchIndexToolIT extends BaseAgentToolsIT { - public static String TEST_INDEX_NAME = "test_index"; - private String registerAgentRequestBody; - - @SneakyThrows - private void prepareIndex() { - createIndexWithConfiguration( - TEST_INDEX_NAME, - "{\n" - + " \"mappings\": {\n" - + " \"properties\": {\n" - + " \"text\": {\n" - + " \"type\": \"text\"\n" - + " }\n" - + " }\n" - + " }\n" - + "}" - ); - addDocToIndex(TEST_INDEX_NAME, "0", List.of("text"), List.of("text doc 1")); - addDocToIndex(TEST_INDEX_NAME, "1", List.of("text"), List.of("text doc 2")); - addDocToIndex(TEST_INDEX_NAME, "2", List.of("text"), List.of("text doc 3")); - } - - @Before - @SneakyThrows - public void setUp() { - super.setUp(); - prepareIndex(); - registerAgentRequestBody = Files - .readString( - Path - .of( - this - .getClass() - .getClassLoader() - .getResource("org/opensearch/agent/tools/register_flow_agent_of_search_index_tool_request_body.json") - .toURI() - ) - ); - } - - @After - @SneakyThrows - public void tearDown() { - super.tearDown(); - deleteExternalIndices(); - } - - public void testSearchIndexToolInFlowAgent_withMatchAllQuery() { - String agentId = createAgent(registerAgentRequestBody); - String agentInput = "{\n" - + " \"parameters\": {\n" - + " \"input\": {\n" - + " \"index\": \"test_index\",\n" - + " \"query\": {\n" - + " \"query\": {\n" - + " \"match_all\": {}\n" - + " }\n" - + " }\n" - + " } \n" - + " }\n" - + "}\n"; - String result = executeAgent(agentId, agentInput); - assertEquals( - "The search index result not equal with expected.", - "{\"_index\":\"test_index\",\"_source\":{\"text\":\"text doc 1\"},\"_id\":\"0\",\"_score\":1.0}\n" - + "{\"_index\":\"test_index\",\"_source\":{\"text\":\"text doc 2\"},\"_id\":\"1\",\"_score\":1.0}\n" - + "{\"_index\":\"test_index\",\"_source\":{\"text\":\"text doc 3\"},\"_id\":\"2\",\"_score\":1.0}\n", - result - ); - } - - public void testSearchIndexToolInFlowAgent_withEmptyIndexField_thenThrowException() { - String agentId = createAgent(registerAgentRequestBody); - String agentInput = "{\n" - + " \"parameters\": {\n" - + " \"input\": {\n" - + " \"query\": {\n" - + " \"query\": {\n" - + " \"match_all\": {}\n" - + " }\n" - + " }\n" - + " } \n" - + " }\n" - + "}\n"; - Exception exception = assertThrows(ResponseException.class, () -> executeAgent(agentId, agentInput)); - MatcherAssert.assertThat(exception.getMessage(), containsString("SearchIndexTool's two parameter: index and query are required!")); - } - - public void testSearchIndexToolInFlowAgent_withEmptyQueryField_thenThrowException() { - String agentId = createAgent(registerAgentRequestBody); - String agentInput = "{\n" - + " \"parameters\": {\n" - + " \"input\": {\n" - + " \"index\": \"test_index\"\n" - + " } \n" - + " }\n" - + "}\n"; - Exception exception = assertThrows(ResponseException.class, () -> executeAgent(agentId, agentInput)); - MatcherAssert.assertThat(exception.getMessage(), containsString("SearchIndexTool's two parameter: index and query are required!")); - } - - public void testSearchIndexToolInFlowAgent_withIllegalQueryField_thenThrowException() { - String agentId = createAgent(registerAgentRequestBody); - String agentInput = "{\n" - + " \"parameters\": {\n" - + " \"input\": {\n" - + " \"index\": \"test_index\",\n" - + " \"query\": \"Invalid Query\"\n" - + " } \n" - + " }\n" - + "}\n"; - Exception exception = assertThrows(ResponseException.class, () -> executeAgent(agentId, agentInput)); - MatcherAssert.assertThat(exception.getMessage(), containsString("ParsingException")); - } -}