Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Büscher committed Jan 16, 2019
1 parent db10c80 commit d127196
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ setup:
mappings:
doc: {}
---
"Get /{index}/_mapping with empty mappings":

- do:
indices.create:
index: t

- do:
indices.get_mapping:
include_type_name: true
index: t

- match: { t.mappings: {}}

---
"Get /_mapping":

- do:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---
setup:
- skip:
version: " - 6.99.99"
reason: include_type_name defaults to true before 7.0
- do:
indices.create:
index: test_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
throw new IllegalArgumentException("Types cannot be provided in get mapping requests, unless" +
" include_type_name is set to true.");
}
// TODO q: do we want to deprecate any use of the parameter or just "true"
if (includeTypeName == true) {
if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) {
deprecationLogger.deprecatedAndMaybeLog("get_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ protected GetMappingsResponse createXContextTestInstance(XContentType xContentTy

/**
* check that the "old" legacy response format with types works as expected
* @throws IOException
*/
public void testToXContentWithTypes() throws IOException {
Params params = new ToXContent.MapParams(Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "true"));
xContentTester(this::createParser, t -> createTestInstance(), params, this::fromXContentLegacy)
xContentTester(this::createParser, t -> createTestInstance(), params, this::fromXContentWithTypes)
.numberOfTestRuns(NUMBER_OF_TEST_RUNS)
.supportsUnknownFields(supportsUnknownFields())
.shuffleFieldsExceptions(getShuffleFieldsExceptions())
Expand All @@ -190,7 +189,7 @@ public void testToXContentWithTypes() throws IOException {
* including the pre-7.0 parsing code here to test that older HLRC clients using this can parse the responses that are
* returned when "include_type_name=true"
*/
private GetMappingsResponse fromXContentLegacy(XContentParser parser) throws IOException {
private GetMappingsResponse fromXContentWithTypes(XContentParser parser) throws IOException {
if (parser.currentToken() == null) {
parser.nextToken();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.test.rest.FakeRestChannel;
import org.elasticsearch.test.rest.FakeRestRequest;
import org.elasticsearch.test.rest.RestActionTestCase;
import org.junit.Before;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -37,6 +38,11 @@

public class RestGetMappingActionTests extends RestActionTestCase {

@Before
public void setUpAction() {
new RestGetMappingAction(Settings.EMPTY, controller());
}

public void testTypeExistsDeprecation() throws Exception {
Map<String, String> params = new HashMap<>();
params.put("type", "_doc");
Expand Down Expand Up @@ -70,17 +76,21 @@ public void testTypeInPath() {
assertEquals(RestStatus.BAD_REQUEST, channel.capturedResponse().status());
}

public void testTypeUrlParamerterDeprecation() throws Exception {
/**
* Setting "include_type_name" to true or false should cause a deprecation warning starting in 7.0
*/
public void testTypeUrlParameterDeprecation() throws Exception {
Map<String, String> params = new HashMap<>();
params.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
params.put(INCLUDE_TYPE_NAME_PARAMETER, Boolean.toString(randomBoolean()));
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
.withMethod(RestRequest.Method.GET)
.withParams(params)
.withPath("some_index/some_type/_mapping/some_field")
.withPath("/some_index/_mappings")
.build();

RestGetMappingAction handler = new RestGetMappingAction(Settings.EMPTY, mock(RestController.class));
handler.prepareRequest(request, mock(NodeClient.class));
FakeRestChannel channel = new FakeRestChannel(request, false, 1);
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
controller().dispatchRequest(request, channel, threadContext);

assertWarnings(RestGetMappingAction.TYPES_DEPRECATION_MESSAGE);
}
Expand Down

0 comments on commit d127196

Please sign in to comment.