use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class ReplicationResponseTests method testShardInfoToAndFromXContent.
public void testShardInfoToAndFromXContent() throws IOException {
final Tuple<ShardInfo, ShardInfo> tuple = RandomObjects.randomShardInfo(random());
ShardInfo shardInfo = tuple.v1();
ShardInfo expectedShardInfo = tuple.v2();
final XContentType xContentType = randomFrom(XContentType.values());
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(shardInfo, xContentType, humanReadable);
// Shuffle the XContent fields
if (randomBoolean()) {
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
originalBytes = shuffleXContent(parser, randomBoolean()).bytes();
}
}
ShardInfo parsedShardInfo;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
// Move to the first start object
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedShardInfo = ShardInfo.fromXContent(parser);
assertNull(parser.nextToken());
}
assertShardInfo(expectedShardInfo, parsedShardInfo);
BytesReference expectedFinalBytes = toXContent(expectedShardInfo, xContentType, humanReadable);
BytesReference finalBytes = toXContent(parsedShardInfo, xContentType, humanReadable);
assertToXContentEquivalent(expectedFinalBytes, finalBytes, xContentType);
}
use of org.elasticsearch.common.xcontent.XContentType in project elasticsearch by elastic.
the class GetResultTests method testGetSourceAsBytes.
public void testGetSourceAsBytes() {
XContentType xContentType = randomFrom(XContentType.values());
Tuple<GetResult, GetResult> tuple = randomGetResult(xContentType);
GetResult getResult = tuple.v1();
if (getResult.isExists() && getResult.isSourceEmpty() == false) {
assertNotNull(getResult.sourceRef());
} else {
assertNull(getResult.sourceRef());
}
}
Aggregations