1111
1212package org .opensearch .security .privileges ;
1313
14+ import java .util .Arrays ;
15+ import java .util .Collection ;
16+ import java .util .Collections ;
17+ import java .util .Map ;
18+
1419import org .junit .Test ;
1520import org .junit .runner .RunWith ;
1621import org .junit .runners .Parameterized ;
1722import org .junit .runners .Suite ;
23+
1824import org .opensearch .action .ActionRequest ;
1925import org .opensearch .action .IndicesRequest ;
2026import org .opensearch .action .OriginalIndices ;
2935import org .opensearch .common .util .concurrent .ThreadContext ;
3036import org .opensearch .security .util .MockIndexMetadataBuilder ;
3137
32- import java .util .Arrays ;
33- import java .util .Collection ;
34- import java .util .Collections ;
35- import java .util .Map ;
36-
3738import static org .junit .Assert .assertArrayEquals ;
3839import static org .junit .Assert .assertEquals ;
3940import static org .junit .Assert .assertFalse ;
4041import static org .junit .Assert .assertTrue ;
4142
4243@ RunWith (Suite .class )
43- @ Suite .SuiteClasses ({
44- IndexRequestModifierTest .SetLocalIndices .class ,
45- IndexRequestModifierTest .SetLocalIndicesToEmpty .class })
44+ @ Suite .SuiteClasses ({ IndexRequestModifierTest .SetLocalIndices .class , IndexRequestModifierTest .SetLocalIndicesToEmpty .class })
4645public class IndexRequestModifierTest {
4746
48- static final IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver (new ThreadContext (Settings .EMPTY ));
47+ static final IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver (
48+ new ThreadContext (Settings .EMPTY )
49+ );
4950 static final Metadata metadata = MockIndexMetadataBuilder .indices ("index" , "index1" , "index2" , "index3" ).build ();
5051 final static ClusterState clusterState = ClusterState .builder (ClusterState .EMPTY_STATE ).metadata (metadata ).build ();
5152 static final IndicesRequestModifier subject = new IndicesRequestModifier ();
@@ -58,17 +59,20 @@ public void basic() {
5859
5960 boolean success = subject .setLocalIndices (request , resolvedIndices , Collections .singletonList ("index1" ));
6061 assertTrue (success );
61- assertArrayEquals (new String [] {"index1" }, request .indices ());
62+ assertArrayEquals (new String [] { "index1" }, request .indices ());
6263 }
6364
6465 @ Test
6566 public void withRemote () {
66- ResolvedIndices resolvedIndices = ResolvedIndices .of ("index1" ).withRemoteIndices (Map .of ("remote" , new OriginalIndices (new String [] {"index_remote" }, IndicesOptions .LENIENT_EXPAND_OPEN )));
67+ ResolvedIndices resolvedIndices = ResolvedIndices .of ("index1" )
68+ .withRemoteIndices (
69+ Map .of ("remote" , new OriginalIndices (new String [] { "index_remote" }, IndicesOptions .LENIENT_EXPAND_OPEN ))
70+ );
6771 SearchRequest request = new SearchRequest ("index1" , "index2" , "index3" , "remote:index_remote" );
6872
6973 boolean success = subject .setLocalIndices (request , resolvedIndices , Collections .singletonList ("index1" ));
7074 assertTrue (success );
71- assertArrayEquals (new String [] {"index1" , "remote:index_remote" }, request .indices ());
75+ assertArrayEquals (new String [] { "index1" , "remote:index_remote" }, request .indices ());
7276 }
7377
7478 @ Test
@@ -78,8 +82,8 @@ public void empty() {
7882
7983 boolean success = subject .setLocalIndices (request , resolvedIndices , Collections .emptyList ());
8084 assertTrue (success );
81- String [] finalResolvedIndices = indexNameExpressionResolver .concreteIndexNames (clusterState , request );
82- assertArrayEquals (new String [0 ], finalResolvedIndices );
85+ String [] finalResolvedIndices = indexNameExpressionResolver .concreteIndexNames (clusterState , request );
86+ assertArrayEquals (new String [0 ], finalResolvedIndices );
8387 }
8488
8589 @ Test
@@ -95,7 +99,6 @@ public void unsupportedType() {
9599 @ RunWith (Parameterized .class )
96100 public static class SetLocalIndicesToEmpty {
97101
98-
99102 String description ;
100103 IndicesRequest request ;
101104
@@ -105,53 +108,49 @@ public void setLocalIndicesToEmpty() {
105108 ResolvedIndices resolvedIndices = ResolvedIndices .of ("index" );
106109
107110 if (Arrays .asList (request .indices ()).contains ("remote:index" )) {
108- resolvedIndices = resolvedIndices .withRemoteIndices (Map .of ("remote" , new OriginalIndices (new String [] {"index" }, request .indicesOptions ())));
111+ resolvedIndices = resolvedIndices .withRemoteIndices (
112+ Map .of ("remote" , new OriginalIndices (new String [] { "index" }, request .indicesOptions ()))
113+ );
109114 }
110115
111116 boolean success = subject .setLocalIndicesToEmpty ((ActionRequest ) request , resolvedIndices );
112117
113118 if (!(request instanceof IndicesRequest .Replaceable )) {
114119 assertFalse (success );
115- } else
116- if (!request .indicesOptions ().allowNoIndices ()) {
120+ } else if (!request .indicesOptions ().allowNoIndices ()) {
117121 assertFalse (success );
118122 } else {
119123 assertTrue (success );
120124
121- String [] finalResolvedIndices = indexNameExpressionResolver .concreteIndexNames (clusterState , request );
125+ String [] finalResolvedIndices = indexNameExpressionResolver .concreteIndexNames (clusterState , request );
122126
123- assertEquals ("Resolved to empty indices: " + Arrays .asList (finalResolvedIndices ), 0 , finalResolvedIndices .length );
127+ assertEquals ("Resolved to empty indices: " + Arrays .asList (finalResolvedIndices ), 0 , finalResolvedIndices .length );
124128 }
125129 }
126130
127-
128131 @ Parameterized .Parameters (name = "{0}" )
129132 public static Collection <Object []> params () {
130133 return Arrays .asList (
131- new Object [] {
132- "lenient expand open" , new SearchRequest ("index" ).indicesOptions (IndicesOptions .LENIENT_EXPAND_OPEN )
133- },
134- new Object [] {
135- "lenient expand open/closed" , new SearchRequest ("index" ).indicesOptions (IndicesOptions .LENIENT_EXPAND_OPEN_CLOSED )
136- },
137- new Object [] {
138- "lenient expand open/closed/hidden" , new SearchRequest ("index" ).indicesOptions (IndicesOptions .LENIENT_EXPAND_OPEN_CLOSED_HIDDEN )
139- },
140- new Object [] {
141- "allow no indices" , new SearchRequest ("index" ).indicesOptions (IndicesOptions .fromOptions (false , true , false , false ))
142- },
143- new Object [] {
144- "ignore unavailable" , new SearchRequest ("index" ).indicesOptions (IndicesOptions .fromOptions (true , false , false , false ))
145- },
146- new Object [] {
147- "strict single index" , new SearchRequest ("index" ).indicesOptions (IndicesOptions .STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED )
148- },
149- new Object [] {
150- "with remote index" , new SearchRequest ("index" , "remote:index" ).indicesOptions (IndicesOptions .LENIENT_EXPAND_OPEN )
151- },
152- new Object [] {
153- "not implementing IndicesRequest.Replaceable" , new IndexRequest ("index" )
154- }
134+ new Object [] { "lenient expand open" , new SearchRequest ("index" ).indicesOptions (IndicesOptions .LENIENT_EXPAND_OPEN ) },
135+ new Object [] {
136+ "lenient expand open/closed" ,
137+ new SearchRequest ("index" ).indicesOptions (IndicesOptions .LENIENT_EXPAND_OPEN_CLOSED ) },
138+ new Object [] {
139+ "lenient expand open/closed/hidden" ,
140+ new SearchRequest ("index" ).indicesOptions (IndicesOptions .LENIENT_EXPAND_OPEN_CLOSED_HIDDEN ) },
141+ new Object [] {
142+ "allow no indices" ,
143+ new SearchRequest ("index" ).indicesOptions (IndicesOptions .fromOptions (false , true , false , false )) },
144+ new Object [] {
145+ "ignore unavailable" ,
146+ new SearchRequest ("index" ).indicesOptions (IndicesOptions .fromOptions (true , false , false , false )) },
147+ new Object [] {
148+ "strict single index" ,
149+ new SearchRequest ("index" ).indicesOptions (IndicesOptions .STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED ) },
150+ new Object [] {
151+ "with remote index" ,
152+ new SearchRequest ("index" , "remote:index" ).indicesOptions (IndicesOptions .LENIENT_EXPAND_OPEN ) },
153+ new Object [] { "not implementing IndicesRequest.Replaceable" , new IndexRequest ("index" ) }
155154 );
156155
157156 }
0 commit comments