Skip to content

Commit

Permalink
Refactor XContentFactory to MediaTypeRegistry (#374)
Browse files Browse the repository at this point in the history
Signed-off-by: Heemin Kim <[email protected]>
  • Loading branch information
heemin32 authored Jul 28, 2023
1 parent 0cfddbf commit 26b1938
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import java.util.List;

import org.opensearch.common.Strings;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.test.OpenSearchTestCase;
Expand Down Expand Up @@ -43,7 +43,7 @@ public void testEmptyUploadStats() {

public void testToXContentWithEmptyUploadStats() throws IOException {
TotalUploadStats totalUploadStats = new TotalUploadStats(Collections.emptyList());
XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
contentBuilder.startObject();
totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
contentBuilder.endObject();
Expand All @@ -58,7 +58,7 @@ public void testToXContentWithRequestAPICount() throws IOException {
long expectedSum = INIT;
expectedSum += randomUploadStats.stream().mapToLong(UploadStats::getTotalAPICount).sum();
TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats);
XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
contentBuilder.startObject();
totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
contentBuilder.endObject();
Expand All @@ -74,7 +74,7 @@ public void testToXContentWithUploadCount() throws IOException {
expectedSum += stats.getMetrics().stream().mapToLong(UploadMetric::getUploadCount).sum();
}
TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats);
XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
contentBuilder.startObject();
totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
contentBuilder.endObject();
Expand All @@ -90,7 +90,7 @@ public void testToXContentWithSuccessCount() throws IOException {
expectedSum += stats.getMetrics().stream().mapToLong(UploadMetric::getSuccessCount).sum();
}
TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats);
XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
contentBuilder.startObject();
totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
contentBuilder.endObject();
Expand All @@ -106,7 +106,7 @@ public void testToXContentWithFailedCount() throws IOException {
expectedSum += stats.getMetrics().stream().mapToLong(UploadMetric::getFailedCount).sum();
}
TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats);
XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
contentBuilder.startObject();
totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
contentBuilder.endObject();
Expand All @@ -122,7 +122,7 @@ public void testToXContentWithDuration() throws IOException {
expectedSum += stats.getMetrics().stream().mapToLong(UploadMetric::getDuration).sum();
}
TotalUploadStats totalUploadStats = new TotalUploadStats(randomUploadStats);
XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder contentBuilder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
contentBuilder.startObject();
totalUploadStats.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
contentBuilder.endObject();
Expand Down

0 comments on commit 26b1938

Please sign in to comment.