|
| 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.rest.action.cat; |
| 21 | + |
| 22 | +import org.elasticsearch.action.ActionListener; |
| 23 | +import org.elasticsearch.action.ActionRequest; |
| 24 | +import org.elasticsearch.action.ActionResponse; |
| 25 | +import org.elasticsearch.action.ActionType; |
| 26 | +import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; |
| 27 | +import org.elasticsearch.cluster.node.DiscoveryNodes; |
| 28 | +import org.elasticsearch.common.collect.MapBuilder; |
| 29 | +import org.elasticsearch.common.xcontent.NamedXContentRegistry; |
| 30 | +import org.elasticsearch.test.ESTestCase; |
| 31 | +import org.elasticsearch.test.client.NoOpNodeClient; |
| 32 | +import org.elasticsearch.test.rest.FakeRestChannel; |
| 33 | +import org.elasticsearch.test.rest.FakeRestRequest; |
| 34 | + |
| 35 | +import static java.util.Collections.emptyList; |
| 36 | +import static org.hamcrest.Matchers.is; |
| 37 | + |
| 38 | +public class RestTasksActionTests extends ESTestCase { |
| 39 | + |
| 40 | + public void testConsumesParameters() throws Exception { |
| 41 | + RestTasksAction action = new RestTasksAction(() -> DiscoveryNodes.EMPTY_NODES); |
| 42 | + FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) |
| 43 | + .withParams(MapBuilder.<String, String>newMapBuilder() |
| 44 | + .put("parent_task_id", "the node:3") |
| 45 | + .put("nodes", "node1,node2") |
| 46 | + .put("actions", "*") |
| 47 | + .map() |
| 48 | + ).build(); |
| 49 | + FakeRestChannel fakeRestChannel = new FakeRestChannel(fakeRestRequest, false, 1); |
| 50 | + try (NoOpNodeClient nodeClient = buildNodeClient()) { |
| 51 | + action.handleRequest(fakeRestRequest, fakeRestChannel, nodeClient); |
| 52 | + } |
| 53 | + |
| 54 | + assertThat(fakeRestChannel.errors().get(), is(0)); |
| 55 | + assertThat(fakeRestChannel.responses().get(), is(1)); |
| 56 | + } |
| 57 | + |
| 58 | + private NoOpNodeClient buildNodeClient() { |
| 59 | + return new NoOpNodeClient(getTestName()) { |
| 60 | + @Override |
| 61 | + @SuppressWarnings("unchecked") |
| 62 | + public <Request extends ActionRequest, Response extends ActionResponse> |
| 63 | + void doExecute(ActionType<Response> action, Request request, ActionListener<Response> listener) { |
| 64 | + listener.onResponse((Response) new ListTasksResponse(emptyList(), emptyList(), emptyList())); |
| 65 | + } |
| 66 | + }; |
| 67 | + } |
| 68 | +} |
0 commit comments