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());
}
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)));
}
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
}
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());
}
Aggregations