Search in sources :

Example 36 with NamedXContentRegistry

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);
}
Also used : SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) Test(org.junit.Test)

Example 37 with NamedXContentRegistry

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);
}
Also used : SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) Test(org.junit.Test)

Example 38 with NamedXContentRegistry

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);
}
Also used : ArrayList(java.util.ArrayList) SearchModule(org.opensearch.search.SearchModule) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry)

Aggregations

NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)38 SearchModule (org.opensearch.search.SearchModule)19 XContentParser (org.opensearch.common.xcontent.XContentParser)15 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)13 ArrayList (java.util.ArrayList)11 Map (java.util.Map)10 BeforeClass (org.junit.BeforeClass)10 Settings (org.opensearch.common.settings.Settings)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 List (java.util.List)8 ClusterService (org.opensearch.cluster.service.ClusterService)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 ActionListener (org.opensearch.action.ActionListener)6 MapperService (org.opensearch.index.mapper.MapperService)6 Test (org.junit.Test)5 ClusterState (org.opensearch.cluster.ClusterState)5 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)5 Arrays (java.util.Arrays)4