-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rest Api Compatibility] Typed endpoints for explain api (#73901)
- Loading branch information
Showing
4 changed files
with
73 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
server/src/test/java/org/elasticsearch/rest/action/search/RestExplainActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.rest.action.search; | ||
|
||
import org.elasticsearch.action.explain.ExplainResponse; | ||
import org.elasticsearch.core.RestApiVersion; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.test.rest.FakeRestRequest; | ||
import org.elasticsearch.test.rest.RestActionTestCase; | ||
import org.junit.Before; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class RestExplainActionTests extends RestActionTestCase { | ||
final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7)); | ||
|
||
@Before | ||
public void setUpAction() { | ||
RestExplainAction action = new RestExplainAction(); | ||
controller().registerHandler(action); | ||
verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(ExplainResponse.class)); | ||
verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(ExplainResponse.class)); | ||
} | ||
|
||
public void testTypeInPath() { | ||
RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()) | ||
.withHeaders(Map.of("Accept", contentTypeHeader)) | ||
.withMethod(RestRequest.Method.GET) | ||
.withPath("/some_index/some_type/some_id/_explain") | ||
.build(); | ||
dispatchRequest(deprecatedRequest); | ||
assertWarnings(RestExplainAction.TYPES_DEPRECATION_MESSAGE); | ||
|
||
RestRequest validRequest = new FakeRestRequest.Builder(xContentRegistry()) | ||
.withHeaders(Map.of("Accept", contentTypeHeader)) | ||
.withMethod(RestRequest.Method.GET) | ||
.withPath("/some_index/_explain/some_id") | ||
.build(); | ||
dispatchRequest(validRequest); | ||
} | ||
|
||
} |