@@ -54,6 +54,7 @@ public class IndexMappingToolTests {
54
54
private GetIndexResponse getIndexResponse ;
55
55
56
56
private Map <String , String > indexParams ;
57
+ private Map <String , String > indexParamsWithRawIndexName ;
57
58
private Map <String , String > otherParams ;
58
59
private Map <String , String > emptyParams ;
59
60
@@ -67,6 +68,7 @@ public void setup() {
67
68
IndexMappingTool .Factory .getInstance ().init (client );
68
69
69
70
indexParams = Map .of ("index" , "[\" foo\" ]" );
71
+ indexParamsWithRawIndexName = Map .of ("index" , "foo" );
70
72
otherParams = Map .of ("other" , "[\" bar\" ]" );
71
73
emptyParams = Collections .emptyMap ();
72
74
}
@@ -175,6 +177,68 @@ public void testRunAsyncIndexMapping() throws Exception {
175
177
assertTrue (responseList .contains ("test.int.setting=123" ));
176
178
}
177
179
180
+ @ Test
181
+ public void testRunWithRawIndexNameInput () throws Exception {
182
+ String indexName = "foo" ;
183
+
184
+ @ SuppressWarnings ("unchecked" )
185
+ ArgumentCaptor <ActionListener <GetIndexResponse >> actionListenerCaptor = ArgumentCaptor .forClass (ActionListener .class );
186
+ doNothing ().when (indicesAdminClient ).getIndex (any (), actionListenerCaptor .capture ());
187
+
188
+ when (getIndexResponse .indices ()).thenReturn (new String [] { indexName });
189
+ Settings settings = Settings .builder ().put ("test.boolean.setting" , false ).put ("test.int.setting" , 123 ).build ();
190
+ when (getIndexResponse .settings ()).thenReturn (Map .of (indexName , settings ));
191
+ String source = """
192
+ {
193
+ "foo": {
194
+ "mappings": {
195
+ "year": {
196
+ "full_name": "year",
197
+ "mapping": {
198
+ "year": {
199
+ "type": "text"
200
+ }
201
+ }
202
+ },
203
+ "age": {
204
+ "full_name": "age",
205
+ "mapping": {
206
+ "age": {
207
+ "type": "integer"
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }""" ;
214
+ MappingMetadata mapping = new MappingMetadata (indexName , XContentHelper .convertToMap (JsonXContent .jsonXContent , source , true ));
215
+ when (getIndexResponse .mappings ()).thenReturn (Map .of (indexName , mapping ));
216
+
217
+ // Now make the call
218
+ Tool tool = IndexMappingTool .Factory .getInstance ().create (Collections .emptyMap ());
219
+ final CompletableFuture <String > future = new CompletableFuture <>();
220
+ ActionListener <String > listener = ActionListener .wrap (r -> { future .complete (r ); }, e -> { future .completeExceptionally (e ); });
221
+
222
+ tool .run (indexParamsWithRawIndexName , listener );
223
+ actionListenerCaptor .getValue ().onResponse (getIndexResponse );
224
+
225
+ future .orTimeout (10 , TimeUnit .SECONDS ).join ();
226
+ String response = future .get ();
227
+ List <String > responseList = Arrays .asList (response .trim ().split ("\\ n" ));
228
+
229
+ assertTrue (responseList .contains ("index: foo" ));
230
+
231
+ assertTrue (responseList .contains ("mappings:" ));
232
+ assertTrue (
233
+ responseList
234
+ .contains ("mappings={year={full_name=year, mapping={year={type=text}}}, age={full_name=age, mapping={age={type=integer}}}}" )
235
+ );
236
+
237
+ assertTrue (responseList .contains ("settings:" ));
238
+ assertTrue (responseList .contains ("test.boolean.setting=false" ));
239
+ assertTrue (responseList .contains ("test.int.setting=123" ));
240
+ }
241
+
178
242
@ Test
179
243
public void testTool () {
180
244
Factory instance = IndexMappingTool .Factory .getInstance ();
0 commit comments