|
39 | 39 | import org.opensearch.Version; |
40 | 40 | import org.opensearch.action.admin.indices.analyze.AnalyzeAction; |
41 | 41 | import org.opensearch.action.admin.indices.analyze.TransportAnalyzeAction; |
| 42 | +import org.opensearch.action.support.ActionFilters; |
| 43 | +import org.opensearch.cluster.ClusterName; |
| 44 | +import org.opensearch.cluster.ClusterState; |
42 | 45 | import org.opensearch.cluster.metadata.IndexMetadata; |
| 46 | +import org.opensearch.cluster.metadata.IndexNameExpressionResolver; |
| 47 | +import org.opensearch.cluster.metadata.Metadata; |
| 48 | +import org.opensearch.cluster.metadata.ResolvedIndices; |
| 49 | +import org.opensearch.cluster.service.ClusterService; |
43 | 50 | import org.opensearch.common.UUIDs; |
44 | 51 | import org.opensearch.common.settings.Settings; |
| 52 | +import org.opensearch.common.util.concurrent.ThreadContext; |
45 | 53 | import org.opensearch.env.Environment; |
46 | 54 | import org.opensearch.env.TestEnvironment; |
47 | 55 | import org.opensearch.index.IndexService; |
|
55 | 63 | import org.opensearch.index.analysis.PreConfiguredCharFilter; |
56 | 64 | import org.opensearch.index.analysis.TokenFilterFactory; |
57 | 65 | import org.opensearch.index.analysis.TokenizerFactory; |
| 66 | +import org.opensearch.indices.IndicesService; |
58 | 67 | import org.opensearch.indices.analysis.AnalysisModule; |
59 | 68 | import org.opensearch.indices.analysis.AnalysisModule.AnalysisProvider; |
60 | 69 | import org.opensearch.indices.analysis.AnalysisModuleTests.AppendCharFilter; |
61 | 70 | import org.opensearch.plugins.AnalysisPlugin; |
62 | 71 | import org.opensearch.test.IndexSettingsModule; |
63 | 72 | import org.opensearch.test.OpenSearchTestCase; |
| 73 | +import org.opensearch.threadpool.ThreadPool; |
| 74 | +import org.opensearch.transport.TransportService; |
64 | 75 |
|
65 | 76 | import java.io.IOException; |
66 | 77 | import java.io.Reader; |
@@ -599,4 +610,53 @@ public void testDeprecationWarnings() throws IOException { |
599 | 610 | analyze = TransportAnalyzeAction.analyze(req, registry, mockIndexService(), maxTokenCount); |
600 | 611 | assertEquals(1, analyze.getTokens().size()); |
601 | 612 | } |
| 613 | + |
| 614 | + public void testResolveIndicesForNoIndex() { |
| 615 | + ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 616 | + IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext); |
| 617 | + |
| 618 | + TransportAnalyzeAction action = new TransportAnalyzeAction( |
| 619 | + Settings.EMPTY, |
| 620 | + mock(ThreadPool.class), |
| 621 | + mock(ClusterService.class), |
| 622 | + mock(TransportService.class), |
| 623 | + mock(IndicesService.class), |
| 624 | + mock(ActionFilters.class), |
| 625 | + indexNameExpressionResolver |
| 626 | + ); |
| 627 | + |
| 628 | + AnalyzeAction.Request request = new AnalyzeAction.Request().text("the quick brown fox"); |
| 629 | + assertEquals(ResolvedIndices.of(ResolvedIndices.Local.of()), action.resolveIndices(request)); |
| 630 | + } |
| 631 | + |
| 632 | + public void testResolveIndicesForIndex() { |
| 633 | + ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 634 | + IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext); |
| 635 | + Metadata.Builder mdBuilder = Metadata.builder() |
| 636 | + .put( |
| 637 | + IndexMetadata.builder("test_index") |
| 638 | + .settings( |
| 639 | + settings(Version.CURRENT).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) |
| 640 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) |
| 641 | + ) |
| 642 | + ); |
| 643 | + |
| 644 | + ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); |
| 645 | + |
| 646 | + ClusterService clusterService = mock(ClusterService.class); |
| 647 | + when(clusterService.state()).thenReturn(clusterState); |
| 648 | + |
| 649 | + TransportAnalyzeAction action = new TransportAnalyzeAction( |
| 650 | + Settings.EMPTY, |
| 651 | + mock(ThreadPool.class), |
| 652 | + clusterService, |
| 653 | + mock(TransportService.class), |
| 654 | + mock(IndicesService.class), |
| 655 | + mock(ActionFilters.class), |
| 656 | + indexNameExpressionResolver |
| 657 | + ); |
| 658 | + |
| 659 | + AnalyzeAction.Request request = new AnalyzeAction.Request("test_index").text("the quick brown fox"); |
| 660 | + assertEquals(ResolvedIndices.of(ResolvedIndices.Local.of("test_index")), action.resolveIndices(request)); |
| 661 | + } |
602 | 662 | } |
0 commit comments