Simplify xcontent usage.
This commit simplifies xcontent usage in x-pack in a way that is compatible with elastic/elasticsearchelastic/elasticsearch#15358. Original commit: elastic/x-pack-elasticsearch@0d6ce5f22f
This commit is contained in:
parent
1f931f705b
commit
aefd963327
|
@ -49,7 +49,7 @@ public class LicenseSerializationTests extends ESTestCase {
|
|||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||
license.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap(License.REST_VIEW_MODE, "true")));
|
||||
builder.flush();
|
||||
Map<String, Object> map = XContentHelper.convertToMap(builder.bytesStream().bytes(), false).v2();
|
||||
Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false).v2();
|
||||
|
||||
// should have an extra status field, human readable issue_data and expiry_date
|
||||
assertThat(map.get("status"), notNullValue());
|
||||
|
@ -59,14 +59,14 @@ public class LicenseSerializationTests extends ESTestCase {
|
|||
builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||
license.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.flush();
|
||||
map = XContentHelper.convertToMap(builder.bytesStream().bytes(), false).v2();
|
||||
map = XContentHelper.convertToMap(builder.bytes(), false).v2();
|
||||
assertThat(map.get("status"), nullValue());
|
||||
|
||||
license = TestUtils.generateLicenses(new TestUtils.LicenseSpec(validLicenseIssueDate, validLicenseExpiryDate));
|
||||
builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||
license.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap(License.REST_VIEW_MODE, "true")));
|
||||
builder.flush();
|
||||
map = XContentHelper.convertToMap(builder.bytesStream().bytes(), false).v2();
|
||||
map = XContentHelper.convertToMap(builder.bytes(), false).v2();
|
||||
|
||||
// should have an extra status field, human readable issue_data and expiry_date
|
||||
assertThat(map.get("status"), notNullValue());
|
||||
|
@ -76,14 +76,14 @@ public class LicenseSerializationTests extends ESTestCase {
|
|||
builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||
license.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.flush();
|
||||
map = XContentHelper.convertToMap(builder.bytesStream().bytes(), false).v2();
|
||||
map = XContentHelper.convertToMap(builder.bytes(), false).v2();
|
||||
assertThat(map.get("status"), nullValue());
|
||||
|
||||
license = TestUtils.generateLicenses(new TestUtils.LicenseSpec(invalidLicenseIssueDate, validLicenseExpiryDate));
|
||||
builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||
license.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap(License.REST_VIEW_MODE, "true")));
|
||||
builder.flush();
|
||||
map = XContentHelper.convertToMap(builder.bytesStream().bytes(), false).v2();
|
||||
map = XContentHelper.convertToMap(builder.bytes(), false).v2();
|
||||
|
||||
// should have an extra status field, human readable issue_data and expiry_date
|
||||
assertThat(map.get("status"), notNullValue());
|
||||
|
@ -93,7 +93,7 @@ public class LicenseSerializationTests extends ESTestCase {
|
|||
builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||
license.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.flush();
|
||||
map = XContentHelper.convertToMap(builder.bytesStream().bytes(), false).v2();
|
||||
map = XContentHelper.convertToMap(builder.bytes(), false).v2();
|
||||
assertThat(map.get("status"), nullValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class PutLicenseResponseTests extends ESTestCase {
|
|||
response.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
|
||||
contentBuilder.endObject();
|
||||
|
||||
Map<String, Object> map = XContentHelper.convertToMap(contentBuilder.bytesStream().bytes(), false).v2();
|
||||
Map<String, Object> map = XContentHelper.convertToMap(contentBuilder.bytes(), false).v2();
|
||||
assertThat(map.containsKey("acknowledged"), equalTo(true));
|
||||
boolean actualAcknowledged = (boolean) map.get("acknowledged");
|
||||
assertThat(actualAcknowledged, equalTo(acknowledged));
|
||||
|
|
|
@ -199,18 +199,15 @@ public class HttpExporter extends Exporter {
|
|||
}
|
||||
builder.endObject();
|
||||
builder.endObject();
|
||||
|
||||
// Adds action metadata line bulk separator
|
||||
builder.flush(); // Flush is needed here because the separator is written directly in the builder's stream
|
||||
builder.stream().write(builder.contentType().xContent().streamSeparator());
|
||||
|
||||
// Render the MarvelDoc
|
||||
renderer.render(marvelDoc, xContentType, out);
|
||||
|
||||
// Adds final bulk separator
|
||||
builder.flush();
|
||||
builder.stream().write(builder.contentType().xContent().streamSeparator());
|
||||
}
|
||||
// Adds action metadata line bulk separator
|
||||
out.write(xContentType.xContent().streamSeparator());
|
||||
|
||||
// Render the MarvelDoc
|
||||
renderer.render(marvelDoc, xContentType, out);
|
||||
|
||||
// Adds final bulk separator
|
||||
out.write(xContentType.xContent().streamSeparator());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
Loading…
Reference in New Issue