use of org.elasticsearch.Version in project elasticsearch by elastic.
the class MoreLikeThisQueryBuilderTests method testItemSerializationBwc.
public void testItemSerializationBwc() throws IOException {
final byte[] data = Base64.getDecoder().decode("AQVpbmRleAEEdHlwZQEODXsiZm9vIjoiYmFyIn0A/wD//////////QAAAAAAAAAA");
final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2, Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
try (StreamInput in = StreamInput.wrap(data)) {
in.setVersion(version);
Item item = new Item(in);
assertEquals(XContentType.JSON, item.xContentType());
assertEquals("{\"foo\":\"bar\"}", item.doc().utf8ToString());
assertEquals("index", item.index());
assertEquals("type", item.type());
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
item.writeTo(out);
assertArrayEquals(data, out.bytes().toBytesRef().bytes);
}
}
}
use of org.elasticsearch.Version 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.Version 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());
}
use of org.elasticsearch.Version in project elasticsearch by elastic.
the class SimulatePipelineRequestTests method testSerializationWithXContentBwc.
public void testSerializationWithXContentBwc() throws IOException {
final byte[] data = Base64.getDecoder().decode("AAAAAnt9AAA=");
final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2, Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
try (StreamInput in = StreamInput.wrap(data)) {
in.setVersion(version);
SimulatePipelineRequest request = new SimulatePipelineRequest();
request.readFrom(in);
assertEquals(XContentType.JSON, request.getXContentType());
assertEquals("{}", request.getSource().utf8ToString());
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
request.writeTo(out);
assertArrayEquals(data, out.bytes().toBytesRef().bytes);
}
}
}
use of org.elasticsearch.Version in project elasticsearch by elastic.
the class PipelineConfigurationTests method testSerializationBwc.
public void testSerializationBwc() throws IOException {
final byte[] data = Base64.getDecoder().decode("ATECe30AAAA=");
final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2, Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
try (StreamInput in = StreamInput.wrap(data)) {
in.setVersion(version);
PipelineConfiguration configuration = PipelineConfiguration.readFrom(in);
assertEquals(XContentType.JSON, configuration.getXContentType());
assertEquals("{}", configuration.getConfig().utf8ToString());
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
configuration.writeTo(out);
assertArrayEquals(data, out.bytes().toBytesRef().bytes);
}
}
}
Aggregations