|
| 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.Version; |
| 23 | +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; |
| 24 | +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; |
| 25 | +import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; |
| 26 | +import org.elasticsearch.cluster.ClusterName; |
| 27 | +import org.elasticsearch.cluster.ClusterState; |
| 28 | +import org.elasticsearch.cluster.node.DiscoveryNode; |
| 29 | +import org.elasticsearch.cluster.node.DiscoveryNodes; |
| 30 | +import org.elasticsearch.common.settings.Settings; |
| 31 | +import org.elasticsearch.rest.RestController; |
| 32 | +import org.elasticsearch.test.ESTestCase; |
| 33 | +import org.elasticsearch.test.rest.FakeRestRequest; |
| 34 | +import org.elasticsearch.usage.UsageService; |
| 35 | +import org.junit.Before; |
| 36 | + |
| 37 | +import java.util.Collections; |
| 38 | + |
| 39 | +import static java.util.Collections.emptyMap; |
| 40 | +import static java.util.Collections.emptySet; |
| 41 | +import static org.mockito.Mockito.mock; |
| 42 | +import static org.mockito.Mockito.when; |
| 43 | + |
| 44 | +public class RestNodesActionTests extends ESTestCase { |
| 45 | + |
| 46 | + private RestNodesAction action; |
| 47 | + |
| 48 | + @Before |
| 49 | + public void setUpAction() { |
| 50 | + UsageService usageService = new UsageService(Settings.EMPTY); |
| 51 | + action = new RestNodesAction(Settings.EMPTY, |
| 52 | + new RestController(Settings.EMPTY, Collections.emptySet(), null, null, null, usageService)); |
| 53 | + } |
| 54 | + |
| 55 | + public void testBuildTableDoesNotThrowGivenNullNodeInfoAndStats() { |
| 56 | + ClusterName clusterName = new ClusterName("cluster-1"); |
| 57 | + DiscoveryNodes.Builder builder = DiscoveryNodes.builder(); |
| 58 | + builder.add(new DiscoveryNode("node-1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)); |
| 59 | + DiscoveryNodes discoveryNodes = builder.build(); |
| 60 | + ClusterState clusterState = mock(ClusterState.class); |
| 61 | + when(clusterState.nodes()).thenReturn(discoveryNodes); |
| 62 | + |
| 63 | + ClusterStateResponse clusterStateResponse = new ClusterStateResponse(clusterName, clusterState, randomNonNegativeLong()); |
| 64 | + NodesInfoResponse nodesInfoResponse = new NodesInfoResponse(clusterName, Collections.emptyList(), Collections.emptyList()); |
| 65 | + NodesStatsResponse nodesStatsResponse = new NodesStatsResponse(clusterName, Collections.emptyList(), Collections.emptyList()); |
| 66 | + |
| 67 | + action.buildTable(false, new FakeRestRequest(), clusterStateResponse, nodesInfoResponse, nodesStatsResponse); |
| 68 | + } |
| 69 | +} |
0 commit comments