|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.action.admin.indices.forcemerge; |
| 21 | + |
| 22 | +import org.elasticsearch.client.node.NodeClient; |
| 23 | +import org.elasticsearch.common.bytes.BytesArray; |
| 24 | +import org.elasticsearch.common.settings.Settings; |
| 25 | +import org.elasticsearch.common.xcontent.NamedXContentRegistry; |
| 26 | +import org.elasticsearch.common.xcontent.XContentType; |
| 27 | +import org.elasticsearch.common.xcontent.json.JsonXContent; |
| 28 | +import org.elasticsearch.rest.RestController; |
| 29 | +import org.elasticsearch.rest.action.admin.indices.RestForceMergeAction; |
| 30 | +import org.elasticsearch.test.ESTestCase; |
| 31 | +import org.elasticsearch.test.rest.FakeRestRequest; |
| 32 | + |
| 33 | +import static org.hamcrest.Matchers.equalTo; |
| 34 | +import static org.mockito.Mockito.mock; |
| 35 | + |
| 36 | +public class RestForceMergeActionTests extends ESTestCase { |
| 37 | + |
| 38 | + public void testBodyRejection() throws Exception { |
| 39 | + final RestForceMergeAction handler = new RestForceMergeAction(Settings.EMPTY, mock(RestController.class)); |
| 40 | + String json = JsonXContent.contentBuilder().startObject().field("max_num_segments", 1).endObject().toString(); |
| 41 | + final FakeRestRequest request = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) |
| 42 | + .withContent(new BytesArray(json), XContentType.JSON).build(); |
| 43 | + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, |
| 44 | + () -> handler.prepareRequest(request, mock(NodeClient.class))); |
| 45 | + assertThat(e.getMessage(), equalTo("forcemerge takes arguments in query parameters, not in the request body")); |
| 46 | + } |
| 47 | +} |
0 commit comments