1717import org .elasticsearch .common .bytes .BytesArray ;
1818import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
1919import org .elasticsearch .common .settings .Settings ;
20+ import org .elasticsearch .common .util .concurrent .ThreadContext ;
2021import org .elasticsearch .common .xcontent .XContentType ;
22+ import org .elasticsearch .core .RestApiVersion ;
2123import org .elasticsearch .indices .breaker .NoneCircuitBreakerService ;
24+ import org .elasticsearch .rest .RestChannel ;
2225import org .elasticsearch .rest .RestController ;
2326import org .elasticsearch .rest .RestRequest ;
2427import org .elasticsearch .search .AbstractSearchTestCase ;
3033import org .elasticsearch .threadpool .ThreadPool ;
3134import org .elasticsearch .transport .Transport ;
3235import org .elasticsearch .usage .UsageService ;
33- import org .junit .AfterClass ;
34- import org .junit .BeforeClass ;
36+ import org .junit .After ;
37+ import org .junit .Before ;
3538
3639import java .util .Collections ;
3740import java .util .HashMap ;
4649
4750public class RestValidateQueryActionTests extends AbstractSearchTestCase {
4851
49- private static ThreadPool threadPool = new TestThreadPool (RestValidateQueryActionTests .class .getName ());
50- private static NodeClient client = new NodeClient (Settings .EMPTY , threadPool );
52+ private ThreadPool threadPool = new TestThreadPool (RestValidateQueryActionTests .class .getName ());
53+ private NodeClient client = new NodeClient (Settings .EMPTY , threadPool );
5154
52- private static UsageService usageService = new UsageService ();
53- private static RestController controller = new RestController (emptySet (), null , client ,
55+ private UsageService usageService = new UsageService ();
56+ private RestController controller = new RestController (emptySet (), null , client ,
5457 new NoneCircuitBreakerService (), usageService );
55- private static RestValidateQueryAction action = new RestValidateQueryAction ();
58+ private RestValidateQueryAction action = new RestValidateQueryAction ();
5659
5760 /**
5861 * Configures {@link NodeClient} to stub {@link ValidateQueryAction} transport action.
5962 * <p>
6063 * This lower level of validation is out of the scope of this test.
6164 */
62- @ BeforeClass
63- public static void stubValidateQueryAction () {
65+ @ Before
66+ public void stubValidateQueryAction () {
6467 final TaskManager taskManager = new TaskManager (Settings .EMPTY , threadPool , Collections .emptySet ());
6568
6669 final TransportAction transportAction = new TransportAction (ValidateQueryAction .NAME ,
@@ -78,8 +81,8 @@ protected void doExecute(Task task, ActionRequest request, ActionListener listen
7881 controller .registerHandler (action );
7982 }
8083
81- @ AfterClass
82- public static void terminateThreadPool () {
84+ @ After
85+ public void terminateThreadPool () {
8386 terminate (threadPool );
8487
8588 threadPool = null ;
@@ -146,4 +149,38 @@ private RestRequest createRestRequest(String content) {
146149 .build ();
147150 }
148151
152+ public void testTypeInPath () {
153+ List <String > compatibleMediaType = Collections .singletonList (randomCompatibleMediaType (RestApiVersion .V_7 ));
154+
155+ RestRequest request = new FakeRestRequest .Builder (xContentRegistry ())
156+ .withHeaders (Map .of ("Accept" , compatibleMediaType ))
157+ .withMethod (RestRequest .Method .GET )
158+ .withPath ("/some_index/some_type/_validate/query" )
159+ .build ();
160+
161+ performRequest (request );
162+ assertWarnings (RestValidateQueryAction .TYPES_DEPRECATION_MESSAGE );
163+ }
164+
165+ public void testTypeParameter () {
166+ List <String > compatibleMediaType = Collections .singletonList (randomCompatibleMediaType (RestApiVersion .V_7 ));
167+
168+ Map <String , String > params = new HashMap <>();
169+ params .put ("type" , "some_type" );
170+ RestRequest request = new FakeRestRequest .Builder (xContentRegistry ())
171+ .withHeaders (Map .of ("Accept" , compatibleMediaType ))
172+ .withMethod (RestRequest .Method .GET )
173+ .withPath ("_validate/query" )
174+ .withParams (params )
175+ .build ();
176+
177+ performRequest (request );
178+ assertWarnings (RestValidateQueryAction .TYPES_DEPRECATION_MESSAGE );
179+ }
180+
181+ private void performRequest (RestRequest request ) {
182+ RestChannel channel = new FakeRestChannel (request , false , 1 );
183+ ThreadContext threadContext = new ThreadContext (Settings .EMPTY );
184+ controller .dispatchRequest (request , channel , threadContext );
185+ }
149186}
0 commit comments