use of org.opensearch.common.xcontent.NamedXContentRegistry in project ml-commons by opensearch-project.
the class AnomalyLocalizationInputTests method testXContentFullObject.
@Test
public void testXContentFullObject() throws Exception {
AnomalyLocalizationInput input = new AnomalyLocalizationInput("indexName", Arrays.asList("attribute"), Arrays.asList(AggregationBuilders.max("max").field("field"), AggregationBuilders.min("min").field("field")), "@timestamp", 0L, 10L, 1L, 2, Optional.of(3L), Optional.of(QueryBuilders.matchAllQuery()));
XContentBuilder builder = XContentFactory.jsonBuilder();
builder = input.toXContent(builder, null);
String json = Strings.toString(builder);
XContentParser parser = XContentType.JSON.xContent().createParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY, false, Collections.emptyList()).getNamedXContents()), null, json);
parser.nextToken();
AnomalyLocalizationInput newInput = AnomalyLocalizationInput.parse(parser);
assertEquals(input, newInput);
}
use of org.opensearch.common.xcontent.NamedXContentRegistry in project ml-commons by opensearch-project.
the class AnomalyLocalizationInputTests method testXContentMissingAnomalyStartFilter.
@Test
public void testXContentMissingAnomalyStartFilter() throws Exception {
AnomalyLocalizationInput input = new AnomalyLocalizationInput("indexName", Arrays.asList("attribute"), Arrays.asList(AggregationBuilders.max("max").field("field")), "@timestamp", 0L, 10L, 1L, 2, Optional.empty(), Optional.empty());
XContentBuilder builder = XContentFactory.jsonBuilder();
builder = input.toXContent(builder, null);
String json = Strings.toString(builder);
XContentParser parser = XContentType.JSON.xContent().createParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY, false, Collections.emptyList()).getNamedXContents()), null, json);
parser.nextToken();
AnomalyLocalizationInput newInput = AnomalyLocalizationInput.parse(parser);
assertEquals(input, newInput);
}
use of org.opensearch.common.xcontent.NamedXContentRegistry in project ml-commons by opensearch-project.
the class TestHelper method getXContentRegistry.
private static NamedXContentRegistry getXContentRegistry() {
SearchModule searchModule = new SearchModule(Settings.EMPTY, Collections.emptyList());
List<NamedXContentRegistry.Entry> entries = new ArrayList<>();
entries.addAll(searchModule.getNamedXContents());
entries.add(KMeansParams.XCONTENT_REGISTRY);
entries.add(LocalSampleCalculatorInput.XCONTENT_REGISTRY);
return new NamedXContentRegistry(entries);
}
Aggregations