Search in sources :

Example 1 with MainResponse

use of org.elasticsearch.action.main.MainResponse in project elasticsearch by elastic.

the class PingAndInfoIT method testInfo.

@SuppressWarnings("unchecked")
public void testInfo() throws IOException {
    MainResponse info = highLevelClient().info();
    // compare with what the low level client outputs
    Map<String, Object> infoAsMap = entityAsMap(adminClient().performRequest("GET", "/"));
    assertEquals(infoAsMap.get("cluster_name"), info.getClusterName().value());
    assertEquals(infoAsMap.get("cluster_uuid"), info.getClusterUuid());
    // only check node name existence, might be a different one from what was hit by low level client in multi-node cluster
    assertNotNull(info.getNodeName());
    Map<String, Object> versionMap = (Map<String, Object>) infoAsMap.get("version");
    assertEquals(versionMap.get("build_hash"), info.getBuild().shortHash());
    assertEquals(versionMap.get("build_date"), info.getBuild().date());
    assertEquals(versionMap.get("build_snapshot"), info.getBuild().isSnapshot());
    assertEquals(versionMap.get("number"), info.getVersion().toString());
    assertEquals(versionMap.get("lucene_version"), info.getVersion().luceneVersion.toString());
}
Also used : MainResponse(org.elasticsearch.action.main.MainResponse) Map(java.util.Map)

Example 2 with MainResponse

use of org.elasticsearch.action.main.MainResponse in project elasticsearch by elastic.

the class RestHighLevelClientTests method testInfo.

public void testInfo() throws IOException {
    Header[] headers = RestClientTestUtil.randomHeaders(random(), "Header");
    Response response = mock(Response.class);
    MainResponse testInfo = new MainResponse("nodeName", Version.CURRENT, new ClusterName("clusterName"), "clusterUuid", Build.CURRENT, true);
    when(response.getEntity()).thenReturn(new StringEntity(toXContent(testInfo, XContentType.JSON, false).utf8ToString(), ContentType.APPLICATION_JSON));
    when(restClient.performRequest(anyString(), anyString(), anyMapOf(String.class, String.class), anyObject(), anyVararg())).thenReturn(response);
    MainResponse receivedInfo = restHighLevelClient.info(headers);
    assertEquals(testInfo, receivedInfo);
    verify(restClient).performRequest(eq("GET"), eq("/"), eq(Collections.emptyMap()), Matchers.isNull(HttpEntity.class), argThat(new HeadersVarargMatcher(headers)));
}
Also used : MainResponse(org.elasticsearch.action.main.MainResponse) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) StringEntity(org.apache.http.entity.StringEntity) Header(org.apache.http.Header) HttpEntity(org.apache.http.HttpEntity) MainResponse(org.elasticsearch.action.main.MainResponse) ClusterName(org.elasticsearch.cluster.ClusterName) Matchers.anyString(org.mockito.Matchers.anyString)

Example 3 with MainResponse

use of org.elasticsearch.action.main.MainResponse in project elasticsearch by elastic.

the class RestMainActionTests method testHeadResponse.

public void testHeadResponse() throws Exception {
    final String nodeName = "node1";
    final ClusterName clusterName = new ClusterName("cluster1");
    final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
    final boolean available = randomBoolean();
    final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
    final Version version = Version.CURRENT;
    final Build build = Build.CURRENT;
    final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
    XContentBuilder builder = JsonXContent.contentBuilder();
    RestRequest restRequest = new FakeRestRequest() {

        @Override
        public Method method() {
            return Method.HEAD;
        }
    };
    BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
    assertNotNull(response);
    assertEquals(expectedStatus, response.status());
// the empty responses are handled in the HTTP layer so we do
// not assert on them here
}
Also used : FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) RestRequest(org.elasticsearch.rest.RestRequest) RestStatus(org.elasticsearch.rest.RestStatus) Version(org.elasticsearch.Version) MainResponse(org.elasticsearch.action.main.MainResponse) Build(org.elasticsearch.Build) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ClusterName(org.elasticsearch.cluster.ClusterName) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 4 with MainResponse

use of org.elasticsearch.action.main.MainResponse in project elasticsearch by elastic.

the class RestMainActionTests method testGetResponse.

public void testGetResponse() throws Exception {
    final String nodeName = "node1";
    final ClusterName clusterName = new ClusterName("cluster1");
    final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
    final boolean available = randomBoolean();
    final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
    final Version version = Version.CURRENT;
    final Build build = Build.CURRENT;
    final boolean prettyPrint = randomBoolean();
    final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
    XContentBuilder builder = JsonXContent.contentBuilder();
    Map<String, String> params = new HashMap<>();
    if (prettyPrint == false) {
        params.put("pretty", String.valueOf(prettyPrint));
    }
    RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();
    BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
    assertNotNull(response);
    assertEquals(expectedStatus, response.status());
    assertThat(response.content().length(), greaterThan(0));
    XContentBuilder responseBuilder = JsonXContent.contentBuilder();
    if (prettyPrint) {
        // do this to mimic what the rest layer does
        responseBuilder.prettyPrint().lfAtEnd();
    }
    mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS);
    BytesReference xcontentBytes = responseBuilder.bytes();
    assertEquals(xcontentBytes, response.content());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) HashMap(java.util.HashMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) RestRequest(org.elasticsearch.rest.RestRequest) RestStatus(org.elasticsearch.rest.RestStatus) Version(org.elasticsearch.Version) MainResponse(org.elasticsearch.action.main.MainResponse) Build(org.elasticsearch.Build) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ClusterName(org.elasticsearch.cluster.ClusterName) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

MainResponse (org.elasticsearch.action.main.MainResponse)4 ClusterName (org.elasticsearch.cluster.ClusterName)3 Build (org.elasticsearch.Build)2 Version (org.elasticsearch.Version)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)2 RestRequest (org.elasticsearch.rest.RestRequest)2 RestStatus (org.elasticsearch.rest.RestStatus)2 FakeRestRequest (org.elasticsearch.test.rest.FakeRestRequest)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Header (org.apache.http.Header)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 StringEntity (org.apache.http.entity.StringEntity)1 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 Matchers.anyString (org.mockito.Matchers.anyString)1